boof-grit 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/API.txt +101 -0
- data/History.txt +53 -0
- data/LICENSE +22 -0
- data/README.md +210 -0
- data/VERSION.yml +4 -0
- data/examples/ex_add_commit.rb +13 -0
- data/examples/ex_index.rb +14 -0
- data/lib/grit.rb +68 -0
- data/lib/grit/actor.rb +36 -0
- data/lib/grit/blame.rb +61 -0
- data/lib/grit/blob.rb +126 -0
- data/lib/grit/commit.rb +246 -0
- data/lib/grit/commit_stats.rb +128 -0
- data/lib/grit/config.rb +44 -0
- data/lib/grit/diff.rb +70 -0
- data/lib/grit/errors.rb +7 -0
- data/lib/grit/git-ruby.rb +186 -0
- data/lib/grit/git-ruby/commit_db.rb +52 -0
- data/lib/grit/git-ruby/file_index.rb +193 -0
- data/lib/grit/git-ruby/git_object.rb +350 -0
- data/lib/grit/git-ruby/internal/file_window.rb +58 -0
- data/lib/grit/git-ruby/internal/loose.rb +137 -0
- data/lib/grit/git-ruby/internal/pack.rb +382 -0
- data/lib/grit/git-ruby/internal/raw_object.rb +37 -0
- data/lib/grit/git-ruby/object.rb +325 -0
- data/lib/grit/git-ruby/repository.rb +740 -0
- data/lib/grit/git.rb +141 -0
- data/lib/grit/index.rb +122 -0
- data/lib/grit/lazy.rb +33 -0
- data/lib/grit/merge.rb +45 -0
- data/lib/grit/ref.rb +177 -0
- data/lib/grit/repo.rb +452 -0
- data/lib/grit/ruby1.9.rb +7 -0
- data/lib/grit/status.rb +151 -0
- data/lib/grit/submodule.rb +88 -0
- data/lib/grit/tag.rb +66 -0
- data/lib/grit/tree.rb +123 -0
- data/lib/open3_detach.rb +46 -0
- data/test/bench/benchmarks.rb +126 -0
- data/test/helper.rb +18 -0
- data/test/profile.rb +21 -0
- data/test/suite.rb +6 -0
- data/test/test_actor.rb +35 -0
- data/test/test_blame.rb +32 -0
- data/test/test_blame_tree.rb +33 -0
- data/test/test_blob.rb +83 -0
- data/test/test_commit.rb +207 -0
- data/test/test_commit_stats.rb +33 -0
- data/test/test_commit_write.rb +20 -0
- data/test/test_config.rb +58 -0
- data/test/test_diff.rb +18 -0
- data/test/test_file_index.rb +56 -0
- data/test/test_git.rb +94 -0
- data/test/test_grit.rb +32 -0
- data/test/test_head.rb +72 -0
- data/test/test_index_status.rb +40 -0
- data/test/test_merge.rb +17 -0
- data/test/test_raw.rb +16 -0
- data/test/test_real.rb +19 -0
- data/test/test_reality.rb +17 -0
- data/test/test_remote.rb +14 -0
- data/test/test_repo.rb +381 -0
- data/test/test_rubygit.rb +192 -0
- data/test/test_rubygit_alt.rb +40 -0
- data/test/test_rubygit_index.rb +76 -0
- data/test/test_rubygit_iv2.rb +28 -0
- data/test/test_submodule.rb +69 -0
- data/test/test_tag.rb +103 -0
- data/test/test_tree.rb +101 -0
- metadata +143 -0
@@ -0,0 +1,33 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/helper'
|
2
|
+
|
3
|
+
class TestCommitStats < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
File.expects(:exist?).twice.returns(true)
|
7
|
+
@r = Repo.new(GRIT_REPO)
|
8
|
+
|
9
|
+
Git.any_instance.expects(:log).returns(fixture('log'))
|
10
|
+
@stats = @r.commit_stats
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_commit_stats
|
14
|
+
assert_equal 3, @stats.size
|
15
|
+
end
|
16
|
+
|
17
|
+
# to_hash
|
18
|
+
|
19
|
+
def test_to_hash
|
20
|
+
expected = {
|
21
|
+
"files"=>
|
22
|
+
[["examples/ex_add_commit.rb", 13, 0, 13],
|
23
|
+
["examples/ex_index.rb", 1, 1, 2]],
|
24
|
+
"total"=>15,
|
25
|
+
"additions"=>14,
|
26
|
+
"id"=>"a49b96b339c525d7fd455e0ad4f6fe7b550c9543",
|
27
|
+
"deletions"=>1
|
28
|
+
}
|
29
|
+
|
30
|
+
assert_equal expected, @stats.assoc('a49b96b339c525d7fd455e0ad4f6fe7b550c9543')[1].to_hash
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/helper'
|
2
|
+
|
3
|
+
class TestCommitWrite < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@r = Repo.new(GRIT_REPO)
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_commit
|
9
|
+
Git.any_instance.expects(:commit).returns(fixture('commit'))
|
10
|
+
results = @r.commit_index('my message')
|
11
|
+
assert_match /Created commit/, results
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_commit_all
|
15
|
+
Git.any_instance.expects(:commit).returns(fixture('commit'))
|
16
|
+
results = @r.commit_all('my message')
|
17
|
+
assert_match /Created commit/, results
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
data/test/test_config.rb
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/helper'
|
2
|
+
|
3
|
+
class TestConfig < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@r = Repo.new(GRIT_REPO)
|
6
|
+
end
|
7
|
+
|
8
|
+
# data
|
9
|
+
|
10
|
+
def test_bracketed_fetch
|
11
|
+
Git.any_instance.expects(:config).returns(fixture('simple_config'))
|
12
|
+
|
13
|
+
config = @r.config
|
14
|
+
|
15
|
+
assert_equal "git://github.com/mojombo/grit.git", config["remote.origin.url"]
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_bracketed_fetch_returns_nil
|
19
|
+
Git.any_instance.expects(:config).returns(fixture('simple_config'))
|
20
|
+
|
21
|
+
config = @r.config
|
22
|
+
|
23
|
+
assert_equal nil, config["unknown"]
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_fetch
|
27
|
+
Git.any_instance.expects(:config).returns(fixture('simple_config'))
|
28
|
+
|
29
|
+
config = @r.config
|
30
|
+
|
31
|
+
assert_equal "false", config.fetch("core.bare")
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_fetch_with_default
|
35
|
+
Git.any_instance.expects(:config).returns(fixture('simple_config'))
|
36
|
+
|
37
|
+
config = @r.config
|
38
|
+
|
39
|
+
assert_equal "default", config.fetch("unknown", "default")
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_fetch_without_default_raises
|
43
|
+
Git.any_instance.expects(:config).returns(fixture('simple_config'))
|
44
|
+
|
45
|
+
config = @r.config
|
46
|
+
|
47
|
+
assert_raise(IndexError) do
|
48
|
+
config.fetch("unknown")
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_set_value
|
53
|
+
Git.any_instance.expects(:config).with({}, 'unknown', 'default')
|
54
|
+
|
55
|
+
config = @r.config
|
56
|
+
config["unknown"] = "default"
|
57
|
+
end
|
58
|
+
end
|
data/test/test_diff.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/helper'
|
2
|
+
|
3
|
+
class TestDiff < 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_new_mode
|
11
|
+
output = fixture('diff_new_mode')
|
12
|
+
|
13
|
+
diffs = Grit::Diff.list_from_string(@r, output)
|
14
|
+
assert_equal 2, diffs.size
|
15
|
+
assert_equal 10, diffs.first.diff.split("\n").size
|
16
|
+
assert_equal nil, diffs.last.diff
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/helper'
|
2
|
+
|
3
|
+
class TestFileIndex < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup_a
|
6
|
+
@findex = Grit::GitRuby::FileIndex.new(File.join(File.dirname(__FILE__), *%w[dot_git]))
|
7
|
+
@commit = 'c12f398c2f3c4068ca5e01d736b1c9ae994b2138'
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_count_all
|
11
|
+
setup_a
|
12
|
+
assert_equal 107, @findex.count_all
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_count
|
16
|
+
setup_a
|
17
|
+
assert_equal 20, @findex.count(@commit)
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_files
|
21
|
+
setup_a
|
22
|
+
files = @findex.files(@commit)
|
23
|
+
assert_equal 4, files.size
|
24
|
+
assert_equal "lib/grit/blob.rb", files.first
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_commits_for
|
28
|
+
setup_a
|
29
|
+
commits = @findex.commits_for('lib/grit/blob.rb')
|
30
|
+
assert commits.include?('3e0955045cb189a7112015c26132152a94f637bf')
|
31
|
+
assert_equal 8, commits.size
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_last_commits_array
|
35
|
+
setup_a
|
36
|
+
arr = @findex.last_commits(@commit, ['lib/grit/git.rb', 'lib/grit/actor.rb', 'lib/grit/commit.rb'])
|
37
|
+
assert_equal '74fd66519e983a0f29e16a342a6059dbffe36020', arr['lib/grit/git.rb']
|
38
|
+
assert_equal @commit, arr['lib/grit/commit.rb']
|
39
|
+
assert_equal nil, arr['lib/grit/actor.rb']
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_last_commits_pattern
|
43
|
+
setup_a
|
44
|
+
arr = @findex.last_commits(@commit, /lib\/grit\/[^\/]*$/)
|
45
|
+
assert_equal 10, arr.size
|
46
|
+
assert_equal @commit, arr['lib/grit/commit.rb']
|
47
|
+
assert_equal nil, arr['lib/grit/actor.rb']
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_last_commits_array
|
51
|
+
setup_a
|
52
|
+
arr = @findex.last_commits(@commit, ['lib/grit.rb', 'lib/grit/'])
|
53
|
+
assert_equal @commit, arr['lib/grit/']
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
data/test/test_git.rb
ADDED
@@ -0,0 +1,94 @@
|
|
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__), '..', '.git')
|
6
|
+
end
|
7
|
+
|
8
|
+
def teardown
|
9
|
+
Grit.debug = false
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_method_missing
|
13
|
+
assert_match(/^git version [\w\.]*$/, @git.version)
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_logs_stderr
|
17
|
+
Grit.debug = true
|
18
|
+
Grit.stubs(:log)
|
19
|
+
Grit.expects(:log).with(includes("git: 'bad' is not a git-command"))
|
20
|
+
@git.bad
|
21
|
+
end
|
22
|
+
|
23
|
+
def testl_logs_stderr_when_skipping_timeout
|
24
|
+
Grit.debug = true
|
25
|
+
Grit.stubs(:log)
|
26
|
+
Grit.expects(:log).with(includes("git: 'bad' is not a git-command"))
|
27
|
+
@git.bad :timeout => false
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_transform_options
|
31
|
+
assert_equal ["-s"], @git.transform_options({:s => true})
|
32
|
+
assert_equal ["-s '5'"], @git.transform_options({:s => 5})
|
33
|
+
|
34
|
+
assert_equal ["--max-count"], @git.transform_options({:max_count => true})
|
35
|
+
assert_equal ["--max-count='5'"], @git.transform_options({:max_count => 5})
|
36
|
+
|
37
|
+
assert_equal ["-s", "-t"], @git.transform_options({:s => true, :t => true}).sort
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_uses_custom_sh_method
|
41
|
+
@git.expects(:sh)
|
42
|
+
@git.something
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_can_skip_timeout
|
46
|
+
@git.expects(:wild_sh)
|
47
|
+
@git.something(:timeout => false)
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_raises_if_too_many_bytes
|
51
|
+
@git.instance_variable_set(:@bytes_read, 6000000)
|
52
|
+
assert_raises Grit::Git::GitTimeout do
|
53
|
+
@git.version
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_raises_on_slow_shell
|
58
|
+
Grit::Git.git_timeout = 0.0000001
|
59
|
+
assert_raises Grit::Git::GitTimeout do
|
60
|
+
@git.version
|
61
|
+
end
|
62
|
+
Grit::Git.git_timeout = 5.0
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_it_really_shell_escapes_arguments_to_the_git_shell
|
66
|
+
@git.expects(:sh).with("#{Git.git_binary} --git-dir='#{@git.git_dir}' foo --bar='bazz\\'er'")
|
67
|
+
@git.foo(:bar => "bazz'er")
|
68
|
+
@git.expects(:sh).with("#{Git.git_binary} --git-dir='#{@git.git_dir}' bar -x 'quu\\'x'")
|
69
|
+
@git.bar(:x => "quu'x")
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_it_shell_escapes_the_standalone_argument
|
73
|
+
@git.expects(:sh).with("#{Git.git_binary} --git-dir='#{@git.git_dir}' foo 'bar\\'s'")
|
74
|
+
@git.foo({}, "bar's")
|
75
|
+
|
76
|
+
@git.expects(:sh).with("#{Git.git_binary} --git-dir='#{@git.git_dir}' foo 'bar' '\\; echo \\'noooo\\''")
|
77
|
+
@git.foo({}, "bar", "; echo 'noooo'")
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_piping_should_work_on_1_9
|
81
|
+
@git.expects(:sh).with("#{Git.git_binary} --git-dir='#{@git.git_dir}' archive 'master' | gzip")
|
82
|
+
@git.archive({}, "master", "| gzip")
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_it_uses_a_work_tree
|
86
|
+
work_tree = File.join @git.git_dir, '..'
|
87
|
+
@git.work_tree = File.expand_path work_tree
|
88
|
+
|
89
|
+
@git.expects(:sh).with("#{Git.git_binary} --work-tree='#{ @git.work_tree }' --git-dir='#{@git.git_dir}' foo ")
|
90
|
+
|
91
|
+
@git.foo({})
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
data/test/test_grit.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/helper'
|
2
|
+
|
3
|
+
class TestGrit < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@old_debug = Grit.debug
|
6
|
+
@old_logger = Grit.logger
|
7
|
+
Grit.debug = true
|
8
|
+
end
|
9
|
+
|
10
|
+
def teardown
|
11
|
+
Grit.debug = @old_debug
|
12
|
+
Grit.logger = @old_logger
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_uses_stdout_logger_by_default
|
16
|
+
assert_equal STDOUT, Grit.logger.instance_variable_get(:@logdev).dev
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_can_override_logger
|
20
|
+
my_logger = Logger.new(io = StringIO.new)
|
21
|
+
Grit.logger = my_logger
|
22
|
+
assert_equal my_logger, Grit.logger
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_logs_to_specified_logger
|
26
|
+
Grit.logger = Logger.new(io = StringIO.new)
|
27
|
+
Grit.log 'hi mom'
|
28
|
+
io.rewind
|
29
|
+
assert io.read.include?('hi mom')
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
data/test/test_head.rb
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/helper'
|
2
|
+
|
3
|
+
class TestHead < 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
|
+
# create
|
9
|
+
|
10
|
+
def test_create_head
|
11
|
+
returned_head = @r.branch 'test/create_head'
|
12
|
+
found_head = @r.heads.find { |h| h.name == 'test/create_head' }
|
13
|
+
@r.git.branch({:d => true}, 'test/create_head')
|
14
|
+
assert_instance_of Grit::Head, returned_head
|
15
|
+
assert_equal returned_head, found_head
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_in_branch_commits_index
|
19
|
+
@r = Repo.init "#{ File.join File.dirname(__FILE__), 'not_bare' }"
|
20
|
+
|
21
|
+
expect_message = 'This is a test...'
|
22
|
+
path = File.join @r.working_dir, 'in_branch'
|
23
|
+
File.open(path, 'w') { |f| f << expect_message }
|
24
|
+
|
25
|
+
commit = @r.branch('test/in_branch').
|
26
|
+
in_branch(expect_message) { |r| r.add path }
|
27
|
+
|
28
|
+
assert_equal expect_message, commit.message
|
29
|
+
ensure
|
30
|
+
FileUtils.rm_r @r.working_dir if File.exists? @r.working_dir
|
31
|
+
end
|
32
|
+
|
33
|
+
# inspect
|
34
|
+
|
35
|
+
def test_inspect
|
36
|
+
head = @r.heads[1]
|
37
|
+
assert_equal %Q{#<Grit::Head "test/master">}, head.inspect
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_master
|
41
|
+
head = @r.commit('master')
|
42
|
+
assert_equal 'ca8a30f5a7f0f163bbe3b6f0abf18a6c83b0687a', head.id
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_submaster
|
46
|
+
head = @r.commit('test/master')
|
47
|
+
assert_equal '2d3acf90f35989df8f262dc50beadc4ee3ae1560', head.id
|
48
|
+
end
|
49
|
+
|
50
|
+
# heads with slashes
|
51
|
+
|
52
|
+
def test_heads_with_slashes
|
53
|
+
head = @r.heads[3]
|
54
|
+
assert_equal %Q{#<Grit::Head "test/chacon">}, head.inspect
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_is_head
|
58
|
+
assert @r.is_head?('master')
|
59
|
+
assert @r.is_head?('test/chacon')
|
60
|
+
assert !@r.is_head?('masterblah')
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_head_count
|
64
|
+
assert_equal 5, @r.heads.size
|
65
|
+
end
|
66
|
+
|
67
|
+
|
68
|
+
def test_nonpack
|
69
|
+
assert @r.heads.map { |h| h.name }.include?('nonpack')
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/helper'
|
2
|
+
|
3
|
+
class TestIndexStatus < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@r = Repo.new(GRIT_REPO)
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_add
|
9
|
+
Git.any_instance.expects(:add).with({}, 'file1', 'file2')
|
10
|
+
@r.add('file1', 'file2')
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_add_array
|
14
|
+
Git.any_instance.expects(:add).with({}, 'file1', 'file2')
|
15
|
+
@r.add(['file1', 'file2'])
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_remove
|
19
|
+
Git.any_instance.expects(:rm).with({}, 'file1', 'file2')
|
20
|
+
@r.remove('file1', 'file2')
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_remove_array
|
24
|
+
Git.any_instance.expects(:rm).with({}, 'file1', 'file2')
|
25
|
+
@r.remove(['file1', 'file2'])
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_status
|
29
|
+
Git.any_instance.expects(:diff_index).with({}, 'HEAD').returns(fixture('diff_index'))
|
30
|
+
Git.any_instance.expects(:diff_files).returns(fixture('diff_files'))
|
31
|
+
Git.any_instance.expects(:ls_files).with({:stage => true}).returns(fixture('ls_files'))
|
32
|
+
status = @r.status
|
33
|
+
stat = status['lib/grit/repo.rb']
|
34
|
+
assert_equal stat.sha_repo, "71e930d551c413a123f43e35c632ea6ba3e3705e"
|
35
|
+
assert_equal stat.mode_repo, "100644"
|
36
|
+
assert_equal stat.type, "M"
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
end
|
data/test/test_merge.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/helper'
|
2
|
+
require 'pp'
|
3
|
+
|
4
|
+
class TestMerge < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@r = Repo.new(File.join(File.dirname(__FILE__), *%w[dot_git]), :is_bare => true)
|
8
|
+
@merge = fixture('merge_result')
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_from_string
|
12
|
+
m = Grit::Merge.new(@merge)
|
13
|
+
assert_equal m.sections, 3
|
14
|
+
assert_equal m.conflicts, 1
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|