grit 2.0.0 → 2.1.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.
- data/History.txt +21 -0
- data/PURE_TODO +35 -0
- data/Rakefile +149 -0
- data/{test/bench/benchmarks.rb → benchmarks.rb} +6 -3
- data/benchmarks.txt +21 -0
- data/examples/ex_index.rb +7 -0
- data/grit.gemspec +76 -0
- data/lib/grit.rb +7 -5
- data/lib/grit/commit.rb +26 -12
- data/lib/grit/diff.rb +22 -13
- data/lib/grit/errors.rb +4 -1
- data/lib/grit/git-ruby.rb +12 -7
- data/lib/grit/git-ruby/git_object.rb +2 -2
- data/lib/grit/git-ruby/internal/loose.rb +1 -1
- data/lib/grit/git-ruby/internal/pack.rb +2 -0
- data/lib/grit/git-ruby/repository.rb +33 -6
- data/lib/grit/git.rb +9 -4
- data/lib/grit/index.rb +1 -1
- data/lib/{open3_detach.rb → grit/open3_detach.rb} +0 -0
- data/lib/grit/ref.rb +3 -1
- data/lib/grit/repo.rb +81 -1
- data/lib/grit/tag.rb +57 -4
- data/lib/grit/tree.rb +1 -1
- metadata +30 -46
- data/VERSION.yml +0 -4
- data/test/helper.rb +0 -18
- data/test/profile.rb +0 -21
- data/test/suite.rb +0 -6
- data/test/test_actor.rb +0 -35
- data/test/test_blame.rb +0 -32
- data/test/test_blame_tree.rb +0 -33
- data/test/test_blob.rb +0 -83
- data/test/test_commit.rb +0 -207
- data/test/test_commit_stats.rb +0 -33
- data/test/test_commit_write.rb +0 -20
- data/test/test_config.rb +0 -58
- data/test/test_diff.rb +0 -18
- data/test/test_file_index.rb +0 -56
- data/test/test_git.rb +0 -105
- data/test/test_grit.rb +0 -32
- data/test/test_head.rb +0 -47
- data/test/test_index_status.rb +0 -40
- data/test/test_merge.rb +0 -17
- data/test/test_raw.rb +0 -16
- data/test/test_real.rb +0 -19
- data/test/test_reality.rb +0 -17
- data/test/test_remote.rb +0 -14
- data/test/test_repo.rb +0 -349
- data/test/test_rubygit.rb +0 -192
- data/test/test_rubygit_alt.rb +0 -40
- data/test/test_rubygit_index.rb +0 -76
- data/test/test_rubygit_iv2.rb +0 -28
- data/test/test_submodule.rb +0 -69
- data/test/test_tag.rb +0 -67
- data/test/test_tree.rb +0 -101
data/test/test_rubygit_alt.rb
DELETED
@@ -1,40 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/helper'
|
2
|
-
require 'pp'
|
3
|
-
|
4
|
-
class TestRubyGitAlt < Test::Unit::TestCase
|
5
|
-
|
6
|
-
def setup
|
7
|
-
@git1 = Grit::Repo.new(File.join(File.dirname(__FILE__), *%w[dot_git]), :is_bare => true)
|
8
|
-
@git2 = Grit::Repo.new(File.join(File.dirname(__FILE__), *%w[dot_git_clone]), :is_bare => true)
|
9
|
-
@git3 = Grit::Repo.new(File.join(File.dirname(__FILE__), *%w[dot_git_clone2]), :is_bare => true)
|
10
|
-
@commit_sha = 'ca8a30f5a7f0f163bbe3b6f0abf18a6c83b0687a'
|
11
|
-
@tree_sha = 'cd7422af5a2e0fff3e94d6fb1a8fff03b2841881'
|
12
|
-
@blob_sha = '4232d073306f01cf0b895864e5a5cfad7dd76fce'
|
13
|
-
end
|
14
|
-
|
15
|
-
def test_basic
|
16
|
-
sha_hex = [@commit_sha].pack("H*")
|
17
|
-
assert @git1.git.ruby_git.in_loose?(sha_hex)
|
18
|
-
assert @git2.git.ruby_git.in_loose?(sha_hex)
|
19
|
-
assert @git1.git.ruby_git.object_exists?(@commit_sha)
|
20
|
-
assert @git2.git.ruby_git.object_exists?(@commit_sha)
|
21
|
-
assert_equal 10, @git1.commits.size
|
22
|
-
assert_equal 10, @git2.commits.size
|
23
|
-
end
|
24
|
-
|
25
|
-
def test_clone_of_clone
|
26
|
-
sha_hex = [@commit_sha].pack("H*")
|
27
|
-
assert @git2.git.ruby_git.in_loose?(sha_hex)
|
28
|
-
assert @git3.git.ruby_git.in_loose?(sha_hex)
|
29
|
-
assert @git2.git.ruby_git.object_exists?(@commit_sha)
|
30
|
-
assert @git3.git.ruby_git.object_exists?(@commit_sha)
|
31
|
-
assert_equal 10, @git2.commits.size
|
32
|
-
assert_equal 10, @git3.commits.size
|
33
|
-
end
|
34
|
-
|
35
|
-
def test_tree_path
|
36
|
-
file = @git2.tree('master', ['test/test_head.rb']).contents.first.name
|
37
|
-
assert_equal file, 'test/test_head.rb'
|
38
|
-
end
|
39
|
-
|
40
|
-
end
|
data/test/test_rubygit_index.rb
DELETED
@@ -1,76 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/helper'
|
2
|
-
require 'pp'
|
3
|
-
|
4
|
-
class TestRubyGitIndex < Test::Unit::TestCase
|
5
|
-
|
6
|
-
def setup
|
7
|
-
@base_repo = create_temp_repo(File.join(File.dirname(__FILE__), *%w[dot_git_iv2]))
|
8
|
-
@git = Grit::Repo.new(@base_repo, :is_bare => true)
|
9
|
-
@rgit = @git.git.ruby_git
|
10
|
-
@user = Actor.from_string("Tom Werner <tom@example.com>")
|
11
|
-
end
|
12
|
-
|
13
|
-
def teardown
|
14
|
-
FileUtils.rm_r(@base_repo)
|
15
|
-
end
|
16
|
-
|
17
|
-
def create_temp_repo(clone_path)
|
18
|
-
filename = 'git_test' + Time.now.to_i.to_s + rand(300).to_s.rjust(3, '0')
|
19
|
-
tmp_path = File.join("/tmp/", filename)
|
20
|
-
FileUtils.mkdir_p(tmp_path)
|
21
|
-
FileUtils.cp_r(clone_path, tmp_path)
|
22
|
-
File.join(tmp_path, 'dot_git_iv2')
|
23
|
-
end
|
24
|
-
|
25
|
-
def test_add_files
|
26
|
-
sha = @git.commits.first.tree.id
|
27
|
-
|
28
|
-
i = @git.index
|
29
|
-
i.read_tree(sha)
|
30
|
-
i.add('atester.rb', 'test stuff')
|
31
|
-
i.commit('message', [@git.commits.first], @user, nil, 'master')
|
32
|
-
|
33
|
-
b = @git.commits.first.tree/'atester.rb'
|
34
|
-
assert_equal 'f80c3b68482d5e1c8d24c9b8139340f0d0a928d0', b.id
|
35
|
-
end
|
36
|
-
|
37
|
-
def test_add_path_file
|
38
|
-
sha = @git.commits.first.tree.id
|
39
|
-
|
40
|
-
i = @git.index
|
41
|
-
i.read_tree(sha)
|
42
|
-
i.add('lib/atester.rb', 'test stuff')
|
43
|
-
i.commit('message', [@git.commits.first], @user, nil, 'master')
|
44
|
-
|
45
|
-
b = @git.commits.first.tree/'lib'/'atester.rb'
|
46
|
-
assert_equal 'f80c3b68482d5e1c8d24c9b8139340f0d0a928d0', b.id
|
47
|
-
b = @git.commits.first.tree/'lib'/'grit.rb'
|
48
|
-
assert_equal '77aa887449c28a922a660b2bb749e4127f7664e5', b.id
|
49
|
-
end
|
50
|
-
|
51
|
-
def test_ordered_properly
|
52
|
-
sha = @git.commits.first.tree.id
|
53
|
-
|
54
|
-
i = @git.index
|
55
|
-
i.read_tree(sha)
|
56
|
-
i.add('lib.rb', 'test stuff')
|
57
|
-
i.commit('message', [@git.commits.first], @user, nil, 'master')
|
58
|
-
|
59
|
-
tr = @git.commits.first.tree.contents
|
60
|
-
entries = tr.select { |c| c.name[0, 3] == 'lib' }.map { |c| c.name }
|
61
|
-
assert_equal 'lib.rb', entries[0]
|
62
|
-
assert_equal 'lib', entries[1]
|
63
|
-
end
|
64
|
-
|
65
|
-
def test_modify_file
|
66
|
-
sha = @git.commits.first.tree.id
|
67
|
-
|
68
|
-
i = @git.index
|
69
|
-
i.read_tree(sha)
|
70
|
-
i.add('README.txt', 'test more stuff')
|
71
|
-
i.commit('message', [@git.commits.first], @user, nil, 'master')
|
72
|
-
|
73
|
-
b = @git.commits.first.tree/'README.txt'
|
74
|
-
assert_equal 'e45d6b418e34951ddaa3e78e4fc4d3d92a46d3d1', b.id
|
75
|
-
end
|
76
|
-
end
|
data/test/test_rubygit_iv2.rb
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/helper'
|
2
|
-
require 'pp'
|
3
|
-
|
4
|
-
class TestRubyGitIv2 < Test::Unit::TestCase
|
5
|
-
|
6
|
-
def setup
|
7
|
-
@git = Grit::Repo.new(File.join(File.dirname(__FILE__), *%w[dot_git_iv2]), :is_bare => true)
|
8
|
-
@rgit = @git.git.ruby_git
|
9
|
-
@commit_sha = 'ca8a30f5a7f0f163bbe3b6f0abf18a6c83b0687a'
|
10
|
-
@tree_sha = 'cd7422af5a2e0fff3e94d6fb1a8fff03b2841881'
|
11
|
-
@blob_sha = '4232d073306f01cf0b895864e5a5cfad7dd76fce'
|
12
|
-
end
|
13
|
-
|
14
|
-
def test_basic
|
15
|
-
assert @rgit.object_exists?(@commit_sha)
|
16
|
-
assert_equal 10, @git.commits.size
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_objects
|
20
|
-
commit = @rgit.get_object_by_sha1(@commit_sha)
|
21
|
-
assert_equal commit.author.email, 'schacon@gmail.com'
|
22
|
-
tree = @rgit.get_object_by_sha1(@tree_sha)
|
23
|
-
assert_equal 7, tree.entry.size
|
24
|
-
blob = @rgit.get_object_by_sha1(@blob_sha)
|
25
|
-
assert_match 'First public release', blob.content
|
26
|
-
end
|
27
|
-
|
28
|
-
end
|
data/test/test_submodule.rb
DELETED
@@ -1,69 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/helper'
|
2
|
-
|
3
|
-
class TestSubmodule < Test::Unit::TestCase
|
4
|
-
def setup
|
5
|
-
@r = Repo.new(GRIT_REPO)
|
6
|
-
@s = Submodule.allocate
|
7
|
-
end
|
8
|
-
|
9
|
-
# config
|
10
|
-
|
11
|
-
def test_config
|
12
|
-
data = fixture('gitmodules')
|
13
|
-
blob = stub(:data => data, :id => 'abc')
|
14
|
-
tree = stub(:'/' => blob)
|
15
|
-
commit = stub(:tree => tree)
|
16
|
-
repo = stub(:commit => commit)
|
17
|
-
|
18
|
-
config = Submodule.config(repo)
|
19
|
-
|
20
|
-
assert_equal "git://github.com/mojombo/glowstick", config['test/glowstick']['url']
|
21
|
-
assert_equal "git://github.com/mojombo/god", config['god']['url']
|
22
|
-
end
|
23
|
-
|
24
|
-
def test_config_with_windows_lineendings
|
25
|
-
data = fixture('gitmodules').gsub(/\n/, "\r\n")
|
26
|
-
blob = stub(:data => data, :id => 'abc')
|
27
|
-
tree = stub(:'/' => blob)
|
28
|
-
commit = stub(:tree => tree)
|
29
|
-
repo = stub(:commit => commit)
|
30
|
-
|
31
|
-
config = Submodule.config(repo)
|
32
|
-
|
33
|
-
assert_equal "git://github.com/mojombo/glowstick", config['test/glowstick']['url']
|
34
|
-
assert_equal "git://github.com/mojombo/god", config['god']['url']
|
35
|
-
end
|
36
|
-
|
37
|
-
def test_no_config
|
38
|
-
tree = stub(:'/' => nil)
|
39
|
-
commit = stub(:tree => tree)
|
40
|
-
repo = stub(:commit => commit)
|
41
|
-
|
42
|
-
config = Submodule.config(repo)
|
43
|
-
|
44
|
-
assert_equal({}, config)
|
45
|
-
end
|
46
|
-
|
47
|
-
def test_empty_config
|
48
|
-
blob = stub(:data => '', :id => 'abc')
|
49
|
-
tree = stub(:'/' => blob)
|
50
|
-
commit = stub(:tree => tree)
|
51
|
-
repo = stub(:commit => commit)
|
52
|
-
|
53
|
-
config = Submodule.config(repo)
|
54
|
-
|
55
|
-
assert_equal({}, config)
|
56
|
-
end
|
57
|
-
|
58
|
-
# inspect
|
59
|
-
|
60
|
-
def test_inspect
|
61
|
-
@t = Submodule.create(@r, :id => 'abc')
|
62
|
-
assert_equal %Q{#<Grit::Submodule "abc">}, @t.inspect
|
63
|
-
end
|
64
|
-
|
65
|
-
def test_basename
|
66
|
-
@submodule = Submodule.create(@r, :name => 'foo/bar')
|
67
|
-
assert_equal "bar", @submodule.basename
|
68
|
-
end
|
69
|
-
end
|
data/test/test_tag.rb
DELETED
@@ -1,67 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/helper'
|
2
|
-
|
3
|
-
class TestTag < 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
|
-
# list_from_string size
|
9
|
-
|
10
|
-
def test_list_from_string_size
|
11
|
-
assert_equal 5, @r.tags.size
|
12
|
-
end
|
13
|
-
|
14
|
-
# list_from_string
|
15
|
-
|
16
|
-
def test_list_from_string
|
17
|
-
tag = @r.tags[1]
|
18
|
-
|
19
|
-
assert_equal 'not_annotated', tag.name
|
20
|
-
assert_equal 'ca8a30f5a7f0f163bbe3b6f0abf18a6c83b0687a', tag.commit.id
|
21
|
-
end
|
22
|
-
|
23
|
-
# list_from_string_for_signed_tag
|
24
|
-
|
25
|
-
def test_list_from_string_for_signed_tag
|
26
|
-
tag = @r.tags[2]
|
27
|
-
|
28
|
-
assert_equal 'v0.7.0', tag.name
|
29
|
-
assert_equal '7bcc0ee821cdd133d8a53e8e7173a334fef448aa', tag.commit.id
|
30
|
-
end
|
31
|
-
|
32
|
-
# list_from_string_for_annotated_tag
|
33
|
-
|
34
|
-
def test_list_from_string_for_annotated_tag
|
35
|
-
tag = @r.tags.first
|
36
|
-
|
37
|
-
assert_equal 'annotated', tag.name
|
38
|
-
assert_equal 'ca8a30f5a7f0f163bbe3b6f0abf18a6c83b0687a', tag.commit.id
|
39
|
-
end
|
40
|
-
|
41
|
-
# list_from_string_for_packed_tag
|
42
|
-
|
43
|
-
def test_list_from_string_for_packed_tag
|
44
|
-
tag = @r.tags[4]
|
45
|
-
|
46
|
-
assert_equal 'packed', tag.name
|
47
|
-
assert_equal 'ca8a30f5a7f0f163bbe3b6f0abf18a6c83b0687a', tag.commit.id
|
48
|
-
end
|
49
|
-
|
50
|
-
# list_from_string_for_packed_annotated_tag
|
51
|
-
|
52
|
-
def test_list_from_string_for_packed_annotated_tag
|
53
|
-
tag = @r.tags[3]
|
54
|
-
|
55
|
-
assert_equal 'packed_annotated', tag.name
|
56
|
-
assert_equal '7bcc0ee821cdd133d8a53e8e7173a334fef448aa', tag.commit.id
|
57
|
-
end
|
58
|
-
|
59
|
-
|
60
|
-
# inspect
|
61
|
-
|
62
|
-
def test_inspect
|
63
|
-
tag = @r.tags.last
|
64
|
-
|
65
|
-
assert_equal %Q{#<Grit::Tag "#{tag.name}">}, tag.inspect
|
66
|
-
end
|
67
|
-
end
|
data/test/test_tree.rb
DELETED
@@ -1,101 +0,0 @@
|
|
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
|
-
def test_nosuch_tree
|
11
|
-
t = @r.tree('blahblah')
|
12
|
-
assert t.contents.is_a?(Array)
|
13
|
-
assert t.is_a?(Tree)
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_contents_should_cache
|
17
|
-
Git.any_instance.expects(:ls_tree).returns(
|
18
|
-
fixture('ls_tree_a'),
|
19
|
-
fixture('ls_tree_b')
|
20
|
-
).times(2)
|
21
|
-
tree = @r.tree('master')
|
22
|
-
|
23
|
-
child = tree.contents.last
|
24
|
-
|
25
|
-
child.contents
|
26
|
-
child.contents
|
27
|
-
end
|
28
|
-
|
29
|
-
# content_from_string
|
30
|
-
|
31
|
-
def test_content_from_string_tree_should_return_tree
|
32
|
-
text = fixture('ls_tree_a').split("\n").last
|
33
|
-
|
34
|
-
tree = @t.content_from_string(nil, text)
|
35
|
-
|
36
|
-
assert_equal Tree, tree.class
|
37
|
-
assert_equal "650fa3f0c17f1edb4ae53d8dcca4ac59d86e6c44", tree.id
|
38
|
-
assert_equal "040000", tree.mode
|
39
|
-
assert_equal "test", tree.name
|
40
|
-
end
|
41
|
-
|
42
|
-
def test_content_from_string_tree_should_return_blob
|
43
|
-
text = fixture('ls_tree_b').split("\n").first
|
44
|
-
|
45
|
-
tree = @t.content_from_string(nil, text)
|
46
|
-
|
47
|
-
assert_equal Blob, tree.class
|
48
|
-
assert_equal "aa94e396335d2957ca92606f909e53e7beaf3fbb", tree.id
|
49
|
-
assert_equal "100644", tree.mode
|
50
|
-
assert_equal "grit.rb", tree.name
|
51
|
-
end
|
52
|
-
|
53
|
-
def test_content_from_string_tree_should_return_submodule
|
54
|
-
text = fixture('ls_tree_submodule').split("\n").first
|
55
|
-
|
56
|
-
sm = @t.content_from_string(nil, text)
|
57
|
-
|
58
|
-
assert_kind_of Submodule, sm
|
59
|
-
end
|
60
|
-
|
61
|
-
def test_content_from_string_invalid_type_should_raise
|
62
|
-
assert_raise(RuntimeError) do
|
63
|
-
@t.content_from_string(nil, "040000 bogus 650fa3f0c17f1edb4ae53d8dcca4ac59d86e6c44 test")
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
# /
|
68
|
-
|
69
|
-
def test_slash
|
70
|
-
Git.any_instance.expects(:ls_tree).returns(
|
71
|
-
fixture('ls_tree_a')
|
72
|
-
)
|
73
|
-
tree = @r.tree('master')
|
74
|
-
|
75
|
-
assert_equal 'aa06ba24b4e3f463b3c4a85469d0fb9e5b421cf8', (tree/'lib').id
|
76
|
-
assert_equal '8b1e02c0fb554eed2ce2ef737a68bb369d7527df', (tree/'README.txt').id
|
77
|
-
end
|
78
|
-
|
79
|
-
def test_slash_with_commits
|
80
|
-
Git.any_instance.expects(:ls_tree).returns(
|
81
|
-
fixture('ls_tree_commit')
|
82
|
-
)
|
83
|
-
tree = @r.tree('master')
|
84
|
-
|
85
|
-
assert_equal 'd35b34c6e931b9da8f6941007a92c9c9a9b0141a', (tree/'bar').id
|
86
|
-
assert_equal '2afb47bcedf21663580d5e6d2f406f08f3f65f19', (tree/'foo').id
|
87
|
-
assert_equal 'f623ee576a09ca491c4a27e48c0dfe04be5f4a2e', (tree/'baz').id
|
88
|
-
end
|
89
|
-
|
90
|
-
# inspect
|
91
|
-
|
92
|
-
def test_inspect
|
93
|
-
@t = Tree.create(@r, :id => 'abc')
|
94
|
-
assert_equal %Q{#<Grit::Tree "abc">}, @t.inspect
|
95
|
-
end
|
96
|
-
|
97
|
-
def test_basename
|
98
|
-
@t = Tree.create(@r, :name => 'foo/bar')
|
99
|
-
assert_equal "bar", @t.basename
|
100
|
-
end
|
101
|
-
end
|