relevance-grit 0.8.1

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 (58) 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 +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 +124 -0
  13. data/lib/grit/index.rb +77 -0
  14. data/lib/grit/lazy.rb +31 -0
  15. data/lib/grit/ref.rb +110 -0
  16. data/lib/grit/repo.rb +318 -0
  17. data/lib/grit/tree.rb +99 -0
  18. data/lib/grit.rb +42 -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_remotes +0 -0
  31. data/test/fixtures/for_each_ref_tags +0 -0
  32. data/test/fixtures/ls_tree_a +7 -0
  33. data/test/fixtures/ls_tree_b +2 -0
  34. data/test/fixtures/ls_tree_commit +3 -0
  35. data/test/fixtures/rev_list +26 -0
  36. data/test/fixtures/rev_list_count +655 -0
  37. data/test/fixtures/rev_list_single +7 -0
  38. data/test/fixtures/rev_parse +1 -0
  39. data/test/fixtures/show_empty_commit +6 -0
  40. data/test/fixtures/simple_config +2 -0
  41. data/test/helper.rb +17 -0
  42. data/test/profile.rb +21 -0
  43. data/test/suite.rb +6 -0
  44. data/test/test_actor.rb +35 -0
  45. data/test/test_blob.rb +74 -0
  46. data/test/test_commit.rb +182 -0
  47. data/test/test_config.rb +58 -0
  48. data/test/test_diff.rb +18 -0
  49. data/test/test_git.rb +52 -0
  50. data/test/test_grit.rb +32 -0
  51. data/test/test_head.rb +22 -0
  52. data/test/test_real.rb +19 -0
  53. data/test/test_reality.rb +17 -0
  54. data/test/test_remote.rb +15 -0
  55. data/test/test_repo.rb +278 -0
  56. data/test/test_tag.rb +29 -0
  57. data/test/test_tree.rb +91 -0
  58. metadata +133 -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,133 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: relevance-grit
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.8.1
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/index.rb
49
+ - lib/grit/lazy.rb
50
+ - lib/grit/ref.rb
51
+ - lib/grit/repo.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_remotes
65
+ - test/fixtures/for_each_ref_tags
66
+ - test/fixtures/ls_tree_a
67
+ - test/fixtures/ls_tree_b
68
+ - test/fixtures/ls_tree_commit
69
+ - test/fixtures/rev_list
70
+ - test/fixtures/rev_list_count
71
+ - test/fixtures/rev_list_single
72
+ - test/fixtures/rev_parse
73
+ - test/fixtures/show_empty_commit
74
+ - test/fixtures/simple_config
75
+ - test/helper.rb
76
+ - test/profile.rb
77
+ - test/suite.rb
78
+ - test/test_actor.rb
79
+ - test/test_blob.rb
80
+ - test/test_commit.rb
81
+ - test/test_config.rb
82
+ - test/test_diff.rb
83
+ - test/test_git.rb
84
+ - test/test_grit.rb
85
+ - test/test_head.rb
86
+ - test/test_reality.rb
87
+ - test/test_remote.rb
88
+ - test/test_repo.rb
89
+ - test/test_tag.rb
90
+ - test/test_tree.rb
91
+ - test/test_real.rb
92
+ has_rdoc: true
93
+ homepage: http://github.com/mojombo/grit
94
+ post_install_message:
95
+ rdoc_options:
96
+ - --main
97
+ - README.txt
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: "0"
105
+ version:
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: "0"
111
+ version:
112
+ requirements: []
113
+
114
+ rubyforge_project:
115
+ rubygems_version: 1.2.0
116
+ signing_key:
117
+ specification_version: 2
118
+ summary: Object model interface to a git repo
119
+ test_files:
120
+ - test/test_actor.rb
121
+ - test/test_blob.rb
122
+ - test/test_commit.rb
123
+ - test/test_config.rb
124
+ - test/test_diff.rb
125
+ - test/test_git.rb
126
+ - test/test_grit.rb
127
+ - test/test_head.rb
128
+ - test/test_real.rb
129
+ - test/test_reality.rb
130
+ - test/test_remote.rb
131
+ - test/test_repo.rb
132
+ - test/test_tag.rb
133
+ - test/test_tree.rb