grit 0.7.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of grit might be problematic. Click here for more details.

Binary file
@@ -0,0 +1,7 @@
1
+ 100644 blob 81d2c27608b352814cbe979a6acd678d30219678 History.txt
2
+ 100644 blob 641972d82c6d1b51122274ae8f6a0ecdfb56ee22 Manifest.txt
3
+ 100644 blob 8b1e02c0fb554eed2ce2ef737a68bb369d7527df README.txt
4
+ 100644 blob 735d7338b7cb208563aa282f0376c5c4049453a7 Rakefile
5
+ 040000 tree c3d07b0083f01a6e1ac969a0f32b8d06f20c62e5 bin
6
+ 040000 tree aa06ba24b4e3f463b3c4a85469d0fb9e5b421cf8 lib
7
+ 040000 tree 650fa3f0c17f1edb4ae53d8dcca4ac59d86e6c44 test
@@ -0,0 +1,2 @@
1
+ 100644 blob aa94e396335d2957ca92606f909e53e7beaf3fbb grit.rb
2
+ 040000 tree 34868e6e7384cb5ee51c543a8187fdff2675b5a7 grit
@@ -0,0 +1,24 @@
1
+ commit 4c8124ffcf4039d292442eeccabdeca5af5c5017
2
+ tree 672eca9b7f9e09c22dcb128c283e8c3c8d7697a4
3
+ parent 634396b2f541a9f2d58b00be1a07f0c358b999b3
4
+ author Tom Preston-Werner <tom@mojombo.com> 1191999972 -0700
5
+ committer Tom Preston-Werner <tom@mojombo.com> 1191999972 -0700
6
+
7
+ implement Grit#heads
8
+
9
+ commit 634396b2f541a9f2d58b00be1a07f0c358b999b3
10
+ tree b35b4bf642d667fdd613eebcfe4e17efd420fb8a
11
+ author Tom Preston-Werner <tom@mojombo.com> 1191997100 -0700
12
+ committer Tom Preston-Werner <tom@mojombo.com> 1191997100 -0700
13
+
14
+ initial grit setup
15
+
16
+ commit ab25fd8483882c3bda8a458ad2965d2248654335
17
+ tree c20b5ec543bde1e43a931449b196052c06ed8acc
18
+ parent 6e64c55896aabb9a7d8e9f8f296f426d21a78c2c
19
+ parent 7f874954efb9ba35210445be456c74e037ba6af2
20
+ author Tom Preston-Werner <tom@mojombo.com> 1182645538 -0700
21
+ committer Tom Preston-Werner <tom@mojombo.com> 1182645538 -0700
22
+
23
+ Merge branch 'site'
24
+ Some other stuff
@@ -0,0 +1,7 @@
1
+ commit 4c8124ffcf4039d292442eeccabdeca5af5c5017
2
+ tree 672eca9b7f9e09c22dcb128c283e8c3c8d7697a4
3
+ parent 634396b2f541a9f2d58b00be1a07f0c358b999b3
4
+ author Tom Preston-Werner <tom@mojombo.com> 1191999972 -0700
5
+ committer Tom Preston-Werner <tom@mojombo.com> 1191999972 -0700
6
+
7
+ implement Grit#heads
@@ -0,0 +1 @@
1
+ 80f136f
data/test/helper.rb ADDED
@@ -0,0 +1,13 @@
1
+ require File.join(File.dirname(__FILE__), *%w[.. lib grit])
2
+
3
+ require 'rubygems'
4
+ require 'test/unit'
5
+ require 'mocha'
6
+
7
+ GRIT_REPO = File.join(File.dirname(__FILE__), *%w[..])
8
+
9
+ include Grit
10
+
11
+ def fixture(name)
12
+ File.read(File.join(File.dirname(__FILE__), 'fixtures', name))
13
+ end
data/test/profile.rb ADDED
@@ -0,0 +1,21 @@
1
+ # require File.join(File.dirname(__FILE__), *%w[.. lib grit])
2
+ # include Grit
3
+ #
4
+ # def recurse(tree, indent = "")
5
+ # tree.contents.each do |c|
6
+ # case c
7
+ # when Tree
8
+ # # puts "#{indent}#{c.name} (#{c.id})"
9
+ # recurse(c, indent + " ")
10
+ # end
11
+ # end
12
+ # end
13
+ #
14
+ # 10.times do
15
+ # r = Repo.new("/Users/tom/dev/god")
16
+ # t = r.tree
17
+ #
18
+ # recurse(t)
19
+ # end
20
+
21
+ 500.times { puts `git --git-dir /Users/tom/dev/god/.git ls-tree master` }
data/test/suite.rb ADDED
@@ -0,0 +1,6 @@
1
+ require 'test/unit'
2
+
3
+ tests = Dir["#{File.dirname(__FILE__)}/test_*.rb"]
4
+ tests.each do |file|
5
+ require file
6
+ end
@@ -0,0 +1,35 @@
1
+ require File.dirname(__FILE__) + '/helper'
2
+
3
+ class TestActor < Test::Unit::TestCase
4
+ def setup
5
+
6
+ end
7
+
8
+ # from_string
9
+
10
+ def test_from_string_should_separate_name_and_email
11
+ a = Actor.from_string("Tom Werner <tom@example.com>")
12
+ assert_equal "Tom Werner", a.name
13
+ assert_equal "tom@example.com", a.email
14
+ end
15
+
16
+ def test_from_string_should_handle_just_name
17
+ a = Actor.from_string("Tom Werner")
18
+ assert_equal "Tom Werner", a.name
19
+ assert_equal nil, a.email
20
+ end
21
+
22
+ # inspect
23
+
24
+ def test_inspect
25
+ a = Actor.from_string("Tom Werner <tom@example.com>")
26
+ assert_equal %Q{#<Grit::Actor "Tom Werner <tom@example.com>">}, a.inspect
27
+ end
28
+
29
+ # to_s
30
+
31
+ def test_to_s_should_alias_name
32
+ a = Actor.from_string("Tom Werner <tom@example.com>")
33
+ assert_equal a.name, a.to_s
34
+ end
35
+ end
data/test/test_blob.rb ADDED
@@ -0,0 +1,74 @@
1
+ require File.dirname(__FILE__) + '/helper'
2
+
3
+ class TestBlob < Test::Unit::TestCase
4
+ def setup
5
+ @r = Repo.new(GRIT_REPO)
6
+ @b = Blob.allocate
7
+ end
8
+
9
+ # blob
10
+
11
+ def test_data_should_return_blob_contents
12
+ Git.any_instance.expects(:cat_file).returns(fixture('cat_file_blob'))
13
+ blob = Blob.create(@r, :id => 'abc')
14
+ assert_equal "Hello world", blob.data
15
+ end
16
+
17
+ def test_data_should_cache
18
+ Git.any_instance.expects(:cat_file).returns(fixture('cat_file_blob')).times(1)
19
+ blob = Blob.create(@r, :id => 'abc')
20
+ blob.data
21
+ blob.data
22
+ end
23
+
24
+ # size
25
+
26
+ def test_size_should_return_file_size
27
+ Git.any_instance.expects(:cat_file).returns(fixture('cat_file_blob_size'))
28
+ blob = Blob.create(@r, :id => 'abc')
29
+ assert_equal 11, blob.size
30
+ end
31
+
32
+ # data
33
+
34
+ # mime_type
35
+
36
+ def test_mime_type_should_return_mime_type_for_known_types
37
+ blob = Blob.create(@r, :id => 'abc', :name => 'foo.png')
38
+ assert_equal "image/png", blob.mime_type
39
+ end
40
+
41
+ def test_mime_type_should_return_text_plain_for_unknown_types
42
+ blob = Blob.create(@r, :id => 'abc')
43
+ assert_equal "text/plain", blob.mime_type
44
+ end
45
+
46
+ # blame
47
+
48
+ def test_blame
49
+ Git.any_instance.expects(:blame).returns(fixture('blame'))
50
+ b = Blob.blame(@r, 'master', 'lib/grit.rb')
51
+ assert_equal 13, b.size
52
+ assert_equal 25, b.inject(0) { |acc, x| acc + x.last.size }
53
+ assert_equal b[0].first.object_id, b[9].first.object_id
54
+ c = b.first.first
55
+ c.expects(:__bake__).times(0)
56
+ assert_equal '634396b2f541a9f2d58b00be1a07f0c358b999b3', c.id
57
+ assert_equal 'Tom Preston-Werner', c.author.name
58
+ assert_equal 'tom@mojombo.com', c.author.email
59
+ assert_equal Time.at(1191997100), c.authored_date
60
+ assert_equal 'Tom Preston-Werner', c.committer.name
61
+ assert_equal 'tom@mojombo.com', c.committer.email
62
+ assert_equal Time.at(1191997100), c.committed_date
63
+ assert_equal 'initial grit setup', c.message
64
+ # c.expects(:__bake__).times(1)
65
+ # assert_equal Tree, c.tree.class
66
+ end
67
+
68
+ # inspect
69
+
70
+ def test_inspect
71
+ @b = Blob.create(@r, :id => 'abc')
72
+ assert_equal %Q{#<Grit::Blob "abc">}, @b.inspect
73
+ end
74
+ end
@@ -0,0 +1,64 @@
1
+ require File.dirname(__FILE__) + '/helper'
2
+
3
+ class TestCommit < Test::Unit::TestCase
4
+ def setup
5
+ @r = Repo.new(GRIT_REPO)
6
+ end
7
+
8
+ # __bake__
9
+
10
+ def test_bake
11
+ Git.any_instance.expects(:rev_list).returns(fixture('rev_list_single'))
12
+ @c = Commit.create(@r, :id => '4c8124ffcf4039d292442eeccabdeca5af5c5017')
13
+ @c.author # bake
14
+
15
+ assert_equal "Tom Preston-Werner", @c.author.name
16
+ assert_equal "tom@mojombo.com", @c.author.email
17
+ end
18
+
19
+ # short_name
20
+
21
+ def test_id_abbrev
22
+ Git.any_instance.expects(:rev_parse).returns(fixture('rev_parse'))
23
+ assert_equal '80f136f', @r.commit('80f136f500dfdb8c3e8abf4ae716f875f0a1b57f').id_abbrev
24
+ end
25
+
26
+ # diff
27
+
28
+ def test_diff
29
+ # git diff --full-index 91169e1f5fa4de2eaea3f176461f5dc784796769 > test/fixtures/diff_p
30
+
31
+ Git.any_instance.expects(:diff).returns(fixture('diff_p'))
32
+ diffs = Commit.diff(@r, 'master')
33
+
34
+ assert_equal 15, diffs.size
35
+
36
+ assert_equal '.gitignore', diffs.first.a_path
37
+ assert_equal '.gitignore', diffs.first.b_path
38
+ assert_equal '4ebc8aea50e0a67e000ba29a30809d0a7b9b2666', diffs.first.a_commit.id
39
+ assert_equal '2dd02534615434d88c51307beb0f0092f21fd103', diffs.first.b_commit.id
40
+ assert_equal '100644', diffs.first.mode
41
+ assert_equal false, diffs.first.new_file
42
+ assert_equal false, diffs.first.deleted_file
43
+ assert_equal "--- a/.gitignore\n+++ b/.gitignore\n@@ -1 +1,2 @@\n coverage\n+pkg", diffs.first.diff
44
+
45
+ assert_equal 'lib/grit/actor.rb', diffs[5].a_path
46
+ assert_equal nil, diffs[5].a_commit
47
+ assert_equal 'f733bce6b57c0e5e353206e692b0e3105c2527f4', diffs[5].b_commit.id
48
+ assert_equal true, diffs[5].new_file
49
+ end
50
+
51
+ # to_s
52
+
53
+ def test_to_s
54
+ @c = Commit.create(@r, :id => 'abc')
55
+ assert_equal "abc", @c.to_s
56
+ end
57
+
58
+ # inspect
59
+
60
+ def test_inspect
61
+ @c = Commit.create(@r, :id => 'abc')
62
+ assert_equal %Q{#<Grit::Commit "abc">}, @c.inspect
63
+ end
64
+ end
data/test/test_git.rb ADDED
@@ -0,0 +1,21 @@
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 test_method_missing
9
+ assert_match(/^git version [\d\.]*$/, @git.version)
10
+ end
11
+
12
+ def test_transform_options
13
+ assert_equal ["-s"], @git.transform_options({:s => true})
14
+ assert_equal ["-s 5"], @git.transform_options({:s => 5})
15
+
16
+ assert_equal ["--max-count"], @git.transform_options({:max_count => true})
17
+ assert_equal ["--max-count=5"], @git.transform_options({:max_count => 5})
18
+
19
+ assert_equal ["-s", "-t"], @git.transform_options({:s => true, :t => true}).sort
20
+ end
21
+ end
data/test/test_head.rb ADDED
@@ -0,0 +1,17 @@
1
+ require File.dirname(__FILE__) + '/helper'
2
+
3
+ class TestHead < Test::Unit::TestCase
4
+ def setup
5
+ @r = Repo.new(GRIT_REPO)
6
+ end
7
+
8
+ # inspect
9
+
10
+ def test_inspect
11
+ Git.any_instance.expects(:for_each_ref).returns(fixture('for_each_ref'))
12
+
13
+ head = @r.heads.first
14
+
15
+ assert_equal %Q{#<Grit::Head "#{head.name}">}, head.inspect
16
+ end
17
+ end
@@ -0,0 +1,17 @@
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_repo.rb ADDED
@@ -0,0 +1,167 @@
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'", c.message
76
+ end
77
+
78
+ # commit
79
+
80
+ def test_commit
81
+ commit = @r.commit('634396b2f541a9f2d58b00be1a07f0c358b999b3')
82
+
83
+ assert_equal "634396b2f541a9f2d58b00be1a07f0c358b999b3", commit.id
84
+ end
85
+
86
+ # tree
87
+
88
+ def test_tree
89
+ Git.any_instance.expects(:ls_tree).returns(fixture('ls_tree_a'))
90
+ tree = @r.tree('master')
91
+
92
+ assert_equal 4, tree.contents.select { |c| c.instance_of?(Blob) }.size
93
+ assert_equal 3, tree.contents.select { |c| c.instance_of?(Tree) }.size
94
+ end
95
+
96
+ # blob
97
+
98
+ def test_blob
99
+ Git.any_instance.expects(:cat_file).returns(fixture('cat_file_blob'))
100
+ blob = @r.blob("abc")
101
+ assert_equal "Hello world", blob.data
102
+ end
103
+
104
+ # init_bar
105
+
106
+ def test_init_bare
107
+ Git.any_instance.expects(:init).returns(true)
108
+ Repo.expects(:new).with("/foo/bar.git")
109
+ Repo.init_bare("/foo/bar.git")
110
+ end
111
+
112
+ # diff
113
+
114
+ def test_diff
115
+ Git.any_instance.expects(:diff).with({}, 'master^', 'master', '--')
116
+ @r.diff('master^', 'master')
117
+
118
+ Git.any_instance.expects(:diff).with({}, 'master^', 'master', '--', 'foo/bar')
119
+ @r.diff('master^', 'master', 'foo/bar')
120
+
121
+ Git.any_instance.expects(:diff).with({}, 'master^', 'master', '--', 'foo/bar', 'foo/baz')
122
+ @r.diff('master^', 'master', 'foo/bar', 'foo/baz')
123
+ end
124
+
125
+ # commit_diff
126
+
127
+ def test_diff
128
+ Git.any_instance.expects(:diff).returns(fixture('diff_p'))
129
+ diffs = @r.commit_diff('master')
130
+
131
+ assert_equal 15, diffs.size
132
+ end
133
+
134
+ # init bare
135
+
136
+ # archive
137
+
138
+ def test_archive_tar
139
+ @r.archive_tar
140
+ end
141
+
142
+ # archive_tar_gz
143
+
144
+ def test_archive_tar_gz
145
+ @r.archive_tar_gz
146
+ end
147
+
148
+ # inspect
149
+
150
+ def test_inspect
151
+ assert_equal %Q{#<Grit::Repo "#{File.expand_path(GRIT_REPO)}/.git">}, @r.inspect
152
+ end
153
+
154
+ # log
155
+
156
+ def test_log
157
+ Git.any_instance.expects(:log).times(2).with({:pretty => 'raw'}, 'master').returns(fixture('rev_list'))
158
+
159
+ assert_equal '4c8124ffcf4039d292442eeccabdeca5af5c5017', @r.log.first.id
160
+ assert_equal 'ab25fd8483882c3bda8a458ad2965d2248654335', @r.log.last.id
161
+ end
162
+
163
+ def test_log_with_path_and_options
164
+ Git.any_instance.expects(:log).with({:pretty => 'raw', :max_count => 1}, 'master -- file.rb').returns(fixture('rev_list'))
165
+ @r.log('master', 'file.rb', :max_count => 1)
166
+ end
167
+ end