mojombo-grit 0.8.0

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