square-circle-triangle-grit 1.1.2 → 1.1.3

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.
@@ -0,0 +1,188 @@
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 'index 0000000..2e3b0cb', out
61
+ end
62
+
63
+ def test_diff_remove
64
+ commit1 = 'c9cf68fc61bd2634e90a4f6a12d88744e6297c4e'
65
+ commit2 = '7a8d32cb18a0ba2ff8bf86cadacc3fd2816da219'
66
+ out = @git.diff({}, commit1, commit2)
67
+ assert_match 'index 0000000..2e3b0cb', out
68
+ end
69
+
70
+
71
+ def test_cat_file_contents_commit
72
+ out = @git.cat_file({:p => true}, @commit_sha)
73
+ assert_equal out, fixture('cat_file_commit_ruby')
74
+ end
75
+
76
+ def test_cat_file_contents_tree
77
+ out = @git.cat_file({:p => true}, @tree_sha)
78
+ assert_equal out, fixture('cat_file_tree_ruby').chomp
79
+ end
80
+
81
+ def test_cat_file_contents_blob
82
+ out = @git.cat_file({:p => true}, @blob_sha)
83
+ assert_equal out, fixture('cat_file_blob_ruby')
84
+ end
85
+
86
+ def test_cat_file_size
87
+ out = @git.cat_file({:s => true}, @tree_sha)
88
+ assert_equal '252', out
89
+ end
90
+
91
+ def test_ls_tree
92
+ out = @git.ls_tree({}, @tree_sha)
93
+ assert_equal out, fixture('cat_file_tree_ruby').chomp
94
+ end
95
+
96
+ def test_ls_tree_with_blobs
97
+ out = @git.ls_tree({}, @blob_sha)
98
+ assert_equal out, nil
99
+ end
100
+
101
+ def test_ls_tree_treeish
102
+ out = @git.ls_tree({}, 'testing')
103
+ assert_equal out, fixture('cat_file_tree_ruby').chomp
104
+ end
105
+
106
+ def test_ls_tree_paths
107
+ paths = ['History.txt', 'lib']
108
+ out = @git.ls_tree({}, @tree_sha, paths)
109
+ assert_equal out, fixture('ls_tree_paths_ruby').chomp
110
+ end
111
+
112
+ def test_ls_tree_paths_multi_single
113
+ paths = ['lib/grit.rb']
114
+ out = @git.ls_tree({}, @tree_sha, paths)
115
+ assert_equal out, '100644 blob 6afcf64c80da8253fa47228eb09bc0eea217e5d1 lib/grit.rb'
116
+ end
117
+
118
+ def test_rev_list_pretty
119
+ out = @git.rev_list({:pretty => 'raw'}, 'master')
120
+ assert_equal out, fixture('rev_list_all')
121
+ end
122
+
123
+ def test_rev_list_raw_since
124
+ out = @git.rev_list({:since => Time.at(1204644738)}, 'master')
125
+ assert_match fixture('rev_list_since'), out # I return slightly more for now
126
+ end
127
+
128
+ def test_rev_list_pretty_raw
129
+ out = @git.rev_list({:pretty => 'raw'}, 'f1964ad1919180dd1d9eae9d21a1a1f68ac60e77')
130
+ assert_match 'f1964ad1919180dd1d9eae9d21a1a1f68ac60e77', out
131
+ assert_equal out.split("\n").size, 654
132
+ end
133
+
134
+ def test_rev_list
135
+ out = @git.rev_list({}, 'master')
136
+ assert_equal out, fixture('rev_list_lines')
137
+ end
138
+
139
+ def test_rev_list_range
140
+ range = '30e367cef2203eba2b341dc9050993b06fd1e108..3fa4e130fa18c92e3030d4accb5d3e0cadd40157'
141
+ out = @git.rev_list({}, range)
142
+ assert_equal fixture('rev_list_range'), out
143
+ end
144
+
145
+ def test_ls_tree_paths_multi
146
+ paths = ['History.txt', 'lib/grit.rb']
147
+ out = @git.ls_tree({}, @tree_sha, paths)
148
+ assert_equal out, fixture('ls_tree_paths_ruby_deep').chomp
149
+ end
150
+
151
+ def test_ls_tree_path
152
+ paths = ['lib/']
153
+ out = @git.ls_tree({}, @tree_sha, paths)
154
+ assert_equal out, "100644 blob 6afcf64c80da8253fa47228eb09bc0eea217e5d1\tlib/grit.rb\n040000 tree 6244414d0229fb2bd58bc426a2afb5ba66773498\tlib/grit"
155
+ end
156
+
157
+ def test_ls_tree_path_deep
158
+ paths = ['lib/grit/']
159
+ out = @git.ls_tree({}, @tree_sha, paths)
160
+ assert_equal out, fixture('ls_tree_subdir').chomp
161
+ end
162
+
163
+ def test_file_type
164
+ out = @git.file_type(@tree_sha).to_s
165
+ assert_equal 'tree', out
166
+ out = @git.file_type(@blob_sha).to_s
167
+ assert_equal 'blob', out
168
+ out = @git.file_type(@commit_sha).to_s
169
+ assert_equal 'commit', out
170
+ end
171
+
172
+ #def test_ls_tree_noexist
173
+ # puts out = @git.ls_tree({}, '6afcf64c80da8253fa47228eb09bc0eea217e5d0')
174
+ #end
175
+
176
+
177
+ =begin
178
+ def test_ls_tree_grit_tree
179
+ paths = ['lib/grit.rb']
180
+ @repo = Grit::Repo.new('~/projects/github')
181
+ paths = ['app/models/event.rb']
182
+ puts out = @repo.git.ls_tree({}, 'master', ['app/models/event.rb'])
183
+ puts out = @repo.tree('master', paths).contents
184
+ assert_equal out, '100644 blob 6afcf64c80da8253fa47228eb09bc0eea217e5d1 lib/grit.rb'
185
+ end
186
+ =end
187
+
188
+ 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
data/test/test_tag.rb ADDED
@@ -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