grit 1.1.1 → 2.0.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 +9 -0
- data/README.md +37 -11
- data/VERSION.yml +3 -3
- data/examples/ex_add_commit.rb +13 -0
- data/examples/ex_index.rb +14 -0
- data/lib/grit.rb +10 -3
- data/lib/grit/actor.rb +5 -5
- data/lib/grit/blob.rb +12 -12
- data/lib/grit/commit.rb +3 -3
- data/lib/grit/commit_stats.rb +26 -26
- data/lib/grit/config.rb +9 -9
- data/lib/grit/diff.rb +16 -16
- data/lib/grit/errors.rb +1 -1
- data/lib/grit/git-ruby.rb +108 -27
- data/lib/grit/git-ruby/commit_db.rb +11 -11
- data/lib/grit/git-ruby/file_index.rb +28 -28
- data/lib/grit/git-ruby/git_object.rb +14 -14
- data/lib/grit/git-ruby/internal/file_window.rb +4 -4
- data/lib/grit/git-ruby/internal/loose.rb +10 -10
- data/lib/grit/git-ruby/internal/pack.rb +29 -29
- data/lib/grit/git-ruby/internal/raw_object.rb +4 -4
- data/lib/grit/git-ruby/object.rb +9 -9
- data/lib/grit/git-ruby/repository.rb +111 -107
- data/lib/grit/git.rb +191 -14
- data/lib/grit/index.rb +21 -21
- data/lib/grit/lazy.rb +1 -1
- data/lib/grit/merge.rb +9 -9
- data/lib/grit/ref.rb +6 -31
- data/lib/grit/repo.rb +110 -65
- data/lib/grit/ruby1.9.rb +1 -1
- data/lib/grit/status.rb +24 -24
- data/lib/grit/submodule.rb +15 -15
- data/lib/grit/tag.rb +7 -57
- data/lib/grit/tree.rb +12 -12
- 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 +105 -0
- data/test/test_grit.rb +32 -0
- data/test/test_head.rb +47 -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 +349 -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 +67 -0
- data/test/test_tree.rb +101 -0
- metadata +43 -13
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,105 @@
|
|
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 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 [], @git.transform_options({:s => false})
|
33
|
+
assert_equal ["-s '5'"], @git.transform_options({:s => 5})
|
34
|
+
|
35
|
+
assert_equal ["--max-count"], @git.transform_options({:max_count => true})
|
36
|
+
assert_equal ["--max-count='5'"], @git.transform_options({:max_count => 5})
|
37
|
+
|
38
|
+
assert_equal ["-s", "-t"], @git.transform_options({:s => true, :t => true}).sort
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_uses_custom_sh_method
|
42
|
+
@git.expects(:sh)
|
43
|
+
@git.something
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_can_skip_timeout
|
47
|
+
@git.expects(:wild_sh)
|
48
|
+
@git.something(:timeout => false)
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_raises_if_too_many_bytes
|
52
|
+
@git.instance_variable_set(:@bytes_read, 6000000)
|
53
|
+
assert_raises Grit::Git::GitTimeout do
|
54
|
+
@git.version
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_raises_on_slow_shell
|
59
|
+
Grit::Git.git_timeout = 0.0000001
|
60
|
+
assert_raises Grit::Git::GitTimeout do
|
61
|
+
@git.version
|
62
|
+
end
|
63
|
+
Grit::Git.git_timeout = 5.0
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_it_really_shell_escapes_arguments_to_the_git_shell
|
67
|
+
@git.expects(:sh).with("#{Git.git_binary} --git-dir='#{@git.git_dir}' foo --bar='bazz\\'er'")
|
68
|
+
@git.foo(:bar => "bazz'er")
|
69
|
+
@git.expects(:sh).with("#{Git.git_binary} --git-dir='#{@git.git_dir}' bar -x 'quu\\'x'")
|
70
|
+
@git.bar(:x => "quu'x")
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_it_shell_escapes_the_standalone_argument
|
74
|
+
@git.expects(:sh).with("#{Git.git_binary} --git-dir='#{@git.git_dir}' foo 'bar\\'s'")
|
75
|
+
@git.foo({}, "bar's")
|
76
|
+
|
77
|
+
@git.expects(:sh).with("#{Git.git_binary} --git-dir='#{@git.git_dir}' foo 'bar' '\\; echo \\'noooo\\''")
|
78
|
+
@git.foo({}, "bar", "; echo 'noooo'")
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_piping_should_work_on_1_9
|
82
|
+
@git.expects(:sh).with("#{Git.git_binary} --git-dir='#{@git.git_dir}' archive 'master' | gzip")
|
83
|
+
@git.archive({}, "master", "| gzip")
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_fs_read
|
87
|
+
f = stub
|
88
|
+
f.expects(:read).returns('bar')
|
89
|
+
File.expects(:open).with(File.join(@git.git_dir, 'foo')).returns(f)
|
90
|
+
assert_equal 'bar', @git.fs_read('foo')
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_fs_write
|
94
|
+
f = stub
|
95
|
+
f.expects(:write).with('baz')
|
96
|
+
FileUtils.expects(:mkdir_p).with(File.join(@git.git_dir, 'foo'))
|
97
|
+
File.expects(:open).with(File.join(@git.git_dir, 'foo/bar'), 'w').yields(f)
|
98
|
+
@git.fs_write('foo/bar', 'baz')
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_fs_delete
|
102
|
+
FileUtils.expects(:rm_rf).with(File.join(@git.git_dir, 'foo'))
|
103
|
+
@git.fs_delete('foo')
|
104
|
+
end
|
105
|
+
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,47 @@
|
|
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
|
+
# inspect
|
9
|
+
|
10
|
+
def test_inspect
|
11
|
+
head = @r.heads[1]
|
12
|
+
assert_equal %Q{#<Grit::Head "test/master">}, head.inspect
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_master
|
16
|
+
head = @r.commit('master')
|
17
|
+
assert_equal 'ca8a30f5a7f0f163bbe3b6f0abf18a6c83b0687a', head.id
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_submaster
|
21
|
+
head = @r.commit('test/master')
|
22
|
+
assert_equal '2d3acf90f35989df8f262dc50beadc4ee3ae1560', head.id
|
23
|
+
end
|
24
|
+
|
25
|
+
# heads with slashes
|
26
|
+
|
27
|
+
def test_heads_with_slashes
|
28
|
+
head = @r.heads[3]
|
29
|
+
assert_equal %Q{#<Grit::Head "test/chacon">}, head.inspect
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_is_head
|
33
|
+
assert @r.is_head?('master')
|
34
|
+
assert @r.is_head?('test/chacon')
|
35
|
+
assert !@r.is_head?('masterblah')
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_head_count
|
39
|
+
assert_equal 5, @r.heads.size
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
def test_nonpack
|
44
|
+
assert @r.heads.map { |h| h.name }.include?('nonpack')
|
45
|
+
end
|
46
|
+
|
47
|
+
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
|
data/test/test_raw.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/helper'
|
2
|
+
require 'pp'
|
3
|
+
|
4
|
+
class TestFileIndex < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@r = Grit::Repo.new(File.join(File.dirname(__FILE__), *%w[dot_git]), :is_bare => true)
|
8
|
+
@tag = 'f0055fda16c18fd8b27986dbf038c735b82198d7'
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_raw_tag
|
12
|
+
tag = @r.git.ruby_git.get_object_by_sha1(@tag)
|
13
|
+
assert_match Regexp.new('v0.7.0'), tag.raw_content
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
data/test/test_real.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# require File.dirname(__FILE__) + '/helper'
|
2
|
+
#
|
3
|
+
# class TestReal < Test::Unit::TestCase
|
4
|
+
# def setup
|
5
|
+
# `rm -fr /Users/tom/dev/sandbox/grittest.git`
|
6
|
+
# `git --git-dir=/Users/tom/dev/sandbox/grittest.git init`
|
7
|
+
# @repo = Repo.new('/Users/tom/dev/sandbox/grittest.git')
|
8
|
+
# end
|
9
|
+
#
|
10
|
+
# def test_real
|
11
|
+
# Grit.debug = true
|
12
|
+
#
|
13
|
+
# index = @repo.index
|
14
|
+
# index.add('foo/bar/baz.txt', 'hello!')
|
15
|
+
# index.add('foo/qux/bam.txt', 'world!')
|
16
|
+
#
|
17
|
+
# puts index.commit('first commit')
|
18
|
+
# end
|
19
|
+
# 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_remote.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/helper'
|
2
|
+
|
3
|
+
class TestRemote < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@r = Repo.new(GRIT_REPO)
|
6
|
+
end
|
7
|
+
|
8
|
+
# inspect
|
9
|
+
|
10
|
+
def test_inspect
|
11
|
+
remote = @r.remotes.first
|
12
|
+
assert_equal %Q{#<Grit::Remote "#{remote.name}">}, remote.inspect
|
13
|
+
end
|
14
|
+
end
|
data/test/test_repo.rb
ADDED
@@ -0,0 +1,349 @@
|
|
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
|
+
def create_temp_repo(clone_path)
|
9
|
+
filename = 'git_test' + Time.now.to_i.to_s + rand(300).to_s.rjust(3, '0')
|
10
|
+
tmp_path = File.join("/tmp/", filename)
|
11
|
+
FileUtils.mkdir_p(tmp_path)
|
12
|
+
FileUtils.cp_r(clone_path, tmp_path)
|
13
|
+
File.join(tmp_path, 'dot_git')
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_update_refs_packed
|
17
|
+
gpath = create_temp_repo(File.join(File.dirname(__FILE__), *%w[dot_git]))
|
18
|
+
@git = Grit::Repo.new(gpath, :is_bare => true)
|
19
|
+
|
20
|
+
# new and existing
|
21
|
+
test = 'ac9a30f5a7f0f163bbe3b6f0abf18a6c83b06872'
|
22
|
+
master = 'ca8a30f5a7f0f163bbe3b6f0abf18a6c83b0687a'
|
23
|
+
|
24
|
+
@git.update_ref('testref', test)
|
25
|
+
new_t = @git.get_head('testref').commit.sha
|
26
|
+
assert new_t != master
|
27
|
+
|
28
|
+
@git.update_ref('master', test)
|
29
|
+
new_m = @git.get_head('master').commit.sha
|
30
|
+
assert new_m != master
|
31
|
+
|
32
|
+
old = @git.get_head('nonpack').commit.sha
|
33
|
+
@git.update_ref('nonpack', test)
|
34
|
+
newp = @git.get_head('nonpack').commit.sha
|
35
|
+
assert newp != old
|
36
|
+
|
37
|
+
FileUtils.rm_r(gpath)
|
38
|
+
end
|
39
|
+
|
40
|
+
# new
|
41
|
+
|
42
|
+
def test_new_should_raise_on_invalid_repo_location
|
43
|
+
assert_raise(InvalidGitRepositoryError) do
|
44
|
+
Repo.new("/tmp")
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_new_should_raise_on_non_existant_path
|
49
|
+
assert_raise(NoSuchPathError) do
|
50
|
+
Repo.new("/foobar")
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
# descriptions
|
55
|
+
|
56
|
+
def test_description
|
57
|
+
assert_equal "Unnamed repository; edit this file to name it for gitweb.", @r.description
|
58
|
+
end
|
59
|
+
|
60
|
+
# refs
|
61
|
+
|
62
|
+
def test_refs_should_return_array_of_ref_objects
|
63
|
+
@r.refs.each do |ref|
|
64
|
+
assert ref.is_a?(Grit::Ref)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
# heads
|
69
|
+
|
70
|
+
def test_current_head
|
71
|
+
@r = Repo.new(File.join(File.dirname(__FILE__), *%w[dot_git]), :is_bare => true)
|
72
|
+
head = @r.head
|
73
|
+
assert_equal Grit::Head, head.class
|
74
|
+
assert_equal 'master', head.name
|
75
|
+
assert_equal 'ca8a30f5a7f0f163bbe3b6f0abf18a6c83b0687a', @r.commits(head.name).first.id
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_heads_should_return_array_of_head_objects
|
79
|
+
@r.heads.each do |head|
|
80
|
+
assert_equal Grit::Head, head.class
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_heads_should_populate_head_data
|
85
|
+
@r = Repo.new(File.join(File.dirname(__FILE__), *%w[dot_git]), :is_bare => true)
|
86
|
+
head = @r.heads[1]
|
87
|
+
|
88
|
+
assert_equal 'test/master', head.name
|
89
|
+
assert_equal '2d3acf90f35989df8f262dc50beadc4ee3ae1560', head.commit.id
|
90
|
+
end
|
91
|
+
|
92
|
+
# branches
|
93
|
+
|
94
|
+
def test_branches
|
95
|
+
# same as heads
|
96
|
+
end
|
97
|
+
|
98
|
+
# commits
|
99
|
+
|
100
|
+
def test_commits
|
101
|
+
Git.any_instance.expects(:rev_list).returns(fixture('rev_list'))
|
102
|
+
|
103
|
+
commits = @r.commits('master', 10)
|
104
|
+
|
105
|
+
c = commits[0]
|
106
|
+
assert_equal '4c8124ffcf4039d292442eeccabdeca5af5c5017', c.id
|
107
|
+
assert_equal ["634396b2f541a9f2d58b00be1a07f0c358b999b3"], c.parents.map { |p| p.id }
|
108
|
+
assert_equal "672eca9b7f9e09c22dcb128c283e8c3c8d7697a4", c.tree.id
|
109
|
+
assert_equal "Tom Preston-Werner", c.author.name
|
110
|
+
assert_equal "tom@mojombo.com", c.author.email
|
111
|
+
assert_equal Time.at(1191999972), c.authored_date
|
112
|
+
assert_equal "Tom Preston-Werner", c.committer.name
|
113
|
+
assert_equal "tom@mojombo.com", c.committer.email
|
114
|
+
assert_equal Time.at(1191999972), c.committed_date
|
115
|
+
assert_equal "implement Grit#heads", c.message
|
116
|
+
|
117
|
+
c = commits[1]
|
118
|
+
assert_equal [], c.parents
|
119
|
+
|
120
|
+
c = commits[2]
|
121
|
+
assert_equal ["6e64c55896aabb9a7d8e9f8f296f426d21a78c2c", "7f874954efb9ba35210445be456c74e037ba6af2"], c.parents.map { |p| p.id }
|
122
|
+
assert_equal "Merge branch 'site'\n\n * Some other stuff\n * just one more", c.message
|
123
|
+
assert_equal "Merge branch 'site'", c.short_message
|
124
|
+
end
|
125
|
+
|
126
|
+
# commit_count
|
127
|
+
|
128
|
+
def test_commit_count
|
129
|
+
Git.any_instance.expects(:rev_list).with({}, 'master').returns(fixture('rev_list_count'))
|
130
|
+
|
131
|
+
assert_equal 655, @r.commit_count('master')
|
132
|
+
end
|
133
|
+
|
134
|
+
# commit
|
135
|
+
|
136
|
+
def test_commit
|
137
|
+
commit = @r.commit('634396b2f541a9f2d58b00be1a07f0c358b999b3')
|
138
|
+
|
139
|
+
assert_equal "634396b2f541a9f2d58b00be1a07f0c358b999b3", commit.id
|
140
|
+
end
|
141
|
+
|
142
|
+
# tree
|
143
|
+
|
144
|
+
def test_tree
|
145
|
+
Git.any_instance.expects(:ls_tree).returns(fixture('ls_tree_a'))
|
146
|
+
tree = @r.tree('master')
|
147
|
+
|
148
|
+
assert_equal 4, tree.contents.select { |c| c.instance_of?(Blob) }.size
|
149
|
+
assert_equal 3, tree.contents.select { |c| c.instance_of?(Tree) }.size
|
150
|
+
end
|
151
|
+
|
152
|
+
# blob
|
153
|
+
|
154
|
+
def test_blob
|
155
|
+
Git.any_instance.expects(:cat_file).returns(fixture('cat_file_blob'))
|
156
|
+
blob = @r.blob("abc")
|
157
|
+
assert_equal "Hello world", blob.data
|
158
|
+
end
|
159
|
+
|
160
|
+
# init_bare
|
161
|
+
|
162
|
+
def test_init_bare
|
163
|
+
Git.any_instance.expects(:init).returns(true)
|
164
|
+
Repo.expects(:new).with("/foo/bar.git", {})
|
165
|
+
Repo.init_bare("/foo/bar.git")
|
166
|
+
end
|
167
|
+
|
168
|
+
def test_init_bare_with_options
|
169
|
+
Git.any_instance.expects(:init).with(
|
170
|
+
:bare => true, :template => "/baz/sweet").returns(true)
|
171
|
+
Repo.expects(:new).with("/foo/bar.git", {})
|
172
|
+
Repo.init_bare("/foo/bar.git", :template => "/baz/sweet")
|
173
|
+
end
|
174
|
+
|
175
|
+
# fork_bare
|
176
|
+
|
177
|
+
def test_fork_bare
|
178
|
+
Git.any_instance.expects(:clone).with(
|
179
|
+
{:bare => true, :shared => true},
|
180
|
+
"#{absolute_project_path}/.git",
|
181
|
+
"/foo/bar.git").returns(nil)
|
182
|
+
Repo.expects(:new)
|
183
|
+
|
184
|
+
@r.fork_bare("/foo/bar.git")
|
185
|
+
end
|
186
|
+
|
187
|
+
def test_fork_bare_with_options
|
188
|
+
Git.any_instance.expects(:clone).with(
|
189
|
+
{:bare => true, :shared => true, :template => '/awesome'},
|
190
|
+
"#{absolute_project_path}/.git",
|
191
|
+
"/foo/bar.git").returns(nil)
|
192
|
+
Repo.expects(:new)
|
193
|
+
|
194
|
+
@r.fork_bare("/foo/bar.git", :template => '/awesome')
|
195
|
+
end
|
196
|
+
|
197
|
+
# diff
|
198
|
+
|
199
|
+
def test_diff
|
200
|
+
Git.any_instance.expects(:diff).with({}, 'master^', 'master', '--')
|
201
|
+
@r.diff('master^', 'master')
|
202
|
+
|
203
|
+
Git.any_instance.expects(:diff).with({}, 'master^', 'master', '--', 'foo/bar')
|
204
|
+
@r.diff('master^', 'master', 'foo/bar')
|
205
|
+
|
206
|
+
Git.any_instance.expects(:diff).with({}, 'master^', 'master', '--', 'foo/bar', 'foo/baz')
|
207
|
+
@r.diff('master^', 'master', 'foo/bar', 'foo/baz')
|
208
|
+
end
|
209
|
+
|
210
|
+
# commit_diff
|
211
|
+
|
212
|
+
def test_diff
|
213
|
+
Git.any_instance.expects(:diff).returns(fixture('diff_p'))
|
214
|
+
diffs = @r.commit_diff('master')
|
215
|
+
|
216
|
+
assert_equal 15, diffs.size
|
217
|
+
end
|
218
|
+
|
219
|
+
# init bare
|
220
|
+
|
221
|
+
# archive
|
222
|
+
|
223
|
+
def test_archive_tar
|
224
|
+
#@r.archive_tar -- no assertion being done here
|
225
|
+
end
|
226
|
+
|
227
|
+
# archive_tar_gz
|
228
|
+
|
229
|
+
def test_archive_tar_gz
|
230
|
+
#@r.archive_tar_gz -- again, no assertion
|
231
|
+
end
|
232
|
+
|
233
|
+
# enable_daemon_serve
|
234
|
+
|
235
|
+
def test_enable_daemon_serve
|
236
|
+
f = stub
|
237
|
+
f.expects("write").with('')
|
238
|
+
File.expects(:open).with(File.join(@r.path, 'git-daemon-export-ok'), 'w').yields(f)
|
239
|
+
@r.enable_daemon_serve
|
240
|
+
end
|
241
|
+
|
242
|
+
# disable_daemon_serve
|
243
|
+
|
244
|
+
def test_disable_daemon_serve
|
245
|
+
FileUtils.expects(:rm_rf).with(File.join(@r.path, 'git-daemon-export-ok'))
|
246
|
+
@r.disable_daemon_serve
|
247
|
+
end
|
248
|
+
|
249
|
+
def test_gc_auto
|
250
|
+
Git.any_instance.expects(:gc).with({:auto => true})
|
251
|
+
@r.gc_auto
|
252
|
+
end
|
253
|
+
|
254
|
+
# alternates
|
255
|
+
|
256
|
+
def test_alternates_with_two_alternates
|
257
|
+
File.expects(:exist?).with("#{absolute_project_path}/.git/objects/info/alternates").returns(true)
|
258
|
+
File.any_instance.expects(:read).returns("/path/to/repo1/.git/objects\n/path/to/repo2.git/objects\n")
|
259
|
+
|
260
|
+
assert_equal ["/path/to/repo1/.git/objects", "/path/to/repo2.git/objects"], @r.alternates
|
261
|
+
end
|
262
|
+
|
263
|
+
def test_alternates_no_file
|
264
|
+
File.expects(:exist?).returns(false)
|
265
|
+
|
266
|
+
assert_equal [], @r.alternates
|
267
|
+
end
|
268
|
+
|
269
|
+
# alternates=
|
270
|
+
|
271
|
+
def test_alternates_setter_ok
|
272
|
+
alts = %w{/path/to/repo.git/objects /path/to/repo2.git/objects}
|
273
|
+
|
274
|
+
alts.each do |alt|
|
275
|
+
File.expects(:exist?).with(alt).returns(true)
|
276
|
+
end
|
277
|
+
|
278
|
+
File.any_instance.expects(:write).with(alts.join("\n"))
|
279
|
+
|
280
|
+
assert_nothing_raised do
|
281
|
+
@r.alternates = alts
|
282
|
+
end
|
283
|
+
end
|
284
|
+
|
285
|
+
def test_alternates_setter_bad
|
286
|
+
alts = %w{/path/to/repo.git/objects}
|
287
|
+
|
288
|
+
alts.each do |alt|
|
289
|
+
File.expects(:exist?).with(alt).returns(false)
|
290
|
+
end
|
291
|
+
|
292
|
+
File.any_instance.expects(:write).never
|
293
|
+
|
294
|
+
assert_raise RuntimeError do
|
295
|
+
@r.alternates = alts
|
296
|
+
end
|
297
|
+
end
|
298
|
+
|
299
|
+
def test_alternates_setter_empty
|
300
|
+
File.any_instance.expects(:write)
|
301
|
+
@r.alternates = []
|
302
|
+
end
|
303
|
+
|
304
|
+
# inspect
|
305
|
+
|
306
|
+
def test_inspect
|
307
|
+
assert_equal %Q{#<Grit::Repo "#{File.expand_path(GRIT_REPO)}/.git">}, @r.inspect
|
308
|
+
end
|
309
|
+
|
310
|
+
# log
|
311
|
+
|
312
|
+
def test_log
|
313
|
+
Git.any_instance.expects(:log).times(2).with({:pretty => 'raw'}, 'master').returns(fixture('rev_list'))
|
314
|
+
|
315
|
+
assert_equal '4c8124ffcf4039d292442eeccabdeca5af5c5017', @r.log.first.id
|
316
|
+
assert_equal 'ab25fd8483882c3bda8a458ad2965d2248654335', @r.log.last.id
|
317
|
+
end
|
318
|
+
|
319
|
+
def test_log_with_path_and_options
|
320
|
+
Git.any_instance.expects(:log).with({:pretty => 'raw', :max_count => 1}, 'master', '--', 'file.rb').returns(fixture('rev_list'))
|
321
|
+
@r.log('master', 'file.rb', :max_count => 1)
|
322
|
+
end
|
323
|
+
|
324
|
+
# commit_deltas_from
|
325
|
+
|
326
|
+
def test_commit_deltas_from_nothing_new
|
327
|
+
other_repo = Repo.new(GRIT_REPO)
|
328
|
+
@r.git.expects(:rev_list).with({}, "master").returns(fixture("rev_list_delta_b"))
|
329
|
+
other_repo.git.expects(:rev_list).with({}, "master").returns(fixture("rev_list_delta_a"))
|
330
|
+
|
331
|
+
delta_blobs = @r.commit_deltas_from(other_repo)
|
332
|
+
assert_equal 0, delta_blobs.size
|
333
|
+
end
|
334
|
+
|
335
|
+
def test_commit_deltas_from_when_other_has_new
|
336
|
+
other_repo = Repo.new(GRIT_REPO)
|
337
|
+
@r.git.expects(:rev_list).with({}, "master").returns(fixture("rev_list_delta_a"))
|
338
|
+
other_repo.git.expects(:rev_list).with({}, "master").returns(fixture("rev_list_delta_b"))
|
339
|
+
%w[
|
340
|
+
4c8124ffcf4039d292442eeccabdeca5af5c5017
|
341
|
+
634396b2f541a9f2d58b00be1a07f0c358b999b3
|
342
|
+
ab25fd8483882c3bda8a458ad2965d2248654335
|
343
|
+
].each do |ref|
|
344
|
+
Commit.expects(:find_all).with(other_repo, ref, :max_count => 1).returns([stub()])
|
345
|
+
end
|
346
|
+
delta_blobs = @r.commit_deltas_from(other_repo)
|
347
|
+
assert_equal 3, delta_blobs.size
|
348
|
+
end
|
349
|
+
end
|