mojombo-grit 0.9.4 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. data/API.txt +101 -0
  2. data/History.txt +38 -2
  3. data/README.md +210 -0
  4. data/VERSION.yml +4 -0
  5. data/lib/grit.rb +13 -4
  6. data/lib/grit/blame.rb +61 -0
  7. data/lib/grit/blob.rb +11 -2
  8. data/lib/grit/commit.rb +44 -31
  9. data/lib/grit/commit_stats.rb +26 -2
  10. data/lib/grit/diff.rb +6 -6
  11. data/lib/grit/git-ruby.rb +4 -2
  12. data/lib/grit/git-ruby/file_index.rb +10 -3
  13. data/lib/grit/git-ruby/git_object.rb +9 -3
  14. data/lib/grit/git-ruby/internal/{mmap.rb → file_window.rb} +2 -2
  15. data/lib/grit/git-ruby/internal/loose.rb +6 -6
  16. data/lib/grit/git-ruby/internal/pack.rb +19 -19
  17. data/lib/grit/git-ruby/object.rb +8 -2
  18. data/lib/grit/git-ruby/repository.rb +11 -6
  19. data/lib/grit/git.rb +23 -10
  20. data/lib/grit/index.rb +12 -11
  21. data/lib/grit/merge.rb +45 -0
  22. data/lib/grit/ref.rb +20 -16
  23. data/lib/grit/repo.rb +59 -9
  24. data/lib/grit/ruby1.9.rb +7 -0
  25. data/lib/grit/submodule.rb +5 -1
  26. data/lib/grit/tag.rb +61 -66
  27. data/lib/grit/tree.rb +20 -1
  28. metadata +29 -47
  29. data/Manifest.txt +0 -71
  30. data/README.txt +0 -213
  31. data/Rakefile +0 -29
  32. data/grit.gemspec +0 -62
  33. data/lib/grit/head.rb +0 -83
  34. data/test/test_actor.rb +0 -35
  35. data/test/test_blob.rb +0 -79
  36. data/test/test_commit.rb +0 -190
  37. data/test/test_config.rb +0 -58
  38. data/test/test_diff.rb +0 -18
  39. data/test/test_git.rb +0 -64
  40. data/test/test_grit.rb +0 -32
  41. data/test/test_head.rb +0 -47
  42. data/test/test_real.rb +0 -19
  43. data/test/test_reality.rb +0 -17
  44. data/test/test_remote.rb +0 -14
  45. data/test/test_repo.rb +0 -277
  46. data/test/test_tag.rb +0 -25
  47. data/test/test_tree.rb +0 -96
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -1,277 +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_heads_should_return_array_of_head_objects
39
- @r.heads.each do |head|
40
- assert_equal Grit::Head, head.class
41
- end
42
- end
43
-
44
- def test_heads_should_populate_head_data
45
- @r = Repo.new(File.join(File.dirname(__FILE__), *%w[dot_git]), :is_bare => true)
46
- head = @r.heads.first
47
-
48
- assert_equal 'test/master', head.name
49
- assert_equal '2d3acf90f35989df8f262dc50beadc4ee3ae1560', head.commit.id
50
- end
51
-
52
- # branches
53
-
54
- def test_branches
55
- # same as heads
56
- end
57
-
58
- # commits
59
-
60
- def test_commits
61
- Git.any_instance.expects(:rev_list).returns(fixture('rev_list'))
62
-
63
- commits = @r.commits('master', 10)
64
-
65
- c = commits[0]
66
- assert_equal '4c8124ffcf4039d292442eeccabdeca5af5c5017', c.id
67
- assert_equal ["634396b2f541a9f2d58b00be1a07f0c358b999b3"], c.parents.map { |p| p.id }
68
- assert_equal "672eca9b7f9e09c22dcb128c283e8c3c8d7697a4", c.tree.id
69
- assert_equal "Tom Preston-Werner", c.author.name
70
- assert_equal "tom@mojombo.com", c.author.email
71
- assert_equal Time.at(1191999972), c.authored_date
72
- assert_equal "Tom Preston-Werner", c.committer.name
73
- assert_equal "tom@mojombo.com", c.committer.email
74
- assert_equal Time.at(1191999972), c.committed_date
75
- assert_equal "implement Grit#heads", c.message
76
-
77
- c = commits[1]
78
- assert_equal [], c.parents
79
-
80
- c = commits[2]
81
- assert_equal ["6e64c55896aabb9a7d8e9f8f296f426d21a78c2c", "7f874954efb9ba35210445be456c74e037ba6af2"], c.parents.map { |p| p.id }
82
- assert_equal "Merge branch 'site'\n\n * Some other stuff\n * just one more", c.message
83
- assert_equal "Merge branch 'site'", c.short_message
84
- end
85
-
86
- # commit_count
87
-
88
- def test_commit_count
89
- Git.any_instance.expects(:rev_list).with({}, 'master').returns(fixture('rev_list_count'))
90
-
91
- assert_equal 655, @r.commit_count('master')
92
- end
93
-
94
- # commit
95
-
96
- def test_commit
97
- commit = @r.commit('634396b2f541a9f2d58b00be1a07f0c358b999b3')
98
-
99
- assert_equal "634396b2f541a9f2d58b00be1a07f0c358b999b3", commit.id
100
- end
101
-
102
- # tree
103
-
104
- def test_tree
105
- Git.any_instance.expects(:ls_tree).returns(fixture('ls_tree_a'))
106
- tree = @r.tree('master')
107
-
108
- assert_equal 4, tree.contents.select { |c| c.instance_of?(Blob) }.size
109
- assert_equal 3, tree.contents.select { |c| c.instance_of?(Tree) }.size
110
- end
111
-
112
- # blob
113
-
114
- def test_blob
115
- Git.any_instance.expects(:cat_file).returns(fixture('cat_file_blob'))
116
- blob = @r.blob("abc")
117
- assert_equal "Hello world", blob.data
118
- end
119
-
120
- # init_bare
121
-
122
- def test_init_bare
123
- Git.any_instance.expects(:init).returns(true)
124
- Repo.expects(:new).with("/foo/bar.git", {})
125
- Repo.init_bare("/foo/bar.git")
126
- end
127
-
128
- def test_init_bare_with_options
129
- Git.any_instance.expects(:init).with(
130
- :template => "/baz/sweet").returns(true)
131
- Repo.expects(:new).with("/foo/bar.git", {})
132
- Repo.init_bare("/foo/bar.git", :template => "/baz/sweet")
133
- end
134
-
135
- # fork_bare
136
-
137
- def test_fork_bare
138
- Git.any_instance.expects(:clone).with(
139
- {:bare => true, :shared => true},
140
- "#{absolute_project_path}/.git",
141
- "/foo/bar.git").returns(nil)
142
- Repo.expects(:new)
143
-
144
- @r.fork_bare("/foo/bar.git")
145
- end
146
-
147
- def test_fork_bare_with_options
148
- Git.any_instance.expects(:clone).with(
149
- {:bare => true, :shared => true, :template => '/awesome'},
150
- "#{absolute_project_path}/.git",
151
- "/foo/bar.git").returns(nil)
152
- Repo.expects(:new)
153
-
154
- @r.fork_bare("/foo/bar.git", :template => '/awesome')
155
- end
156
-
157
- # diff
158
-
159
- def test_diff
160
- Git.any_instance.expects(:diff).with({}, 'master^', 'master', '--')
161
- @r.diff('master^', 'master')
162
-
163
- Git.any_instance.expects(:diff).with({}, 'master^', 'master', '--', 'foo/bar')
164
- @r.diff('master^', 'master', 'foo/bar')
165
-
166
- Git.any_instance.expects(:diff).with({}, 'master^', 'master', '--', 'foo/bar', 'foo/baz')
167
- @r.diff('master^', 'master', 'foo/bar', 'foo/baz')
168
- end
169
-
170
- # commit_diff
171
-
172
- def test_diff
173
- Git.any_instance.expects(:diff).returns(fixture('diff_p'))
174
- diffs = @r.commit_diff('master')
175
-
176
- assert_equal 15, diffs.size
177
- end
178
-
179
- # init bare
180
-
181
- # archive
182
-
183
- def test_archive_tar
184
- #@r.archive_tar -- no assertion being done here
185
- end
186
-
187
- # archive_tar_gz
188
-
189
- def test_archive_tar_gz
190
- #@r.archive_tar_gz -- again, no assertion
191
- end
192
-
193
- # enable_daemon_serve
194
-
195
- def test_enable_daemon_serve
196
- FileUtils.expects(:touch).with(File.join(@r.path, 'git-daemon-export-ok'))
197
- @r.enable_daemon_serve
198
- end
199
-
200
- # disable_daemon_serve
201
-
202
- def test_disable_daemon_serve
203
- FileUtils.expects(:rm_f).with(File.join(@r.path, 'git-daemon-export-ok'))
204
- @r.disable_daemon_serve
205
- end
206
-
207
- # alternates
208
-
209
- def test_alternates_with_two_alternates
210
- File.expects(:exist?).with("#{absolute_project_path}/.git/objects/info/alternates").returns(true)
211
- File.expects(:read).returns("/path/to/repo1/.git/objects\n/path/to/repo2.git/objects\n")
212
-
213
- assert_equal ["/path/to/repo1/.git/objects", "/path/to/repo2.git/objects"], @r.alternates
214
- end
215
-
216
- def test_alternates_no_file
217
- File.expects(:exist?).returns(false)
218
-
219
- assert_equal [], @r.alternates
220
- end
221
-
222
- # alternates=
223
-
224
- def test_alternates_setter_ok
225
- alts = %w{/path/to/repo.git/objects /path/to/repo2.git/objects}
226
-
227
- alts.each do |alt|
228
- File.expects(:exist?).with(alt).returns(true)
229
- end
230
-
231
- File.any_instance.expects(:write).with(alts.join("\n"))
232
-
233
- assert_nothing_raised do
234
- @r.alternates = alts
235
- end
236
- end
237
-
238
- def test_alternates_setter_bad
239
- alts = %w{/path/to/repo.git/objects}
240
-
241
- alts.each do |alt|
242
- File.expects(:exist?).with(alt).returns(false)
243
- end
244
-
245
- File.any_instance.expects(:write).never
246
-
247
- assert_raise RuntimeError do
248
- @r.alternates = alts
249
- end
250
- end
251
-
252
- def test_alternates_setter_empty
253
- File.expects(:delete)
254
-
255
- @r.alternates = []
256
- end
257
-
258
- # inspect
259
-
260
- def test_inspect
261
- assert_equal %Q{#<Grit::Repo "#{File.expand_path(GRIT_REPO)}/.git">}, @r.inspect
262
- end
263
-
264
- # log
265
-
266
- def test_log
267
- Git.any_instance.expects(:log).times(2).with({:pretty => 'raw'}, 'master').returns(fixture('rev_list'))
268
-
269
- assert_equal '4c8124ffcf4039d292442eeccabdeca5af5c5017', @r.log.first.id
270
- assert_equal 'ab25fd8483882c3bda8a458ad2965d2248654335', @r.log.last.id
271
- end
272
-
273
- def test_log_with_path_and_options
274
- Git.any_instance.expects(:log).with({:pretty => 'raw', :max_count => 1}, 'master', '--', 'file.rb').returns(fixture('rev_list'))
275
- @r.log('master', 'file.rb', :max_count => 1)
276
- end
277
- end