cho45-grit 0.8.2

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.
Files changed (56) hide show
  1. data/History.txt +6 -0
  2. data/Manifest.txt +56 -0
  3. data/README.txt +213 -0
  4. data/Rakefile +29 -0
  5. data/grit.gemspec +25 -0
  6. data/lib/grit/actor.rb +36 -0
  7. data/lib/grit/blob.rb +117 -0
  8. data/lib/grit/commit.rb +208 -0
  9. data/lib/grit/config.rb +44 -0
  10. data/lib/grit/diff.rb +70 -0
  11. data/lib/grit/errors.rb +7 -0
  12. data/lib/grit/git.rb +124 -0
  13. data/lib/grit/lazy.rb +31 -0
  14. data/lib/grit/ref.rb +110 -0
  15. data/lib/grit/repo.rb +318 -0
  16. data/lib/grit/tree.rb +99 -0
  17. data/lib/grit.rb +46 -0
  18. data/test/fixtures/blame +131 -0
  19. data/test/fixtures/cat_file_blob +1 -0
  20. data/test/fixtures/cat_file_blob_size +1 -0
  21. data/test/fixtures/diff_2 +54 -0
  22. data/test/fixtures/diff_2f +19 -0
  23. data/test/fixtures/diff_f +15 -0
  24. data/test/fixtures/diff_i +201 -0
  25. data/test/fixtures/diff_mode_only +1152 -0
  26. data/test/fixtures/diff_new_mode +17 -0
  27. data/test/fixtures/diff_p +610 -0
  28. data/test/fixtures/for_each_ref +0 -0
  29. data/test/fixtures/for_each_ref_remotes +0 -0
  30. data/test/fixtures/for_each_ref_tags +0 -0
  31. data/test/fixtures/ls_tree_a +7 -0
  32. data/test/fixtures/ls_tree_b +2 -0
  33. data/test/fixtures/ls_tree_commit +3 -0
  34. data/test/fixtures/rev_list +26 -0
  35. data/test/fixtures/rev_list_count +655 -0
  36. data/test/fixtures/rev_list_single +7 -0
  37. data/test/fixtures/rev_parse +1 -0
  38. data/test/fixtures/show_empty_commit +6 -0
  39. data/test/fixtures/simple_config +2 -0
  40. data/test/helper.rb +17 -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_blob.rb +74 -0
  45. data/test/test_commit.rb +182 -0
  46. data/test/test_config.rb +58 -0
  47. data/test/test_diff.rb +18 -0
  48. data/test/test_git.rb +52 -0
  49. data/test/test_head.rb +22 -0
  50. data/test/test_real.rb +19 -0
  51. data/test/test_reality.rb +17 -0
  52. data/test/test_remote.rb +15 -0
  53. data/test/test_repo.rb +278 -0
  54. data/test/test_tag.rb +29 -0
  55. data/test/test_tree.rb +91 -0
  56. metadata +139 -0
data/test/test_repo.rb ADDED
@@ -0,0 +1,278 @@
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
+ Git.any_instance.expects(:for_each_ref).returns(fixture('for_each_ref'))
46
+
47
+ head = @r.heads.first
48
+
49
+ assert_equal 'master', head.name
50
+ assert_equal '634396b2f541a9f2d58b00be1a07f0c358b999b3', head.commit.id
51
+ end
52
+
53
+ # branches
54
+
55
+ def test_branches
56
+ # same as heads
57
+ end
58
+
59
+ # commits
60
+
61
+ def test_commits
62
+ Git.any_instance.expects(:rev_list).returns(fixture('rev_list'))
63
+
64
+ commits = @r.commits('master', 10)
65
+
66
+ c = commits[0]
67
+ assert_equal '4c8124ffcf4039d292442eeccabdeca5af5c5017', c.id
68
+ assert_equal ["634396b2f541a9f2d58b00be1a07f0c358b999b3"], c.parents.map { |p| p.id }
69
+ assert_equal "672eca9b7f9e09c22dcb128c283e8c3c8d7697a4", c.tree.id
70
+ assert_equal "Tom Preston-Werner", c.author.name
71
+ assert_equal "tom@mojombo.com", c.author.email
72
+ assert_equal Time.at(1191999972), c.authored_date
73
+ assert_equal "Tom Preston-Werner", c.committer.name
74
+ assert_equal "tom@mojombo.com", c.committer.email
75
+ assert_equal Time.at(1191999972), c.committed_date
76
+ assert_equal "implement Grit#heads", c.message
77
+
78
+ c = commits[1]
79
+ assert_equal [], c.parents
80
+
81
+ c = commits[2]
82
+ assert_equal ["6e64c55896aabb9a7d8e9f8f296f426d21a78c2c", "7f874954efb9ba35210445be456c74e037ba6af2"], c.parents.map { |p| p.id }
83
+ assert_equal "Merge branch 'site'\n\n * Some other stuff\n * just one more", c.message
84
+ assert_equal "Merge branch 'site'", c.short_message
85
+ end
86
+
87
+ # commit_count
88
+
89
+ def test_commit_count
90
+ Git.any_instance.expects(:rev_list).with({}, 'master').returns(fixture('rev_list_count'))
91
+
92
+ assert_equal 655, @r.commit_count('master')
93
+ end
94
+
95
+ # commit
96
+
97
+ def test_commit
98
+ commit = @r.commit('634396b2f541a9f2d58b00be1a07f0c358b999b3')
99
+
100
+ assert_equal "634396b2f541a9f2d58b00be1a07f0c358b999b3", commit.id
101
+ end
102
+
103
+ # tree
104
+
105
+ def test_tree
106
+ Git.any_instance.expects(:ls_tree).returns(fixture('ls_tree_a'))
107
+ tree = @r.tree('master')
108
+
109
+ assert_equal 4, tree.contents.select { |c| c.instance_of?(Blob) }.size
110
+ assert_equal 3, tree.contents.select { |c| c.instance_of?(Tree) }.size
111
+ end
112
+
113
+ # blob
114
+
115
+ def test_blob
116
+ Git.any_instance.expects(:cat_file).returns(fixture('cat_file_blob'))
117
+ blob = @r.blob("abc")
118
+ assert_equal "Hello world", blob.data
119
+ end
120
+
121
+ # init_bare
122
+
123
+ def test_init_bare
124
+ Git.any_instance.expects(:init).returns(true)
125
+ Repo.expects(:new).with("/foo/bar.git")
126
+ Repo.init_bare("/foo/bar.git")
127
+ end
128
+
129
+ def test_init_bare_with_options
130
+ Git.any_instance.expects(:init).with(
131
+ :template => "/baz/sweet").returns(true)
132
+ Repo.expects(:new).with("/foo/bar.git")
133
+ Repo.init_bare("/foo/bar.git", :template => "/baz/sweet")
134
+ end
135
+
136
+ # fork_bare
137
+
138
+ def test_fork_bare
139
+ Git.any_instance.expects(:clone).with(
140
+ {:bare => true, :shared => true},
141
+ "#{absolute_project_path}/.git",
142
+ "/foo/bar.git").returns(nil)
143
+ Repo.expects(:new)
144
+
145
+ @r.fork_bare("/foo/bar.git")
146
+ end
147
+
148
+ def test_fork_bare_with_options
149
+ Git.any_instance.expects(:clone).with(
150
+ {:bare => true, :shared => true, :template => '/awesome'},
151
+ "#{absolute_project_path}/.git",
152
+ "/foo/bar.git").returns(nil)
153
+ Repo.expects(:new)
154
+
155
+ @r.fork_bare("/foo/bar.git", :template => '/awesome')
156
+ end
157
+
158
+ # diff
159
+
160
+ def test_diff
161
+ Git.any_instance.expects(:diff).with({}, 'master^', 'master', '--')
162
+ @r.diff('master^', 'master')
163
+
164
+ Git.any_instance.expects(:diff).with({}, 'master^', 'master', '--', 'foo/bar')
165
+ @r.diff('master^', 'master', 'foo/bar')
166
+
167
+ Git.any_instance.expects(:diff).with({}, 'master^', 'master', '--', 'foo/bar', 'foo/baz')
168
+ @r.diff('master^', 'master', 'foo/bar', 'foo/baz')
169
+ end
170
+
171
+ # commit_diff
172
+
173
+ def test_diff
174
+ Git.any_instance.expects(:diff).returns(fixture('diff_p'))
175
+ diffs = @r.commit_diff('master')
176
+
177
+ assert_equal 15, diffs.size
178
+ end
179
+
180
+ # init bare
181
+
182
+ # archive
183
+
184
+ def test_archive_tar
185
+ @r.archive_tar
186
+ end
187
+
188
+ # archive_tar_gz
189
+
190
+ def test_archive_tar_gz
191
+ @r.archive_tar_gz
192
+ end
193
+
194
+ # enable_daemon_serve
195
+
196
+ def test_enable_daemon_serve
197
+ FileUtils.expects(:touch).with(File.join(@r.path, 'git-daemon-export-ok'))
198
+ @r.enable_daemon_serve
199
+ end
200
+
201
+ # disable_daemon_serve
202
+
203
+ def test_disable_daemon_serve
204
+ FileUtils.expects(:rm_f).with(File.join(@r.path, 'git-daemon-export-ok'))
205
+ @r.disable_daemon_serve
206
+ end
207
+
208
+ # alternates
209
+
210
+ def test_alternates_with_two_alternates
211
+ File.expects(:exist?).with("#{absolute_project_path}/.git/objects/info/alternates").returns(true)
212
+ File.expects(:read).returns("/path/to/repo1/.git/objects\n/path/to/repo2.git/objects\n")
213
+
214
+ assert_equal ["/path/to/repo1/.git/objects", "/path/to/repo2.git/objects"], @r.alternates
215
+ end
216
+
217
+ def test_alternates_no_file
218
+ File.expects(:exist?).returns(false)
219
+
220
+ assert_equal [], @r.alternates
221
+ end
222
+
223
+ # alternates=
224
+
225
+ def test_alternates_setter_ok
226
+ alts = %w{/path/to/repo.git/objects /path/to/repo2.git/objects}
227
+
228
+ alts.each do |alt|
229
+ File.expects(:exist?).with(alt).returns(true)
230
+ end
231
+
232
+ File.any_instance.expects(:write).with(alts.join("\n"))
233
+
234
+ assert_nothing_raised do
235
+ @r.alternates = alts
236
+ end
237
+ end
238
+
239
+ def test_alternates_setter_bad
240
+ alts = %w{/path/to/repo.git/objects}
241
+
242
+ alts.each do |alt|
243
+ File.expects(:exist?).with(alt).returns(false)
244
+ end
245
+
246
+ File.any_instance.expects(:write).never
247
+
248
+ assert_raise RuntimeError do
249
+ @r.alternates = alts
250
+ end
251
+ end
252
+
253
+ def test_alternates_setter_empty
254
+ File.expects(:delete)
255
+
256
+ @r.alternates = []
257
+ end
258
+
259
+ # inspect
260
+
261
+ def test_inspect
262
+ assert_equal %Q{#<Grit::Repo "#{File.expand_path(GRIT_REPO)}/.git">}, @r.inspect
263
+ end
264
+
265
+ # log
266
+
267
+ def test_log
268
+ Git.any_instance.expects(:log).times(2).with({:pretty => 'raw'}, 'master').returns(fixture('rev_list'))
269
+
270
+ assert_equal '4c8124ffcf4039d292442eeccabdeca5af5c5017', @r.log.first.id
271
+ assert_equal 'ab25fd8483882c3bda8a458ad2965d2248654335', @r.log.last.id
272
+ end
273
+
274
+ def test_log_with_path_and_options
275
+ Git.any_instance.expects(:log).with({:pretty => 'raw', :max_count => 1}, 'master', '--', 'file.rb').returns(fixture('rev_list'))
276
+ @r.log('master', 'file.rb', :max_count => 1)
277
+ end
278
+ end
data/test/test_tag.rb ADDED
@@ -0,0 +1,29 @@
1
+ require File.dirname(__FILE__) + '/helper'
2
+
3
+ class TestTag < 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
11
+ Git.any_instance.expects(:for_each_ref).returns(fixture('for_each_ref_tags'))
12
+
13
+ tags = @r.tags
14
+
15
+ assert_equal 1, tags.size
16
+ assert_equal 'v0.7.1', tags.first.name
17
+ assert_equal '634396b2f541a9f2d58b00be1a07f0c358b999b3', tags.first.commit.id
18
+ end
19
+
20
+ # inspect
21
+
22
+ def test_inspect
23
+ Git.any_instance.expects(:for_each_ref).returns(fixture('for_each_ref'))
24
+
25
+ tag = @r.tags.first
26
+
27
+ assert_equal %Q{#<Grit::Tag "#{tag.name}">}, tag.inspect
28
+ end
29
+ end
data/test/test_tree.rb ADDED
@@ -0,0 +1,91 @@
1
+ require File.dirname(__FILE__) + '/helper'
2
+
3
+ class TestTree < Test::Unit::TestCase
4
+ def setup
5
+ @r = Repo.new(GRIT_REPO)
6
+ @t = Tree.allocate
7
+ end
8
+
9
+ # contents
10
+
11
+ def test_contents_should_cache
12
+ Git.any_instance.expects(:ls_tree).returns(
13
+ fixture('ls_tree_a'),
14
+ fixture('ls_tree_b')
15
+ ).times(2)
16
+ tree = @r.tree('master')
17
+
18
+ child = tree.contents.last
19
+
20
+ child.contents
21
+ child.contents
22
+ end
23
+
24
+ # content_from_string
25
+
26
+ def test_content_from_string_tree_should_return_tree
27
+ text = fixture('ls_tree_a').split("\n").last
28
+
29
+ tree = @t.content_from_string(nil, text)
30
+
31
+ assert_equal Tree, tree.class
32
+ assert_equal "650fa3f0c17f1edb4ae53d8dcca4ac59d86e6c44", tree.id
33
+ assert_equal "040000", tree.mode
34
+ assert_equal "test", tree.name
35
+ end
36
+
37
+ def test_content_from_string_tree_should_return_blob
38
+ text = fixture('ls_tree_b').split("\n").first
39
+
40
+ tree = @t.content_from_string(nil, text)
41
+
42
+ assert_equal Blob, tree.class
43
+ assert_equal "aa94e396335d2957ca92606f909e53e7beaf3fbb", tree.id
44
+ assert_equal "100644", tree.mode
45
+ assert_equal "grit.rb", tree.name
46
+ end
47
+
48
+ def test_content_from_string_tree_should_return_commit
49
+ text = fixture('ls_tree_commit').split("\n")[1]
50
+
51
+ tree = @t.content_from_string(nil, text)
52
+
53
+ assert_nil tree
54
+ end
55
+
56
+ def test_content_from_string_invalid_type_should_raise
57
+ assert_raise(RuntimeError) do
58
+ @t.content_from_string(nil, "040000 bogus 650fa3f0c17f1edb4ae53d8dcca4ac59d86e6c44 test")
59
+ end
60
+ end
61
+
62
+ # /
63
+
64
+ def test_slash
65
+ Git.any_instance.expects(:ls_tree).returns(
66
+ fixture('ls_tree_a')
67
+ )
68
+ tree = @r.tree('master')
69
+
70
+ assert_equal 'aa06ba24b4e3f463b3c4a85469d0fb9e5b421cf8', (tree/'lib').id
71
+ assert_equal '8b1e02c0fb554eed2ce2ef737a68bb369d7527df', (tree/'README.txt').id
72
+ end
73
+
74
+ def test_slash_with_commits
75
+ Git.any_instance.expects(:ls_tree).returns(
76
+ fixture('ls_tree_commit')
77
+ )
78
+ tree = @r.tree('master')
79
+
80
+ assert_nil tree/'bar'
81
+ assert_equal '2afb47bcedf21663580d5e6d2f406f08f3f65f19', (tree/'foo').id
82
+ assert_equal 'f623ee576a09ca491c4a27e48c0dfe04be5f4a2e', (tree/'baz').id
83
+ end
84
+
85
+ # inspect
86
+
87
+ def test_inspect
88
+ @t = Tree.create(@r, :id => 'abc')
89
+ assert_equal %Q{#<Grit::Tree "abc">}, @t.inspect
90
+ end
91
+ end
metadata ADDED
@@ -0,0 +1,139 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cho45-grit
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.8.2
5
+ platform: ruby
6
+ authors:
7
+ - Tom Preston-Werner
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-06-15 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: mime-types
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: "0"
23
+ version:
24
+ - !ruby/object:Gem::Dependency
25
+ name: hoe
26
+ version_requirement:
27
+ version_requirements: !ruby/object:Gem::Requirement
28
+ requirements:
29
+ - - ">="
30
+ - !ruby/object:Gem::Version
31
+ version: 1.5.3
32
+ version:
33
+ description: Grit is a Ruby library for extracting information from a git repository in and object oriented manner.
34
+ email: tom@rubyisawesome.com
35
+ executables: []
36
+
37
+ extensions: []
38
+
39
+ extra_rdoc_files:
40
+ - History.txt
41
+ - Manifest.txt
42
+ - README.txt
43
+ files:
44
+ - History.txt
45
+ - Manifest.txt
46
+ - README.txt
47
+ - Rakefile
48
+ - grit.gemspec
49
+ - lib/grit.rb
50
+ - lib/grit/actor.rb
51
+ - lib/grit/blob.rb
52
+ - lib/grit/commit.rb
53
+ - lib/grit/config.rb
54
+ - lib/grit/diff.rb
55
+ - lib/grit/errors.rb
56
+ - lib/grit/git.rb
57
+ - lib/grit/lazy.rb
58
+ - lib/grit/ref.rb
59
+ - lib/grit/repo.rb
60
+ - lib/grit/tree.rb
61
+ - test/fixtures/blame
62
+ - test/fixtures/cat_file_blob
63
+ - test/fixtures/cat_file_blob_size
64
+ - test/fixtures/diff_2
65
+ - test/fixtures/diff_2f
66
+ - test/fixtures/diff_f
67
+ - test/fixtures/diff_i
68
+ - test/fixtures/diff_mode_only
69
+ - test/fixtures/diff_new_mode
70
+ - test/fixtures/diff_p
71
+ - test/fixtures/for_each_ref
72
+ - test/fixtures/for_each_ref_remotes
73
+ - test/fixtures/for_each_ref_tags
74
+ - test/fixtures/ls_tree_a
75
+ - test/fixtures/ls_tree_b
76
+ - test/fixtures/ls_tree_commit
77
+ - test/fixtures/rev_list
78
+ - test/fixtures/rev_list_count
79
+ - test/fixtures/rev_list_single
80
+ - test/fixtures/rev_parse
81
+ - test/fixtures/show_empty_commit
82
+ - test/fixtures/simple_config
83
+ - test/helper.rb
84
+ - test/profile.rb
85
+ - test/suite.rb
86
+ - test/test_actor.rb
87
+ - test/test_blob.rb
88
+ - test/test_commit.rb
89
+ - test/test_config.rb
90
+ - test/test_diff.rb
91
+ - test/test_git.rb
92
+ - test/test_head.rb
93
+ - test/test_reality.rb
94
+ - test/test_repo.rb
95
+ - test/test_tag.rb
96
+ - test/test_tree.rb
97
+ - test/test_real.rb
98
+ - test/test_remote.rb
99
+ has_rdoc: true
100
+ homepage: http://github.com/mojombo/grit
101
+ post_install_message:
102
+ rdoc_options:
103
+ - --main
104
+ - README.txt
105
+ require_paths:
106
+ - lib
107
+ required_ruby_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: "0"
112
+ version:
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: "0"
118
+ version:
119
+ requirements: []
120
+
121
+ rubyforge_project: grit
122
+ rubygems_version: 1.2.0
123
+ signing_key:
124
+ specification_version: 2
125
+ summary: Object model interface to a git repo
126
+ test_files:
127
+ - test/test_actor.rb
128
+ - test/test_blob.rb
129
+ - test/test_commit.rb
130
+ - test/test_config.rb
131
+ - test/test_diff.rb
132
+ - test/test_git.rb
133
+ - test/test_head.rb
134
+ - test/test_real.rb
135
+ - test/test_reality.rb
136
+ - test/test_remote.rb
137
+ - test/test_repo.rb
138
+ - test/test_tag.rb
139
+ - test/test_tree.rb