boof-grit 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. data/API.txt +101 -0
  2. data/History.txt +53 -0
  3. data/LICENSE +22 -0
  4. data/README.md +210 -0
  5. data/VERSION.yml +4 -0
  6. data/examples/ex_add_commit.rb +13 -0
  7. data/examples/ex_index.rb +14 -0
  8. data/lib/grit.rb +68 -0
  9. data/lib/grit/actor.rb +36 -0
  10. data/lib/grit/blame.rb +61 -0
  11. data/lib/grit/blob.rb +126 -0
  12. data/lib/grit/commit.rb +246 -0
  13. data/lib/grit/commit_stats.rb +128 -0
  14. data/lib/grit/config.rb +44 -0
  15. data/lib/grit/diff.rb +70 -0
  16. data/lib/grit/errors.rb +7 -0
  17. data/lib/grit/git-ruby.rb +186 -0
  18. data/lib/grit/git-ruby/commit_db.rb +52 -0
  19. data/lib/grit/git-ruby/file_index.rb +193 -0
  20. data/lib/grit/git-ruby/git_object.rb +350 -0
  21. data/lib/grit/git-ruby/internal/file_window.rb +58 -0
  22. data/lib/grit/git-ruby/internal/loose.rb +137 -0
  23. data/lib/grit/git-ruby/internal/pack.rb +382 -0
  24. data/lib/grit/git-ruby/internal/raw_object.rb +37 -0
  25. data/lib/grit/git-ruby/object.rb +325 -0
  26. data/lib/grit/git-ruby/repository.rb +740 -0
  27. data/lib/grit/git.rb +141 -0
  28. data/lib/grit/index.rb +122 -0
  29. data/lib/grit/lazy.rb +33 -0
  30. data/lib/grit/merge.rb +45 -0
  31. data/lib/grit/ref.rb +177 -0
  32. data/lib/grit/repo.rb +452 -0
  33. data/lib/grit/ruby1.9.rb +7 -0
  34. data/lib/grit/status.rb +151 -0
  35. data/lib/grit/submodule.rb +88 -0
  36. data/lib/grit/tag.rb +66 -0
  37. data/lib/grit/tree.rb +123 -0
  38. data/lib/open3_detach.rb +46 -0
  39. data/test/bench/benchmarks.rb +126 -0
  40. data/test/helper.rb +18 -0
  41. data/test/profile.rb +21 -0
  42. data/test/suite.rb +6 -0
  43. data/test/test_actor.rb +35 -0
  44. data/test/test_blame.rb +32 -0
  45. data/test/test_blame_tree.rb +33 -0
  46. data/test/test_blob.rb +83 -0
  47. data/test/test_commit.rb +207 -0
  48. data/test/test_commit_stats.rb +33 -0
  49. data/test/test_commit_write.rb +20 -0
  50. data/test/test_config.rb +58 -0
  51. data/test/test_diff.rb +18 -0
  52. data/test/test_file_index.rb +56 -0
  53. data/test/test_git.rb +94 -0
  54. data/test/test_grit.rb +32 -0
  55. data/test/test_head.rb +72 -0
  56. data/test/test_index_status.rb +40 -0
  57. data/test/test_merge.rb +17 -0
  58. data/test/test_raw.rb +16 -0
  59. data/test/test_real.rb +19 -0
  60. data/test/test_reality.rb +17 -0
  61. data/test/test_remote.rb +14 -0
  62. data/test/test_repo.rb +381 -0
  63. data/test/test_rubygit.rb +192 -0
  64. data/test/test_rubygit_alt.rb +40 -0
  65. data/test/test_rubygit_index.rb +76 -0
  66. data/test/test_rubygit_iv2.rb +28 -0
  67. data/test/test_submodule.rb +69 -0
  68. data/test/test_tag.rb +103 -0
  69. data/test/test_tree.rb +101 -0
  70. metadata +143 -0
data/test/test_raw.rb ADDED
@@ -0,0 +1,16 @@
1
+ require File.dirname(__FILE__) + '/helper'
2
+ require 'pp'
3
+
4
+ class TestFileIndex < Test::Unit::TestCase
5
+
6
+ def setup
7
+ @r = Grit::Repo.new(File.join(File.dirname(__FILE__), *%w[dot_git]), :is_bare => true)
8
+ @tag = 'f0055fda16c18fd8b27986dbf038c735b82198d7'
9
+ end
10
+
11
+ def test_raw_tag
12
+ tag = @r.git.ruby_git.get_object_by_sha1(@tag)
13
+ assert_match Regexp.new('v0.7.0'), tag.raw_content
14
+ end
15
+
16
+ end
data/test/test_real.rb ADDED
@@ -0,0 +1,19 @@
1
+ # require File.dirname(__FILE__) + '/helper'
2
+ #
3
+ # class TestReal < Test::Unit::TestCase
4
+ # def setup
5
+ # `rm -fr /Users/tom/dev/sandbox/grittest.git`
6
+ # `git --git-dir=/Users/tom/dev/sandbox/grittest.git init`
7
+ # @repo = Repo.new('/Users/tom/dev/sandbox/grittest.git')
8
+ # end
9
+ #
10
+ # def test_real
11
+ # Grit.debug = true
12
+ #
13
+ # index = @repo.index
14
+ # index.add('foo/bar/baz.txt', 'hello!')
15
+ # index.add('foo/qux/bam.txt', 'world!')
16
+ #
17
+ # puts index.commit('first commit')
18
+ # end
19
+ # end
@@ -0,0 +1,17 @@
1
+ require File.dirname(__FILE__) + '/helper'
2
+
3
+ # class TestTreeRecursion < Test::Unit::TestCase
4
+ # def test_
5
+ # r = Repo.new("/Users/tom/dev/god")
6
+ # t = r.tree("HEAD")
7
+ #
8
+ # recurse(t)
9
+ # end
10
+ #
11
+ # def recurse(tree, indent = "")
12
+ # tree.contents.each do |c|
13
+ # # puts "#{indent}#{c.name} (#{c.id})"
14
+ # recurse(c, indent + " ") if c.kind_of?(Tree)
15
+ # end
16
+ # end
17
+ # end
@@ -0,0 +1,14 @@
1
+ require File.dirname(__FILE__) + '/helper'
2
+
3
+ class TestRemote < Test::Unit::TestCase
4
+ def setup
5
+ @r = Repo.new(GRIT_REPO)
6
+ end
7
+
8
+ # inspect
9
+
10
+ def test_inspect
11
+ remote = @r.remotes.first
12
+ assert_equal %Q{#<Grit::Remote "#{remote.name}">}, remote.inspect
13
+ end
14
+ end
data/test/test_repo.rb ADDED
@@ -0,0 +1,381 @@
1
+ require File.dirname(__FILE__) + '/helper'
2
+
3
+ class TestRepo < Test::Unit::TestCase
4
+ def setup
5
+ @r = Repo.new(GRIT_REPO, :work_tree => true)
6
+ end
7
+
8
+ def create_temp_repo(clone_path)
9
+ filename = 'git_test' + Time.now.to_i.to_s + rand(300).to_s.rjust(3, '0')
10
+ tmp_path = File.join("/tmp/", filename)
11
+ FileUtils.mkdir_p(tmp_path)
12
+ FileUtils.cp_r(clone_path, tmp_path)
13
+ File.join(tmp_path, 'dot_git')
14
+ end
15
+
16
+ def test_update_refs_packed
17
+ gpath = create_temp_repo(File.join(File.dirname(__FILE__), *%w[dot_git]))
18
+ @git = Grit::Repo.new(gpath, :is_bare => true)
19
+
20
+ # new and existing
21
+ test = 'ac9a30f5a7f0f163bbe3b6f0abf18a6c83b06872'
22
+ master = 'ca8a30f5a7f0f163bbe3b6f0abf18a6c83b0687a'
23
+
24
+ @git.update_ref('testref', test)
25
+ new_t = @git.get_head('testref').commit.sha
26
+ assert new_t != master
27
+
28
+ @git.update_ref('master', test)
29
+ new_m = @git.get_head('master').commit.sha
30
+ assert new_m != master
31
+
32
+ old = @git.get_head('nonpack').commit.sha
33
+ @git.update_ref('nonpack', test)
34
+ newp = @git.get_head('nonpack').commit.sha
35
+ assert newp != old
36
+
37
+ FileUtils.rm_r(gpath)
38
+ end
39
+
40
+ # init
41
+
42
+ def assert_and_cleanup_directories(work_tree, git_dir)
43
+ directories_exist = File.exists?(work_tree) && File.exists?(git_dir)
44
+ FileUtils.rm_r work_tree rescue nil
45
+
46
+ assert directories_exist,
47
+ "expected #{ work_tree } and #{ git_dir } to exist"
48
+ end
49
+ def assert_initialized_repository(work_tree, git_dir, options = {})
50
+ assert_nothing_raised do
51
+ assert_instance_of Grit::Repo, Repo.init(work_tree, options)
52
+ end
53
+ assert_and_cleanup_directories work_tree, git_dir
54
+ end
55
+ def test_init_creates_a_repository
56
+ work_tree = File.join File.dirname(__FILE__), 'tmp'
57
+ git_dir = File.join work_tree, '.git'
58
+ assert_initialized_repository work_tree, git_dir
59
+ end
60
+ def test_init_creates_a_bare_repository
61
+ work_tree = File.join File.dirname(__FILE__), 'tmp.git'
62
+ git_dir = work_tree
63
+ assert_initialized_repository work_tree, git_dir
64
+ end
65
+ def test_init_creates_a_bare_repository_when_forced
66
+ work_tree = File.join File.dirname(__FILE__), 'tmp'
67
+ git_dir = work_tree
68
+ assert_initialized_repository work_tree, git_dir, :is_bare => true
69
+ end
70
+
71
+ # new
72
+
73
+ def test_new_should_raise_on_invalid_repo_location
74
+ assert_raise(InvalidGitRepositoryError) do
75
+ Repo.new("/tmp")
76
+ end
77
+ end
78
+
79
+ def test_new_should_raise_on_non_existant_path
80
+ assert_raise(NoSuchPathError) do
81
+ Repo.new("/foobar")
82
+ end
83
+ end
84
+
85
+ # descriptions
86
+
87
+ def test_description
88
+ expect = File.read File.join(GRIT_REPO, '.git', 'description')
89
+ expect.chomp!
90
+
91
+ assert_equal expect, @r.description
92
+ end
93
+
94
+ # refs
95
+
96
+ def test_refs_should_return_array_of_ref_objects
97
+ @r.refs.each do |ref|
98
+ assert ref.is_a?(Grit::Ref)
99
+ end
100
+ end
101
+
102
+ # heads
103
+
104
+ def test_current_head
105
+ @r = Repo.new(File.join(File.dirname(__FILE__), *%w[dot_git]), :is_bare => true)
106
+ head = @r.head
107
+ assert_equal Grit::Head, head.class
108
+ assert_equal 'master', head.name
109
+ assert_equal 'ca8a30f5a7f0f163bbe3b6f0abf18a6c83b0687a', @r.commits(head.name).first.id
110
+ end
111
+
112
+ def test_heads_should_return_array_of_head_objects
113
+ @r.heads.each do |head|
114
+ assert_equal Grit::Head, head.class
115
+ end
116
+ end
117
+
118
+ def test_heads_should_populate_head_data
119
+ @r = Repo.new(File.join(File.dirname(__FILE__), *%w[dot_git]), :is_bare => true)
120
+ head = @r.heads[1]
121
+
122
+ assert_equal 'test/master', head.name
123
+ assert_equal '2d3acf90f35989df8f262dc50beadc4ee3ae1560', head.commit.id
124
+ end
125
+
126
+ # branches
127
+
128
+ def test_branches
129
+ # same as heads
130
+ end
131
+
132
+ # commits
133
+
134
+ def test_commits
135
+ Git.any_instance.expects(:rev_list).returns(fixture('rev_list'))
136
+
137
+ commits = @r.commits('master', 10)
138
+
139
+ c = commits[0]
140
+ assert_equal '4c8124ffcf4039d292442eeccabdeca5af5c5017', c.id
141
+ assert_equal ["634396b2f541a9f2d58b00be1a07f0c358b999b3"], c.parents.map { |p| p.id }
142
+ assert_equal "672eca9b7f9e09c22dcb128c283e8c3c8d7697a4", c.tree.id
143
+ assert_equal "Tom Preston-Werner", c.author.name
144
+ assert_equal "tom@mojombo.com", c.author.email
145
+ assert_equal Time.at(1191999972), c.authored_date
146
+ assert_equal "Tom Preston-Werner", c.committer.name
147
+ assert_equal "tom@mojombo.com", c.committer.email
148
+ assert_equal Time.at(1191999972), c.committed_date
149
+ assert_equal "implement Grit#heads", c.message
150
+
151
+ c = commits[1]
152
+ assert_equal [], c.parents
153
+
154
+ c = commits[2]
155
+ assert_equal ["6e64c55896aabb9a7d8e9f8f296f426d21a78c2c", "7f874954efb9ba35210445be456c74e037ba6af2"], c.parents.map { |p| p.id }
156
+ assert_equal "Merge branch 'site'\n\n * Some other stuff\n * just one more", c.message
157
+ assert_equal "Merge branch 'site'", c.short_message
158
+ end
159
+
160
+ # commit_count
161
+
162
+ def test_commit_count
163
+ Git.any_instance.expects(:rev_list).with({}, 'master').returns(fixture('rev_list_count'))
164
+
165
+ assert_equal 655, @r.commit_count('master')
166
+ end
167
+
168
+ # commit
169
+
170
+ def test_commit
171
+ commit = @r.commit('634396b2f541a9f2d58b00be1a07f0c358b999b3')
172
+
173
+ assert_equal "634396b2f541a9f2d58b00be1a07f0c358b999b3", commit.id
174
+ end
175
+
176
+ # tree
177
+
178
+ def test_tree
179
+ Git.any_instance.expects(:ls_tree).returns(fixture('ls_tree_a'))
180
+ tree = @r.tree('master')
181
+
182
+ assert_equal 4, tree.contents.select { |c| c.instance_of?(Blob) }.size
183
+ assert_equal 3, tree.contents.select { |c| c.instance_of?(Tree) }.size
184
+ end
185
+
186
+ # blob
187
+
188
+ def test_blob
189
+ Git.any_instance.expects(:cat_file).returns(fixture('cat_file_blob'))
190
+ blob = @r.blob("abc")
191
+ assert_equal "Hello world", blob.data
192
+ end
193
+
194
+ # init_bare
195
+
196
+ def test_init_bare
197
+ Git.any_instance.expects(:init).returns(true)
198
+ Repo.expects(:new).with("/foo/bar.git", {})
199
+ Repo.init_bare("/foo/bar.git")
200
+ end
201
+
202
+ def test_init_bare_with_options
203
+ Git.any_instance.expects(:init).with(
204
+ :template => "/baz/sweet").returns(true)
205
+ Repo.expects(:new).with("/foo/bar.git", {})
206
+ Repo.init_bare("/foo/bar.git", :template => "/baz/sweet")
207
+ end
208
+
209
+ # fork_bare
210
+
211
+ def test_fork_bare
212
+ Git.any_instance.expects(:clone).with(
213
+ {:bare => true, :shared => true},
214
+ "#{absolute_project_path}/.git",
215
+ "/foo/bar.git").returns(nil)
216
+ Repo.expects(:new)
217
+
218
+ @r.fork_bare("/foo/bar.git")
219
+ end
220
+
221
+ def test_fork_bare_with_options
222
+ Git.any_instance.expects(:clone).with(
223
+ {:bare => true, :shared => true, :template => '/awesome'},
224
+ "#{absolute_project_path}/.git",
225
+ "/foo/bar.git").returns(nil)
226
+ Repo.expects(:new)
227
+
228
+ @r.fork_bare("/foo/bar.git", :template => '/awesome')
229
+ end
230
+
231
+ # diff
232
+
233
+ def test_diff
234
+ Git.any_instance.expects(:diff).with({}, 'master^', 'master', '--')
235
+ @r.diff('master^', 'master')
236
+
237
+ Git.any_instance.expects(:diff).with({}, 'master^', 'master', '--', 'foo/bar')
238
+ @r.diff('master^', 'master', 'foo/bar')
239
+
240
+ Git.any_instance.expects(:diff).with({}, 'master^', 'master', '--', 'foo/bar', 'foo/baz')
241
+ @r.diff('master^', 'master', 'foo/bar', 'foo/baz')
242
+ end
243
+
244
+ # commit_diff
245
+
246
+ def test_diff
247
+ Git.any_instance.expects(:diff).returns(fixture('diff_p'))
248
+ diffs = @r.commit_diff('master')
249
+
250
+ assert_equal 15, diffs.size
251
+ end
252
+
253
+ # init bare
254
+
255
+ # archive
256
+
257
+ def test_archive_tar
258
+ #@r.archive_tar -- no assertion being done here
259
+ end
260
+
261
+ # archive_tar_gz
262
+
263
+ def test_archive_tar_gz
264
+ #@r.archive_tar_gz -- again, no assertion
265
+ end
266
+
267
+ # enable_daemon_serve
268
+
269
+ def test_enable_daemon_serve
270
+ FileUtils.expects(:touch).with(File.join(@r.path, 'git-daemon-export-ok'))
271
+ @r.enable_daemon_serve
272
+ end
273
+
274
+ # disable_daemon_serve
275
+
276
+ def test_disable_daemon_serve
277
+ FileUtils.expects(:rm_f).with(File.join(@r.path, 'git-daemon-export-ok'))
278
+ @r.disable_daemon_serve
279
+ end
280
+
281
+ def test_gc_auto
282
+ Git.any_instance.expects(:gc).with({:auto => true})
283
+ @r.gc_auto
284
+ end
285
+
286
+ # alternates
287
+
288
+ def test_alternates_with_two_alternates
289
+ File.expects(:exist?).with("#{absolute_project_path}/.git/objects/info/alternates").returns(true)
290
+ File.expects(:read).returns("/path/to/repo1/.git/objects\n/path/to/repo2.git/objects\n")
291
+
292
+ assert_equal ["/path/to/repo1/.git/objects", "/path/to/repo2.git/objects"], @r.alternates
293
+ end
294
+
295
+ def test_alternates_no_file
296
+ File.expects(:exist?).returns(false)
297
+
298
+ assert_equal [], @r.alternates
299
+ end
300
+
301
+ # alternates=
302
+
303
+ def test_alternates_setter_ok
304
+ alts = %w{/path/to/repo.git/objects /path/to/repo2.git/objects}
305
+
306
+ alts.each do |alt|
307
+ File.expects(:exist?).with(alt).returns(true)
308
+ end
309
+
310
+ File.any_instance.expects(:write).with(alts.join("\n"))
311
+
312
+ assert_nothing_raised do
313
+ @r.alternates = alts
314
+ end
315
+ end
316
+
317
+ def test_alternates_setter_bad
318
+ alts = %w{/path/to/repo.git/objects}
319
+
320
+ alts.each do |alt|
321
+ File.expects(:exist?).with(alt).returns(false)
322
+ end
323
+
324
+ File.any_instance.expects(:write).never
325
+
326
+ assert_raise RuntimeError do
327
+ @r.alternates = alts
328
+ end
329
+ end
330
+
331
+ def test_alternates_setter_empty
332
+ File.any_instance.expects(:write)
333
+ @r.alternates = []
334
+ end
335
+
336
+ # inspect
337
+
338
+ def test_inspect
339
+ assert_equal %Q{#<Grit::Repo "#{File.expand_path(GRIT_REPO)}/.git">}, @r.inspect
340
+ end
341
+
342
+ # log
343
+
344
+ def test_log
345
+ Git.any_instance.expects(:log).times(2).with({:pretty => 'raw'}, 'master').returns(fixture('rev_list'))
346
+
347
+ assert_equal '4c8124ffcf4039d292442eeccabdeca5af5c5017', @r.log.first.id
348
+ assert_equal 'ab25fd8483882c3bda8a458ad2965d2248654335', @r.log.last.id
349
+ end
350
+
351
+ def test_log_with_path_and_options
352
+ Git.any_instance.expects(:log).with({:pretty => 'raw', :max_count => 1}, 'master', '--', 'file.rb').returns(fixture('rev_list'))
353
+ @r.log('master', 'file.rb', :max_count => 1)
354
+ end
355
+
356
+ # commit_deltas_from
357
+
358
+ def test_commit_deltas_from_nothing_new
359
+ other_repo = Repo.new(GRIT_REPO)
360
+ @r.git.expects(:rev_list).with({}, "master").returns(fixture("rev_list_delta_b"))
361
+ other_repo.git.expects(:rev_list).with({}, "master").returns(fixture("rev_list_delta_a"))
362
+
363
+ delta_blobs = @r.commit_deltas_from(other_repo)
364
+ assert_equal 0, delta_blobs.size
365
+ end
366
+
367
+ def test_commit_deltas_from_when_other_has_new
368
+ other_repo = Repo.new(GRIT_REPO)
369
+ @r.git.expects(:rev_list).with({}, "master").returns(fixture("rev_list_delta_a"))
370
+ other_repo.git.expects(:rev_list).with({}, "master").returns(fixture("rev_list_delta_b"))
371
+ %w[
372
+ 4c8124ffcf4039d292442eeccabdeca5af5c5017
373
+ 634396b2f541a9f2d58b00be1a07f0c358b999b3
374
+ ab25fd8483882c3bda8a458ad2965d2248654335
375
+ ].each do |ref|
376
+ Commit.expects(:find_all).with(other_repo, ref, :max_count => 1).returns([stub()])
377
+ end
378
+ delta_blobs = @r.commit_deltas_from(other_repo)
379
+ assert_equal 3, delta_blobs.size
380
+ end
381
+ end