schacon-git 1.0.7 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README +7 -1
- data/lib/git/base.rb +51 -47
- data/lib/git/branch.rb +3 -5
- data/lib/git/branches.rb +4 -13
- data/lib/git/diff.rb +20 -17
- data/lib/git/lib.rb +126 -117
- data/lib/git/log.rb +20 -18
- data/lib/git/object.rb +63 -86
- data/lib/git/remote.rb +1 -3
- data/lib/git/stash.rb +2 -1
- data/lib/git/stashes.rb +5 -10
- data/lib/git/status.rb +7 -15
- data/lib/git.rb +14 -0
- metadata +6 -7
- data/tests/all_tests.rb +0 -4
- data/tests/test_helper.rb +0 -77
data/lib/git/object.rb
CHANGED
@@ -8,36 +8,35 @@ module Git
|
|
8
8
|
|
9
9
|
class AbstractObject
|
10
10
|
attr_accessor :objectish, :size, :type, :mode
|
11
|
-
|
12
|
-
@base = nil
|
13
|
-
@contents = nil
|
14
|
-
@size = nil
|
15
|
-
@sha = nil
|
16
11
|
|
17
12
|
def initialize(base, objectish)
|
18
13
|
@base = base
|
19
14
|
@objectish = objectish.to_s
|
20
|
-
|
15
|
+
@contents = nil
|
16
|
+
@trees = nil
|
17
|
+
@size = nil
|
18
|
+
@sha = nil
|
21
19
|
end
|
22
20
|
|
23
21
|
def sha
|
24
|
-
@sha
|
22
|
+
@sha ||= @base.lib.revparse(@objectish)
|
25
23
|
end
|
26
24
|
|
27
25
|
def size
|
28
|
-
@size
|
26
|
+
@size ||= @base.lib.object_size(@objectish)
|
29
27
|
end
|
30
28
|
|
31
|
-
#
|
32
|
-
#
|
33
|
-
#
|
34
|
-
# read a large file in chunks.
|
35
|
-
#
|
29
|
+
# Get the object's contents.
|
30
|
+
# If no block is given, the contents are cached in memory and returned as a string.
|
31
|
+
# If a block is given, it yields an IO object (via IO::popen) which could be used to
|
32
|
+
# read a large file in chunks.
|
33
|
+
#
|
34
|
+
# Use this for large files so that they are not held in memory.
|
36
35
|
def contents(&block)
|
37
36
|
if block_given?
|
38
37
|
@base.lib.object_contents(@objectish, &block)
|
39
38
|
else
|
40
|
-
@contents
|
39
|
+
@contents ||= @base.lib.object_contents(@objectish)
|
41
40
|
end
|
42
41
|
end
|
43
42
|
|
@@ -45,18 +44,13 @@ module Git
|
|
45
44
|
self.contents.split("\n")
|
46
45
|
end
|
47
46
|
|
48
|
-
def setup
|
49
|
-
raise NotImplementedError
|
50
|
-
end
|
51
|
-
|
52
47
|
def to_s
|
53
48
|
@objectish
|
54
49
|
end
|
55
50
|
|
56
51
|
def grep(string, path_limiter = nil, opts = {})
|
57
|
-
|
58
|
-
|
59
|
-
@base.lib.grep(string, grep_options)
|
52
|
+
opts = {:object => sha, :path_limiter => path_limiter}.merge(opts)
|
53
|
+
@base.lib.grep(string, opts)
|
60
54
|
end
|
61
55
|
|
62
56
|
def diff(objectish)
|
@@ -72,21 +66,13 @@ module Git
|
|
72
66
|
@base.lib.archive(@objectish, file, opts)
|
73
67
|
end
|
74
68
|
|
75
|
-
def tree
|
76
|
-
@type == 'tree'
|
77
|
-
end
|
69
|
+
def tree?; false; end
|
78
70
|
|
79
|
-
def blob
|
80
|
-
@type == 'blob'
|
81
|
-
end
|
71
|
+
def blob?; false; end
|
82
72
|
|
83
|
-
def commit
|
84
|
-
|
85
|
-
end
|
86
|
-
|
87
|
-
def tag?
|
88
|
-
@type == 'tag'
|
89
|
-
end
|
73
|
+
def commit?; false; end
|
74
|
+
|
75
|
+
def tag?; false; end
|
90
76
|
|
91
77
|
end
|
92
78
|
|
@@ -98,11 +84,10 @@ module Git
|
|
98
84
|
@mode = mode
|
99
85
|
end
|
100
86
|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
end
|
87
|
+
def blob?
|
88
|
+
true
|
89
|
+
end
|
90
|
+
|
106
91
|
end
|
107
92
|
|
108
93
|
class Tree < AbstractObject
|
@@ -139,16 +124,16 @@ module Git
|
|
139
124
|
def depth
|
140
125
|
@base.lib.tree_depth(@objectish)
|
141
126
|
end
|
127
|
+
|
128
|
+
def tree?
|
129
|
+
true
|
130
|
+
end
|
142
131
|
|
143
132
|
private
|
144
|
-
|
145
|
-
def setup
|
146
|
-
@type = 'tree'
|
147
|
-
end
|
148
133
|
|
149
134
|
# actually run the git command
|
150
135
|
def check_tree
|
151
|
-
|
136
|
+
unless @trees
|
152
137
|
@trees = {}
|
153
138
|
@blobs = {}
|
154
139
|
data = @base.lib.ls_tree(@objectish)
|
@@ -161,14 +146,13 @@ module Git
|
|
161
146
|
|
162
147
|
class Commit < AbstractObject
|
163
148
|
|
164
|
-
@tree = nil
|
165
|
-
@parents = nil
|
166
|
-
@author = nil
|
167
|
-
@committer = nil
|
168
|
-
@message = nil
|
169
|
-
|
170
149
|
def initialize(base, sha, init = nil)
|
171
150
|
super(base, sha)
|
151
|
+
@tree = nil
|
152
|
+
@parents = nil
|
153
|
+
@author = nil
|
154
|
+
@committer = nil
|
155
|
+
@message = nil
|
172
156
|
if init
|
173
157
|
set_commit(init)
|
174
158
|
end
|
@@ -233,16 +217,16 @@ module Git
|
|
233
217
|
@parents = data['parent'].map{ |sha| Git::Object::Commit.new(@base, sha) }
|
234
218
|
@message = data['message'].chomp
|
235
219
|
end
|
236
|
-
|
237
|
-
private
|
238
220
|
|
239
|
-
|
240
|
-
|
241
|
-
|
221
|
+
def commit?
|
222
|
+
true
|
223
|
+
end
|
224
|
+
|
225
|
+
private
|
242
226
|
|
243
227
|
# see if this object has been initialized and do so if not
|
244
228
|
def check_commit
|
245
|
-
|
229
|
+
unless @tree
|
246
230
|
data = @base.lib.commit_data(@objectish)
|
247
231
|
set_commit(data)
|
248
232
|
end
|
@@ -257,40 +241,33 @@ module Git
|
|
257
241
|
super(base, sha)
|
258
242
|
@name = name
|
259
243
|
end
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
@type = 'tag'
|
265
|
-
end
|
244
|
+
|
245
|
+
def tag?
|
246
|
+
true
|
247
|
+
end
|
266
248
|
|
267
249
|
end
|
268
250
|
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
raise Git::GitTagNameDoesNotExist.new(objectish)
|
277
|
-
end
|
278
|
-
return Git::Object::Tag.new(base, sha, objectish)
|
279
|
-
else
|
280
|
-
if !type
|
281
|
-
type = base.lib.object_type(objectish)
|
282
|
-
end
|
251
|
+
# if we're calling this, we don't know what type it is yet
|
252
|
+
# so this is our little factory method
|
253
|
+
def self.new(base, objectish, type = nil, is_tag = false)
|
254
|
+
if is_tag
|
255
|
+
sha = base.lib.tag_sha(objectish)
|
256
|
+
if sha == ''
|
257
|
+
raise Git::GitTagNameDoesNotExist.new(objectish)
|
283
258
|
end
|
284
|
-
|
285
|
-
klass =
|
286
|
-
case type
|
287
|
-
when /blob/: Blob
|
288
|
-
when /commit/: Commit
|
289
|
-
when /tree/: Tree
|
290
|
-
end
|
291
|
-
klass::new(base, objectish)
|
259
|
+
return Git::Object::Tag.new(base, sha, objectish)
|
292
260
|
end
|
293
|
-
|
261
|
+
|
262
|
+
type ||= base.lib.object_type(objectish)
|
263
|
+
klass =
|
264
|
+
case type
|
265
|
+
when /blob/ then Blob
|
266
|
+
when /commit/ then Commit
|
267
|
+
when /tree/ then Tree
|
268
|
+
end
|
269
|
+
klass.new(base, objectish)
|
270
|
+
end
|
294
271
|
|
295
272
|
end
|
296
|
-
end
|
273
|
+
end
|
data/lib/git/remote.rb
CHANGED
data/lib/git/stash.rb
CHANGED
data/lib/git/stashes.rb
CHANGED
@@ -4,9 +4,6 @@ module Git
|
|
4
4
|
class Stashes
|
5
5
|
include Enumerable
|
6
6
|
|
7
|
-
@base = nil
|
8
|
-
@stashes = nil
|
9
|
-
|
10
7
|
def initialize(base)
|
11
8
|
@stashes = []
|
12
9
|
|
@@ -22,8 +19,8 @@ module Git
|
|
22
19
|
@stashes.unshift(s) if s.saved?
|
23
20
|
end
|
24
21
|
|
25
|
-
def apply(index=
|
26
|
-
@base.lib.stash_apply(index
|
22
|
+
def apply(index=nil)
|
23
|
+
@base.lib.stash_apply(index)
|
27
24
|
end
|
28
25
|
|
29
26
|
def clear
|
@@ -35,10 +32,8 @@ module Git
|
|
35
32
|
@stashes.size
|
36
33
|
end
|
37
34
|
|
38
|
-
def each
|
39
|
-
@stashes.each
|
40
|
-
yield s
|
41
|
-
end
|
35
|
+
def each(&block)
|
36
|
+
@stashes.each(&block)
|
42
37
|
end
|
43
38
|
|
44
39
|
def [](index)
|
@@ -46,4 +41,4 @@ module Git
|
|
46
41
|
end
|
47
42
|
|
48
43
|
end
|
49
|
-
end
|
44
|
+
end
|
data/lib/git/status.rb
CHANGED
@@ -3,9 +3,6 @@ module Git
|
|
3
3
|
class Status
|
4
4
|
include Enumerable
|
5
5
|
|
6
|
-
@base = nil
|
7
|
-
@files = nil
|
8
|
-
|
9
6
|
def initialize(base)
|
10
7
|
@base = base
|
11
8
|
construct_status
|
@@ -48,19 +45,15 @@ module Git
|
|
48
45
|
@files[file]
|
49
46
|
end
|
50
47
|
|
51
|
-
def each
|
52
|
-
@files.each
|
53
|
-
yield file
|
54
|
-
end
|
48
|
+
def each(&block)
|
49
|
+
@files.values.each(&block)
|
55
50
|
end
|
56
51
|
|
57
52
|
class StatusFile
|
58
53
|
attr_accessor :path, :type, :stage, :untracked
|
59
54
|
attr_accessor :mode_index, :mode_repo
|
60
55
|
attr_accessor :sha_index, :sha_repo
|
61
|
-
|
62
|
-
@base = nil
|
63
|
-
|
56
|
+
|
64
57
|
def initialize(base, hash)
|
65
58
|
@base = base
|
66
59
|
@path = hash[:path]
|
@@ -88,16 +81,15 @@ module Git
|
|
88
81
|
|
89
82
|
def construct_status
|
90
83
|
@files = @base.lib.ls_files
|
84
|
+
ignore = @base.lib.ignored_files
|
91
85
|
|
92
86
|
# find untracked in working dir
|
93
87
|
Dir.chdir(@base.dir.path) do
|
94
88
|
Dir.glob('**/*') do |file|
|
95
|
-
|
96
|
-
@files[file] = {:path => file, :untracked => true} if !File.directory?(file)
|
97
|
-
end
|
89
|
+
@files[file] = {:path => file, :untracked => true} unless @files[file] || File.directory?(file) || ignore.include?(file)
|
98
90
|
end
|
99
91
|
end
|
100
|
-
|
92
|
+
|
101
93
|
# find modified in tree
|
102
94
|
@base.lib.diff_files.each do |path, data|
|
103
95
|
@files[path] ? @files[path].merge!(data) : @files[path] = data
|
@@ -115,4 +107,4 @@ module Git
|
|
115
107
|
|
116
108
|
end
|
117
109
|
|
118
|
-
end
|
110
|
+
end
|
data/lib/git.rb
CHANGED
@@ -92,5 +92,19 @@ module Git
|
|
92
92
|
def self.clone(repository, name, options = {})
|
93
93
|
Base.clone(repository, name, options)
|
94
94
|
end
|
95
|
+
|
96
|
+
# Export the current HEAD (or a branch, if <tt>options[:branch]</tt>
|
97
|
+
# is specified) into the +name+ directory, then remove all traces of git from the
|
98
|
+
# directory.
|
99
|
+
#
|
100
|
+
# See +clone+ for options. Does not obey the <tt>:remote</tt> option,
|
101
|
+
# since the .git info will be deleted anyway; always uses the default
|
102
|
+
# remote, 'origin.'
|
103
|
+
def self.export(repository, name, options = {})
|
104
|
+
options.delete(:remote)
|
105
|
+
repo = clone(repository, name, {:depth => 1}.merge(options))
|
106
|
+
repo.checkout("origin/#{options[:branch]}") if options[:branch]
|
107
|
+
Dir.chdir(repo.dir.to_s) { FileUtils.rm_r '.git' }
|
108
|
+
end
|
95
109
|
|
96
110
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: schacon-git
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Scott Chacon
|
@@ -9,7 +9,7 @@ autorequire: git
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2009-04-08 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -42,7 +42,7 @@ files:
|
|
42
42
|
- lib/git.rb
|
43
43
|
- README
|
44
44
|
has_rdoc: true
|
45
|
-
homepage:
|
45
|
+
homepage: http://github.com/schacon/ruby-git/tree/master
|
46
46
|
post_install_message:
|
47
47
|
rdoc_options: []
|
48
48
|
|
@@ -63,10 +63,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
63
63
|
requirements: []
|
64
64
|
|
65
65
|
rubyforge_project:
|
66
|
-
rubygems_version: 1.0
|
66
|
+
rubygems_version: 1.2.0
|
67
67
|
signing_key:
|
68
68
|
specification_version: 2
|
69
69
|
summary: A package for using Git in Ruby code.
|
70
|
-
test_files:
|
71
|
-
|
72
|
-
- tests/test_helper.rb
|
70
|
+
test_files: []
|
71
|
+
|
data/tests/all_tests.rb
DELETED
data/tests/test_helper.rb
DELETED
@@ -1,77 +0,0 @@
|
|
1
|
-
require 'test/unit'
|
2
|
-
require 'fileutils'
|
3
|
-
require 'logger'
|
4
|
-
require File.dirname(__FILE__) + '/../lib/git'
|
5
|
-
|
6
|
-
class Test::Unit::TestCase
|
7
|
-
|
8
|
-
def set_file_paths
|
9
|
-
cwd = `pwd`.chomp
|
10
|
-
if File.directory?(File.join(cwd, 'files'))
|
11
|
-
@test_dir = File.join(cwd, 'files')
|
12
|
-
elsif File.directory?(File.join(cwd, '..', 'files'))
|
13
|
-
@test_dir = File.join(cwd, '..', 'files')
|
14
|
-
elsif File.directory?(File.join(cwd, 'tests', 'files'))
|
15
|
-
@test_dir = File.join(cwd, 'tests', 'files')
|
16
|
-
end
|
17
|
-
|
18
|
-
@wdir_dot = File.expand_path(File.join(@test_dir, 'working'))
|
19
|
-
@wbare = File.expand_path(File.join(@test_dir, 'working.git'))
|
20
|
-
@index = File.expand_path(File.join(@test_dir, 'index'))
|
21
|
-
|
22
|
-
@wdir = create_temp_repo(@wdir_dot)
|
23
|
-
end
|
24
|
-
|
25
|
-
def teardown
|
26
|
-
if @tmp_path
|
27
|
-
#puts "teardown #{@tmp_path}"
|
28
|
-
FileUtils.rm_r(@tmp_path)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
|
33
|
-
def with_temp_bare
|
34
|
-
in_temp_dir do |path|
|
35
|
-
g = Git.clone(@wbare, 'new')
|
36
|
-
Dir.chdir('new') do
|
37
|
-
yield g
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
def create_temp_repo(clone_path)
|
43
|
-
filename = 'git_test' + Time.now.to_i.to_s + rand(300).to_s.rjust(3, '0')
|
44
|
-
@tmp_path = File.join("/tmp/", filename)
|
45
|
-
FileUtils.mkdir_p(@tmp_path)
|
46
|
-
FileUtils.cp_r(clone_path, @tmp_path)
|
47
|
-
tmp_path = File.join(@tmp_path, 'working')
|
48
|
-
Dir.chdir(tmp_path) do
|
49
|
-
FileUtils.mv('dot_git', '.git')
|
50
|
-
end
|
51
|
-
tmp_path
|
52
|
-
end
|
53
|
-
|
54
|
-
def in_temp_dir(remove_after = true)
|
55
|
-
filename = 'git_test' + Time.now.to_i.to_s + rand(300).to_s.rjust(3, '0')
|
56
|
-
tmp_path = File.join("/tmp/", filename)
|
57
|
-
FileUtils.mkdir(tmp_path)
|
58
|
-
Dir.chdir tmp_path do
|
59
|
-
yield tmp_path
|
60
|
-
end
|
61
|
-
FileUtils.rm_r(tmp_path) if remove_after
|
62
|
-
end
|
63
|
-
|
64
|
-
|
65
|
-
def new_file(name, contents)
|
66
|
-
File.open(name, 'w') do |f|
|
67
|
-
f.puts contents
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
def append_file(name, contents)
|
72
|
-
File.open(name, 'a') do |f|
|
73
|
-
f.puts contents
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
end
|