schacon-grit 0.9.4 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/test/test_config.rb DELETED
@@ -1,58 +0,0 @@
1
- require File.dirname(__FILE__) + '/helper'
2
-
3
- class TestConfig < Test::Unit::TestCase
4
- def setup
5
- @r = Repo.new(GRIT_REPO)
6
- end
7
-
8
- # data
9
-
10
- def test_bracketed_fetch
11
- Git.any_instance.expects(:config).returns(fixture('simple_config'))
12
-
13
- config = @r.config
14
-
15
- assert_equal "git://github.com/mojombo/grit.git", config["remote.origin.url"]
16
- end
17
-
18
- def test_bracketed_fetch_returns_nil
19
- Git.any_instance.expects(:config).returns(fixture('simple_config'))
20
-
21
- config = @r.config
22
-
23
- assert_equal nil, config["unknown"]
24
- end
25
-
26
- def test_fetch
27
- Git.any_instance.expects(:config).returns(fixture('simple_config'))
28
-
29
- config = @r.config
30
-
31
- assert_equal "false", config.fetch("core.bare")
32
- end
33
-
34
- def test_fetch_with_default
35
- Git.any_instance.expects(:config).returns(fixture('simple_config'))
36
-
37
- config = @r.config
38
-
39
- assert_equal "default", config.fetch("unknown", "default")
40
- end
41
-
42
- def test_fetch_without_default_raises
43
- Git.any_instance.expects(:config).returns(fixture('simple_config'))
44
-
45
- config = @r.config
46
-
47
- assert_raise(IndexError) do
48
- config.fetch("unknown")
49
- end
50
- end
51
-
52
- def test_set_value
53
- Git.any_instance.expects(:config).with({}, 'unknown', 'default')
54
-
55
- config = @r.config
56
- config["unknown"] = "default"
57
- end
58
- end
data/test/test_diff.rb DELETED
@@ -1,18 +0,0 @@
1
- require File.dirname(__FILE__) + '/helper'
2
-
3
- class TestDiff < Test::Unit::TestCase
4
- def setup
5
- @r = Repo.new(GRIT_REPO)
6
- end
7
-
8
- # list_from_string
9
-
10
- def test_list_from_string_new_mode
11
- output = fixture('diff_new_mode')
12
-
13
- diffs = Grit::Diff.list_from_string(@r, output)
14
- assert_equal 2, diffs.size
15
- assert_equal 10, diffs.first.diff.split("\n").size
16
- assert_equal nil, diffs.last.diff
17
- end
18
- end
data/test/test_git.rb DELETED
@@ -1,64 +0,0 @@
1
- require File.dirname(__FILE__) + '/helper'
2
-
3
- class TestGit < Test::Unit::TestCase
4
- def setup
5
- @git = Git.new(File.join(File.dirname(__FILE__), *%w[..]))
6
- end
7
-
8
- def teardown
9
- Grit.debug = false
10
- end
11
-
12
- def test_method_missing
13
- assert_match(/^git version [\w\.]*$/, @git.version)
14
- end
15
-
16
- def test_logs_stderr
17
- Grit.debug = true
18
- Grit.stubs(:log)
19
- Grit.expects(:log).with(includes("git: 'bad' is not a git-command"))
20
- @git.bad
21
- end
22
-
23
- def testl_logs_stderr_when_skipping_timeout
24
- Grit.debug = true
25
- Grit.stubs(:log)
26
- Grit.expects(:log).with(includes("git: 'bad' is not a git-command"))
27
- @git.bad :timeout => false
28
- end
29
-
30
- def test_transform_options
31
- assert_equal ["-s"], @git.transform_options({:s => true})
32
- assert_equal ["-s '5'"], @git.transform_options({:s => 5})
33
-
34
- assert_equal ["--max-count"], @git.transform_options({:max_count => true})
35
- assert_equal ["--max-count='5'"], @git.transform_options({:max_count => 5})
36
-
37
- assert_equal ["-s", "-t"], @git.transform_options({:s => true, :t => true}).sort
38
- end
39
-
40
- def test_uses_custom_sh_method
41
- @git.expects(:sh)
42
- @git.something
43
- end
44
-
45
- def test_can_skip_timeout
46
- @git.expects(:wild_sh)
47
- @git.something(:timeout => false)
48
- end
49
-
50
- def test_raises_if_too_many_bytes
51
- @git.instance_variable_set(:@bytes_read, 6000000)
52
- assert_raises Grit::Git::GitTimeout do
53
- @git.version
54
- end
55
- end
56
-
57
- def test_raises_on_slow_shell
58
- Grit::Git.git_timeout = 0.001
59
- assert_raises Grit::Git::GitTimeout do
60
- @git.version
61
- end
62
- Grit::Git.git_timeout = 5.0
63
- end
64
- end
data/test/test_grit.rb DELETED
@@ -1,32 +0,0 @@
1
- require File.dirname(__FILE__) + '/helper'
2
-
3
- class TestGrit < Test::Unit::TestCase
4
- def setup
5
- @old_debug = Grit.debug
6
- @old_logger = Grit.logger
7
- Grit.debug = true
8
- end
9
-
10
- def teardown
11
- Grit.debug = @old_debug
12
- Grit.logger = @old_logger
13
- end
14
-
15
- def test_uses_stdout_logger_by_default
16
- assert_equal STDOUT, Grit.logger.instance_variable_get(:@logdev).dev
17
- end
18
-
19
- def test_can_override_logger
20
- my_logger = Logger.new(io = StringIO.new)
21
- Grit.logger = my_logger
22
- assert_equal my_logger, Grit.logger
23
- end
24
-
25
- def test_logs_to_specified_logger
26
- Grit.logger = Logger.new(io = StringIO.new)
27
- Grit.log 'hi mom'
28
- io.rewind
29
- assert io.read.include?('hi mom')
30
- end
31
-
32
- end
data/test/test_head.rb DELETED
@@ -1,47 +0,0 @@
1
- require File.dirname(__FILE__) + '/helper'
2
-
3
- class TestHead < 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
- # inspect
9
-
10
- def test_inspect
11
- head = @r.heads.first
12
- assert_equal %Q{#<Grit::Head "test/master">}, head.inspect
13
- end
14
-
15
- def test_master
16
- head = @r.commit('master')
17
- assert_equal 'ca8a30f5a7f0f163bbe3b6f0abf18a6c83b0687a', head.id
18
- end
19
-
20
- def test_submaster
21
- head = @r.commit('test/master')
22
- assert_equal '2d3acf90f35989df8f262dc50beadc4ee3ae1560', head.id
23
- end
24
-
25
- # heads with slashes
26
-
27
- def test_heads_with_slashes
28
- head = @r.heads[2]
29
- assert_equal %Q{#<Grit::Head "test/chacon">}, head.inspect
30
- end
31
-
32
- def test_is_head
33
- assert @r.is_head?('master')
34
- assert @r.is_head?('test/chacon')
35
- assert !@r.is_head?('masterblah')
36
- end
37
-
38
- def test_head_count
39
- assert_equal 5, @r.heads.size
40
- end
41
-
42
-
43
- def test_nonpack
44
- assert @r.heads.map { |h| h.name }.include?('nonpack')
45
- end
46
-
47
- end
data/test/test_real.rb DELETED
@@ -1,19 +0,0 @@
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
data/test/test_reality.rb DELETED
@@ -1,17 +0,0 @@
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
data/test/test_remote.rb DELETED
@@ -1,14 +0,0 @@
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 DELETED
@@ -1,285 +0,0 @@
1
- require File.dirname(__FILE__) + '/helper'
2
-
3
- class TestRepo < Test::Unit::TestCase
4
- def setup
5
- @r = Repo.new(GRIT_REPO)
6
- end
7
-
8
- # new
9
-
10
- def test_new_should_raise_on_invalid_repo_location
11
- assert_raise(InvalidGitRepositoryError) do
12
- Repo.new("/tmp")
13
- end
14
- end
15
-
16
- def test_new_should_raise_on_non_existant_path
17
- assert_raise(NoSuchPathError) do
18
- Repo.new("/foobar")
19
- end
20
- end
21
-
22
- # descriptions
23
-
24
- def test_description
25
- assert_equal "Unnamed repository; edit this file to name it for gitweb.", @r.description
26
- end
27
-
28
- # refs
29
-
30
- def test_refs_should_return_array_of_ref_objects
31
- @r.refs.each do |ref|
32
- assert ref.is_a? Grit::Ref
33
- end
34
- end
35
-
36
- # heads
37
-
38
- def test_current_head
39
- @r = Repo.new(File.join(File.dirname(__FILE__), *%w[dot_git]), :is_bare => true)
40
- head = @r.head
41
- assert_equal Grit::Head, head.class
42
- assert_equal 'master', head.name
43
- assert_equal 'ca8a30f5a7f0f163bbe3b6f0abf18a6c83b0687a', @r.commits(head.name).first.id
44
- end
45
-
46
- def test_heads_should_return_array_of_head_objects
47
- @r.heads.each do |head|
48
- assert_equal Grit::Head, head.class
49
- end
50
- end
51
-
52
- def test_heads_should_populate_head_data
53
- @r = Repo.new(File.join(File.dirname(__FILE__), *%w[dot_git]), :is_bare => true)
54
- head = @r.heads.first
55
-
56
- assert_equal 'test/master', head.name
57
- assert_equal '2d3acf90f35989df8f262dc50beadc4ee3ae1560', head.commit.id
58
- end
59
-
60
- # branches
61
-
62
- def test_branches
63
- # same as heads
64
- end
65
-
66
- # commits
67
-
68
- def test_commits
69
- Git.any_instance.expects(:rev_list).returns(fixture('rev_list'))
70
-
71
- commits = @r.commits('master', 10)
72
-
73
- c = commits[0]
74
- assert_equal '4c8124ffcf4039d292442eeccabdeca5af5c5017', c.id
75
- assert_equal ["634396b2f541a9f2d58b00be1a07f0c358b999b3"], c.parents.map { |p| p.id }
76
- assert_equal "672eca9b7f9e09c22dcb128c283e8c3c8d7697a4", c.tree.id
77
- assert_equal "Tom Preston-Werner", c.author.name
78
- assert_equal "tom@mojombo.com", c.author.email
79
- assert_equal Time.at(1191999972), c.authored_date
80
- assert_equal "Tom Preston-Werner", c.committer.name
81
- assert_equal "tom@mojombo.com", c.committer.email
82
- assert_equal Time.at(1191999972), c.committed_date
83
- assert_equal "implement Grit#heads", c.message
84
-
85
- c = commits[1]
86
- assert_equal [], c.parents
87
-
88
- c = commits[2]
89
- assert_equal ["6e64c55896aabb9a7d8e9f8f296f426d21a78c2c", "7f874954efb9ba35210445be456c74e037ba6af2"], c.parents.map { |p| p.id }
90
- assert_equal "Merge branch 'site'\n\n * Some other stuff\n * just one more", c.message
91
- assert_equal "Merge branch 'site'", c.short_message
92
- end
93
-
94
- # commit_count
95
-
96
- def test_commit_count
97
- Git.any_instance.expects(:rev_list).with({}, 'master').returns(fixture('rev_list_count'))
98
-
99
- assert_equal 655, @r.commit_count('master')
100
- end
101
-
102
- # commit
103
-
104
- def test_commit
105
- commit = @r.commit('634396b2f541a9f2d58b00be1a07f0c358b999b3')
106
-
107
- assert_equal "634396b2f541a9f2d58b00be1a07f0c358b999b3", commit.id
108
- end
109
-
110
- # tree
111
-
112
- def test_tree
113
- Git.any_instance.expects(:ls_tree).returns(fixture('ls_tree_a'))
114
- tree = @r.tree('master')
115
-
116
- assert_equal 4, tree.contents.select { |c| c.instance_of?(Blob) }.size
117
- assert_equal 3, tree.contents.select { |c| c.instance_of?(Tree) }.size
118
- end
119
-
120
- # blob
121
-
122
- def test_blob
123
- Git.any_instance.expects(:cat_file).returns(fixture('cat_file_blob'))
124
- blob = @r.blob("abc")
125
- assert_equal "Hello world", blob.data
126
- end
127
-
128
- # init_bare
129
-
130
- def test_init_bare
131
- Git.any_instance.expects(:init).returns(true)
132
- Repo.expects(:new).with("/foo/bar.git", {})
133
- Repo.init_bare("/foo/bar.git")
134
- end
135
-
136
- def test_init_bare_with_options
137
- Git.any_instance.expects(:init).with(
138
- :template => "/baz/sweet").returns(true)
139
- Repo.expects(:new).with("/foo/bar.git", {})
140
- Repo.init_bare("/foo/bar.git", :template => "/baz/sweet")
141
- end
142
-
143
- # fork_bare
144
-
145
- def test_fork_bare
146
- Git.any_instance.expects(:clone).with(
147
- {:bare => true, :shared => true},
148
- "#{absolute_project_path}/.git",
149
- "/foo/bar.git").returns(nil)
150
- Repo.expects(:new)
151
-
152
- @r.fork_bare("/foo/bar.git")
153
- end
154
-
155
- def test_fork_bare_with_options
156
- Git.any_instance.expects(:clone).with(
157
- {:bare => true, :shared => true, :template => '/awesome'},
158
- "#{absolute_project_path}/.git",
159
- "/foo/bar.git").returns(nil)
160
- Repo.expects(:new)
161
-
162
- @r.fork_bare("/foo/bar.git", :template => '/awesome')
163
- end
164
-
165
- # diff
166
-
167
- def test_diff
168
- Git.any_instance.expects(:diff).with({}, 'master^', 'master', '--')
169
- @r.diff('master^', 'master')
170
-
171
- Git.any_instance.expects(:diff).with({}, 'master^', 'master', '--', 'foo/bar')
172
- @r.diff('master^', 'master', 'foo/bar')
173
-
174
- Git.any_instance.expects(:diff).with({}, 'master^', 'master', '--', 'foo/bar', 'foo/baz')
175
- @r.diff('master^', 'master', 'foo/bar', 'foo/baz')
176
- end
177
-
178
- # commit_diff
179
-
180
- def test_diff
181
- Git.any_instance.expects(:diff).returns(fixture('diff_p'))
182
- diffs = @r.commit_diff('master')
183
-
184
- assert_equal 15, diffs.size
185
- end
186
-
187
- # init bare
188
-
189
- # archive
190
-
191
- def test_archive_tar
192
- #@r.archive_tar -- no assertion being done here
193
- end
194
-
195
- # archive_tar_gz
196
-
197
- def test_archive_tar_gz
198
- #@r.archive_tar_gz -- again, no assertion
199
- end
200
-
201
- # enable_daemon_serve
202
-
203
- def test_enable_daemon_serve
204
- FileUtils.expects(:touch).with(File.join(@r.path, 'git-daemon-export-ok'))
205
- @r.enable_daemon_serve
206
- end
207
-
208
- # disable_daemon_serve
209
-
210
- def test_disable_daemon_serve
211
- FileUtils.expects(:rm_f).with(File.join(@r.path, 'git-daemon-export-ok'))
212
- @r.disable_daemon_serve
213
- end
214
-
215
- # alternates
216
-
217
- def test_alternates_with_two_alternates
218
- File.expects(:exist?).with("#{absolute_project_path}/.git/objects/info/alternates").returns(true)
219
- File.expects(:read).returns("/path/to/repo1/.git/objects\n/path/to/repo2.git/objects\n")
220
-
221
- assert_equal ["/path/to/repo1/.git/objects", "/path/to/repo2.git/objects"], @r.alternates
222
- end
223
-
224
- def test_alternates_no_file
225
- File.expects(:exist?).returns(false)
226
-
227
- assert_equal [], @r.alternates
228
- end
229
-
230
- # alternates=
231
-
232
- def test_alternates_setter_ok
233
- alts = %w{/path/to/repo.git/objects /path/to/repo2.git/objects}
234
-
235
- alts.each do |alt|
236
- File.expects(:exist?).with(alt).returns(true)
237
- end
238
-
239
- File.any_instance.expects(:write).with(alts.join("\n"))
240
-
241
- assert_nothing_raised do
242
- @r.alternates = alts
243
- end
244
- end
245
-
246
- def test_alternates_setter_bad
247
- alts = %w{/path/to/repo.git/objects}
248
-
249
- alts.each do |alt|
250
- File.expects(:exist?).with(alt).returns(false)
251
- end
252
-
253
- File.any_instance.expects(:write).never
254
-
255
- assert_raise RuntimeError do
256
- @r.alternates = alts
257
- end
258
- end
259
-
260
- def test_alternates_setter_empty
261
- File.expects(:delete)
262
-
263
- @r.alternates = []
264
- end
265
-
266
- # inspect
267
-
268
- def test_inspect
269
- assert_equal %Q{#<Grit::Repo "#{File.expand_path(GRIT_REPO)}/.git">}, @r.inspect
270
- end
271
-
272
- # log
273
-
274
- def test_log
275
- Git.any_instance.expects(:log).times(2).with({:pretty => 'raw'}, 'master').returns(fixture('rev_list'))
276
-
277
- assert_equal '4c8124ffcf4039d292442eeccabdeca5af5c5017', @r.log.first.id
278
- assert_equal 'ab25fd8483882c3bda8a458ad2965d2248654335', @r.log.last.id
279
- end
280
-
281
- def test_log_with_path_and_options
282
- Git.any_instance.expects(:log).with({:pretty => 'raw', :max_count => 1}, 'master', '--', 'file.rb').returns(fixture('rev_list'))
283
- @r.log('master', 'file.rb', :max_count => 1)
284
- end
285
- end