grit 1.1.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of grit might be problematic. Click here for more details.

Files changed (66) hide show
  1. data/History.txt +9 -0
  2. data/README.md +37 -11
  3. data/VERSION.yml +3 -3
  4. data/examples/ex_add_commit.rb +13 -0
  5. data/examples/ex_index.rb +14 -0
  6. data/lib/grit.rb +10 -3
  7. data/lib/grit/actor.rb +5 -5
  8. data/lib/grit/blob.rb +12 -12
  9. data/lib/grit/commit.rb +3 -3
  10. data/lib/grit/commit_stats.rb +26 -26
  11. data/lib/grit/config.rb +9 -9
  12. data/lib/grit/diff.rb +16 -16
  13. data/lib/grit/errors.rb +1 -1
  14. data/lib/grit/git-ruby.rb +108 -27
  15. data/lib/grit/git-ruby/commit_db.rb +11 -11
  16. data/lib/grit/git-ruby/file_index.rb +28 -28
  17. data/lib/grit/git-ruby/git_object.rb +14 -14
  18. data/lib/grit/git-ruby/internal/file_window.rb +4 -4
  19. data/lib/grit/git-ruby/internal/loose.rb +10 -10
  20. data/lib/grit/git-ruby/internal/pack.rb +29 -29
  21. data/lib/grit/git-ruby/internal/raw_object.rb +4 -4
  22. data/lib/grit/git-ruby/object.rb +9 -9
  23. data/lib/grit/git-ruby/repository.rb +111 -107
  24. data/lib/grit/git.rb +191 -14
  25. data/lib/grit/index.rb +21 -21
  26. data/lib/grit/lazy.rb +1 -1
  27. data/lib/grit/merge.rb +9 -9
  28. data/lib/grit/ref.rb +6 -31
  29. data/lib/grit/repo.rb +110 -65
  30. data/lib/grit/ruby1.9.rb +1 -1
  31. data/lib/grit/status.rb +24 -24
  32. data/lib/grit/submodule.rb +15 -15
  33. data/lib/grit/tag.rb +7 -57
  34. data/lib/grit/tree.rb +12 -12
  35. data/test/bench/benchmarks.rb +126 -0
  36. data/test/helper.rb +18 -0
  37. data/test/profile.rb +21 -0
  38. data/test/suite.rb +6 -0
  39. data/test/test_actor.rb +35 -0
  40. data/test/test_blame.rb +32 -0
  41. data/test/test_blame_tree.rb +33 -0
  42. data/test/test_blob.rb +83 -0
  43. data/test/test_commit.rb +207 -0
  44. data/test/test_commit_stats.rb +33 -0
  45. data/test/test_commit_write.rb +20 -0
  46. data/test/test_config.rb +58 -0
  47. data/test/test_diff.rb +18 -0
  48. data/test/test_file_index.rb +56 -0
  49. data/test/test_git.rb +105 -0
  50. data/test/test_grit.rb +32 -0
  51. data/test/test_head.rb +47 -0
  52. data/test/test_index_status.rb +40 -0
  53. data/test/test_merge.rb +17 -0
  54. data/test/test_raw.rb +16 -0
  55. data/test/test_real.rb +19 -0
  56. data/test/test_reality.rb +17 -0
  57. data/test/test_remote.rb +14 -0
  58. data/test/test_repo.rb +349 -0
  59. data/test/test_rubygit.rb +192 -0
  60. data/test/test_rubygit_alt.rb +40 -0
  61. data/test/test_rubygit_index.rb +76 -0
  62. data/test/test_rubygit_iv2.rb +28 -0
  63. data/test/test_submodule.rb +69 -0
  64. data/test/test_tag.rb +67 -0
  65. data/test/test_tree.rb +101 -0
  66. metadata +43 -13
@@ -0,0 +1,192 @@
1
+ require File.dirname(__FILE__) + '/helper'
2
+ require 'tempfile'
3
+
4
+ class TestRubyGit < Test::Unit::TestCase
5
+
6
+ def setup
7
+ @git = Git.new(File.join(File.dirname(__FILE__), *%w[dot_git]))
8
+ @commit_sha = '5e3ee1198672257164ce3fe31dea3e40848e68d5'
9
+ @tree_sha = 'cd7422af5a2e0fff3e94d6fb1a8fff03b2841881'
10
+ @blob_sha = '4232d073306f01cf0b895864e5a5cfad7dd76fce'
11
+ end
12
+
13
+ def test_init_gitdir
14
+ tf = Tempfile.new('gitdir')
15
+ temppath = tf.path
16
+ tf.unlink
17
+
18
+ git = Git.new(temppath)
19
+ git.init({})
20
+ assert File.exists?(File.join(temppath, 'config'))
21
+ end
22
+
23
+ def test_log_merge
24
+ c1 = '420eac97a826bfac8724b6b0eef35c20922124b7'
25
+ c2 = '30e367cef2203eba2b341dc9050993b06fd1e108'
26
+ out = @git.rev_list({:pretty => 'raw', :max_count => 10}, 'master')
27
+ assert_match "commit #{c1}", out
28
+ assert_match "commit #{c2}", out
29
+ end
30
+
31
+ def test_log_max_count
32
+ out = @git.rev_list({:max_count => 10}, 'master')
33
+ assert_equal 10, out.split("\n").size
34
+ end
35
+
36
+ def test_diff
37
+ commit1 = '2d3acf90f35989df8f262dc50beadc4ee3ae1560'
38
+ commit2 = '420eac97a826bfac8724b6b0eef35c20922124b7'
39
+ out = @git.diff({}, commit1, commit2)
40
+ assert_match 'index 6afcf64..9e78ddf 100644', out
41
+ end
42
+
43
+ def test_diff_single
44
+ commit1 = '2d3acf90f35989df8f262dc50beadc4ee3ae1560'
45
+ out = @git.diff({}, commit1, nil)
46
+ assert_match 'index ad42ff5..aa50f09 100644', out
47
+ end
48
+
49
+ def test_diff_full
50
+ commit1 = '2d3acf90f35989df8f262dc50beadc4ee3ae1560'
51
+ commit2 = '420eac97a826bfac8724b6b0eef35c20922124b7'
52
+ out = @git.diff({:full_index => true}, commit1, commit2)
53
+ assert_match 'index 6afcf64c80da8253fa47228eb09bc0eea217e5d1..9e78ddfaabf79f8314cc9a53a2f59775aee06bd7', out
54
+ end
55
+
56
+ def test_diff_add
57
+ commit1 = 'c9cf68fc61bd2634e90a4f6a12d88744e6297c4e'
58
+ commit2 = '7a8d32cb18a0ba2ff8bf86cadacc3fd2816da219'
59
+ out = @git.diff({}, commit1, commit2)
60
+ assert_match "--- /dev/null\n+++ b/test/test_tag.rb", out
61
+ assert_match "diff --git a/test/test_tag.rb b/test/test_tag.rb", out
62
+ assert_match 'index 0000000..2e3b0cb', out
63
+ end
64
+
65
+ def test_diff_remove
66
+ commit1 = 'c9cf68fc61bd2634e90a4f6a12d88744e6297c4e'
67
+ commit2 = '7a8d32cb18a0ba2ff8bf86cadacc3fd2816da219'
68
+ out = @git.diff({}, commit1, commit2)
69
+ assert_match "--- a/test/fixtures/diff_2\n+++ /dev/null", out
70
+ assert_match "diff --git a/test/fixtures/diff_2 b/test/fixtures/diff_2", out
71
+ assert_match 'index 0000000..2e3b0cb', out
72
+ end
73
+
74
+
75
+ def test_cat_file_contents_commit
76
+ out = @git.cat_file({:p => true}, @commit_sha)
77
+ assert_equal out, fixture('cat_file_commit_ruby')
78
+ end
79
+
80
+ def test_cat_file_contents_tree
81
+ out = @git.cat_file({:p => true}, @tree_sha)
82
+ assert_equal out, fixture('cat_file_tree_ruby').chomp
83
+ end
84
+
85
+ def test_cat_file_contents_blob
86
+ out = @git.cat_file({:p => true}, @blob_sha)
87
+ assert_equal out, fixture('cat_file_blob_ruby')
88
+ end
89
+
90
+ def test_cat_file_size
91
+ out = @git.cat_file({:s => true}, @tree_sha)
92
+ assert_equal '252', out
93
+ end
94
+
95
+ def test_ls_tree
96
+ out = @git.ls_tree({}, @tree_sha)
97
+ assert_equal out, fixture('cat_file_tree_ruby').chomp
98
+ end
99
+
100
+ def test_ls_tree_with_blobs
101
+ out = @git.ls_tree({}, @blob_sha)
102
+ assert_equal out, nil
103
+ end
104
+
105
+ def test_ls_tree_treeish
106
+ out = @git.ls_tree({}, 'testing')
107
+ assert_equal out, fixture('cat_file_tree_ruby').chomp
108
+ end
109
+
110
+ def test_ls_tree_paths
111
+ paths = ['History.txt', 'lib']
112
+ out = @git.ls_tree({}, @tree_sha, paths)
113
+ assert_equal out, fixture('ls_tree_paths_ruby').chomp
114
+ end
115
+
116
+ def test_ls_tree_paths_multi_single
117
+ paths = ['lib/grit.rb']
118
+ out = @git.ls_tree({}, @tree_sha, paths)
119
+ assert_equal out, "100644 blob 6afcf64c80da8253fa47228eb09bc0eea217e5d1\tlib/grit.rb"
120
+ end
121
+
122
+ def test_rev_list_pretty
123
+ out = @git.rev_list({:pretty => 'raw'}, 'master')
124
+ assert_equal out, fixture('rev_list_all')
125
+ end
126
+
127
+ def test_rev_list_raw_since
128
+ out = @git.rev_list({:since => Time.at(1204644738)}, 'master')
129
+ assert_match fixture('rev_list_since'), out # I return slightly more for now
130
+ end
131
+
132
+ def test_rev_list_pretty_raw
133
+ out = @git.rev_list({:pretty => 'raw'}, 'f1964ad1919180dd1d9eae9d21a1a1f68ac60e77')
134
+ assert_match 'f1964ad1919180dd1d9eae9d21a1a1f68ac60e77', out
135
+ assert_equal out.split("\n").size, 654
136
+ end
137
+
138
+ def test_rev_list
139
+ out = @git.rev_list({}, 'master')
140
+ assert_equal out, fixture('rev_list_lines')
141
+ end
142
+
143
+ def test_rev_list_range
144
+ range = '30e367cef2203eba2b341dc9050993b06fd1e108..3fa4e130fa18c92e3030d4accb5d3e0cadd40157'
145
+ out = @git.rev_list({}, range)
146
+ assert_equal fixture('rev_list_range'), out
147
+ end
148
+
149
+ def test_ls_tree_paths_multi
150
+ paths = ['History.txt', 'lib/grit.rb']
151
+ out = @git.ls_tree({}, @tree_sha, paths)
152
+ assert_equal out, fixture('ls_tree_paths_ruby_deep').chomp
153
+ end
154
+
155
+ def test_ls_tree_path
156
+ paths = ['lib/']
157
+ out = @git.ls_tree({}, @tree_sha, paths)
158
+ assert_equal out, "100644 blob 6afcf64c80da8253fa47228eb09bc0eea217e5d1\tlib/grit.rb\n040000 tree 6244414d0229fb2bd58bc426a2afb5ba66773498\tlib/grit"
159
+ end
160
+
161
+ def test_ls_tree_path_deep
162
+ paths = ['lib/grit/']
163
+ out = @git.ls_tree({}, @tree_sha, paths)
164
+ assert_equal out, fixture('ls_tree_subdir').chomp
165
+ end
166
+
167
+ def test_file_type
168
+ out = @git.file_type(@tree_sha).to_s
169
+ assert_equal 'tree', out
170
+ out = @git.file_type(@blob_sha).to_s
171
+ assert_equal 'blob', out
172
+ out = @git.file_type(@commit_sha).to_s
173
+ assert_equal 'commit', out
174
+ end
175
+
176
+ #def test_ls_tree_noexist
177
+ # puts out = @git.ls_tree({}, '6afcf64c80da8253fa47228eb09bc0eea217e5d0')
178
+ #end
179
+
180
+
181
+ =begin
182
+ def test_ls_tree_grit_tree
183
+ paths = ['lib/grit.rb']
184
+ @repo = Grit::Repo.new('~/projects/github')
185
+ paths = ['app/models/event.rb']
186
+ puts out = @repo.git.ls_tree({}, 'master', ['app/models/event.rb'])
187
+ puts out = @repo.tree('master', paths).contents
188
+ assert_equal out, '100644 blob 6afcf64c80da8253fa47228eb09bc0eea217e5d1 lib/grit.rb'
189
+ end
190
+ =end
191
+
192
+ end
@@ -0,0 +1,40 @@
1
+ require File.dirname(__FILE__) + '/helper'
2
+ require 'pp'
3
+
4
+ class TestRubyGitAlt < Test::Unit::TestCase
5
+
6
+ def setup
7
+ @git1 = Grit::Repo.new(File.join(File.dirname(__FILE__), *%w[dot_git]), :is_bare => true)
8
+ @git2 = Grit::Repo.new(File.join(File.dirname(__FILE__), *%w[dot_git_clone]), :is_bare => true)
9
+ @git3 = Grit::Repo.new(File.join(File.dirname(__FILE__), *%w[dot_git_clone2]), :is_bare => true)
10
+ @commit_sha = 'ca8a30f5a7f0f163bbe3b6f0abf18a6c83b0687a'
11
+ @tree_sha = 'cd7422af5a2e0fff3e94d6fb1a8fff03b2841881'
12
+ @blob_sha = '4232d073306f01cf0b895864e5a5cfad7dd76fce'
13
+ end
14
+
15
+ def test_basic
16
+ sha_hex = [@commit_sha].pack("H*")
17
+ assert @git1.git.ruby_git.in_loose?(sha_hex)
18
+ assert @git2.git.ruby_git.in_loose?(sha_hex)
19
+ assert @git1.git.ruby_git.object_exists?(@commit_sha)
20
+ assert @git2.git.ruby_git.object_exists?(@commit_sha)
21
+ assert_equal 10, @git1.commits.size
22
+ assert_equal 10, @git2.commits.size
23
+ end
24
+
25
+ def test_clone_of_clone
26
+ sha_hex = [@commit_sha].pack("H*")
27
+ assert @git2.git.ruby_git.in_loose?(sha_hex)
28
+ assert @git3.git.ruby_git.in_loose?(sha_hex)
29
+ assert @git2.git.ruby_git.object_exists?(@commit_sha)
30
+ assert @git3.git.ruby_git.object_exists?(@commit_sha)
31
+ assert_equal 10, @git2.commits.size
32
+ assert_equal 10, @git3.commits.size
33
+ end
34
+
35
+ def test_tree_path
36
+ file = @git2.tree('master', ['test/test_head.rb']).contents.first.name
37
+ assert_equal file, 'test/test_head.rb'
38
+ end
39
+
40
+ end
@@ -0,0 +1,76 @@
1
+ require File.dirname(__FILE__) + '/helper'
2
+ require 'pp'
3
+
4
+ class TestRubyGitIndex < Test::Unit::TestCase
5
+
6
+ def setup
7
+ @base_repo = create_temp_repo(File.join(File.dirname(__FILE__), *%w[dot_git_iv2]))
8
+ @git = Grit::Repo.new(@base_repo, :is_bare => true)
9
+ @rgit = @git.git.ruby_git
10
+ @user = Actor.from_string("Tom Werner <tom@example.com>")
11
+ end
12
+
13
+ def teardown
14
+ FileUtils.rm_r(@base_repo)
15
+ end
16
+
17
+ def create_temp_repo(clone_path)
18
+ filename = 'git_test' + Time.now.to_i.to_s + rand(300).to_s.rjust(3, '0')
19
+ tmp_path = File.join("/tmp/", filename)
20
+ FileUtils.mkdir_p(tmp_path)
21
+ FileUtils.cp_r(clone_path, tmp_path)
22
+ File.join(tmp_path, 'dot_git_iv2')
23
+ end
24
+
25
+ def test_add_files
26
+ sha = @git.commits.first.tree.id
27
+
28
+ i = @git.index
29
+ i.read_tree(sha)
30
+ i.add('atester.rb', 'test stuff')
31
+ i.commit('message', [@git.commits.first], @user, nil, 'master')
32
+
33
+ b = @git.commits.first.tree/'atester.rb'
34
+ assert_equal 'f80c3b68482d5e1c8d24c9b8139340f0d0a928d0', b.id
35
+ end
36
+
37
+ def test_add_path_file
38
+ sha = @git.commits.first.tree.id
39
+
40
+ i = @git.index
41
+ i.read_tree(sha)
42
+ i.add('lib/atester.rb', 'test stuff')
43
+ i.commit('message', [@git.commits.first], @user, nil, 'master')
44
+
45
+ b = @git.commits.first.tree/'lib'/'atester.rb'
46
+ assert_equal 'f80c3b68482d5e1c8d24c9b8139340f0d0a928d0', b.id
47
+ b = @git.commits.first.tree/'lib'/'grit.rb'
48
+ assert_equal '77aa887449c28a922a660b2bb749e4127f7664e5', b.id
49
+ end
50
+
51
+ def test_ordered_properly
52
+ sha = @git.commits.first.tree.id
53
+
54
+ i = @git.index
55
+ i.read_tree(sha)
56
+ i.add('lib.rb', 'test stuff')
57
+ i.commit('message', [@git.commits.first], @user, nil, 'master')
58
+
59
+ tr = @git.commits.first.tree.contents
60
+ entries = tr.select { |c| c.name[0, 3] == 'lib' }.map { |c| c.name }
61
+ assert_equal 'lib.rb', entries[0]
62
+ assert_equal 'lib', entries[1]
63
+ end
64
+
65
+ def test_modify_file
66
+ sha = @git.commits.first.tree.id
67
+
68
+ i = @git.index
69
+ i.read_tree(sha)
70
+ i.add('README.txt', 'test more stuff')
71
+ i.commit('message', [@git.commits.first], @user, nil, 'master')
72
+
73
+ b = @git.commits.first.tree/'README.txt'
74
+ assert_equal 'e45d6b418e34951ddaa3e78e4fc4d3d92a46d3d1', b.id
75
+ end
76
+ end
@@ -0,0 +1,28 @@
1
+ require File.dirname(__FILE__) + '/helper'
2
+ require 'pp'
3
+
4
+ class TestRubyGitIv2 < Test::Unit::TestCase
5
+
6
+ def setup
7
+ @git = Grit::Repo.new(File.join(File.dirname(__FILE__), *%w[dot_git_iv2]), :is_bare => true)
8
+ @rgit = @git.git.ruby_git
9
+ @commit_sha = 'ca8a30f5a7f0f163bbe3b6f0abf18a6c83b0687a'
10
+ @tree_sha = 'cd7422af5a2e0fff3e94d6fb1a8fff03b2841881'
11
+ @blob_sha = '4232d073306f01cf0b895864e5a5cfad7dd76fce'
12
+ end
13
+
14
+ def test_basic
15
+ assert @rgit.object_exists?(@commit_sha)
16
+ assert_equal 10, @git.commits.size
17
+ end
18
+
19
+ def test_objects
20
+ commit = @rgit.get_object_by_sha1(@commit_sha)
21
+ assert_equal commit.author.email, 'schacon@gmail.com'
22
+ tree = @rgit.get_object_by_sha1(@tree_sha)
23
+ assert_equal 7, tree.entry.size
24
+ blob = @rgit.get_object_by_sha1(@blob_sha)
25
+ assert_match 'First public release', blob.content
26
+ end
27
+
28
+ end
@@ -0,0 +1,69 @@
1
+ require File.dirname(__FILE__) + '/helper'
2
+
3
+ class TestSubmodule < Test::Unit::TestCase
4
+ def setup
5
+ @r = Repo.new(GRIT_REPO)
6
+ @s = Submodule.allocate
7
+ end
8
+
9
+ # config
10
+
11
+ def test_config
12
+ data = fixture('gitmodules')
13
+ blob = stub(:data => data, :id => 'abc')
14
+ tree = stub(:'/' => blob)
15
+ commit = stub(:tree => tree)
16
+ repo = stub(:commit => commit)
17
+
18
+ config = Submodule.config(repo)
19
+
20
+ assert_equal "git://github.com/mojombo/glowstick", config['test/glowstick']['url']
21
+ assert_equal "git://github.com/mojombo/god", config['god']['url']
22
+ end
23
+
24
+ def test_config_with_windows_lineendings
25
+ data = fixture('gitmodules').gsub(/\n/, "\r\n")
26
+ blob = stub(:data => data, :id => 'abc')
27
+ tree = stub(:'/' => blob)
28
+ commit = stub(:tree => tree)
29
+ repo = stub(:commit => commit)
30
+
31
+ config = Submodule.config(repo)
32
+
33
+ assert_equal "git://github.com/mojombo/glowstick", config['test/glowstick']['url']
34
+ assert_equal "git://github.com/mojombo/god", config['god']['url']
35
+ end
36
+
37
+ def test_no_config
38
+ tree = stub(:'/' => nil)
39
+ commit = stub(:tree => tree)
40
+ repo = stub(:commit => commit)
41
+
42
+ config = Submodule.config(repo)
43
+
44
+ assert_equal({}, config)
45
+ end
46
+
47
+ def test_empty_config
48
+ blob = stub(:data => '', :id => 'abc')
49
+ tree = stub(:'/' => blob)
50
+ commit = stub(:tree => tree)
51
+ repo = stub(:commit => commit)
52
+
53
+ config = Submodule.config(repo)
54
+
55
+ assert_equal({}, config)
56
+ end
57
+
58
+ # inspect
59
+
60
+ def test_inspect
61
+ @t = Submodule.create(@r, :id => 'abc')
62
+ assert_equal %Q{#<Grit::Submodule "abc">}, @t.inspect
63
+ end
64
+
65
+ def test_basename
66
+ @submodule = Submodule.create(@r, :name => 'foo/bar')
67
+ assert_equal "bar", @submodule.basename
68
+ end
69
+ end
@@ -0,0 +1,67 @@
1
+ require File.dirname(__FILE__) + '/helper'
2
+
3
+ class TestTag < Test::Unit::TestCase
4
+ def setup
5
+ @r = Repo.new(File.join(File.dirname(__FILE__), *%w[dot_git]), :is_bare => true)
6
+ end
7
+
8
+ # list_from_string size
9
+
10
+ def test_list_from_string_size
11
+ assert_equal 5, @r.tags.size
12
+ end
13
+
14
+ # list_from_string
15
+
16
+ def test_list_from_string
17
+ tag = @r.tags[1]
18
+
19
+ assert_equal 'not_annotated', tag.name
20
+ assert_equal 'ca8a30f5a7f0f163bbe3b6f0abf18a6c83b0687a', tag.commit.id
21
+ end
22
+
23
+ # list_from_string_for_signed_tag
24
+
25
+ def test_list_from_string_for_signed_tag
26
+ tag = @r.tags[2]
27
+
28
+ assert_equal 'v0.7.0', tag.name
29
+ assert_equal '7bcc0ee821cdd133d8a53e8e7173a334fef448aa', tag.commit.id
30
+ end
31
+
32
+ # list_from_string_for_annotated_tag
33
+
34
+ def test_list_from_string_for_annotated_tag
35
+ tag = @r.tags.first
36
+
37
+ assert_equal 'annotated', tag.name
38
+ assert_equal 'ca8a30f5a7f0f163bbe3b6f0abf18a6c83b0687a', tag.commit.id
39
+ end
40
+
41
+ # list_from_string_for_packed_tag
42
+
43
+ def test_list_from_string_for_packed_tag
44
+ tag = @r.tags[4]
45
+
46
+ assert_equal 'packed', tag.name
47
+ assert_equal 'ca8a30f5a7f0f163bbe3b6f0abf18a6c83b0687a', tag.commit.id
48
+ end
49
+
50
+ # list_from_string_for_packed_annotated_tag
51
+
52
+ def test_list_from_string_for_packed_annotated_tag
53
+ tag = @r.tags[3]
54
+
55
+ assert_equal 'packed_annotated', tag.name
56
+ assert_equal '7bcc0ee821cdd133d8a53e8e7173a334fef448aa', tag.commit.id
57
+ end
58
+
59
+
60
+ # inspect
61
+
62
+ def test_inspect
63
+ tag = @r.tags.last
64
+
65
+ assert_equal %Q{#<Grit::Tag "#{tag.name}">}, tag.inspect
66
+ end
67
+ end