boof-grit 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. data/API.txt +101 -0
  2. data/History.txt +53 -0
  3. data/LICENSE +22 -0
  4. data/README.md +210 -0
  5. data/VERSION.yml +4 -0
  6. data/examples/ex_add_commit.rb +13 -0
  7. data/examples/ex_index.rb +14 -0
  8. data/lib/grit.rb +68 -0
  9. data/lib/grit/actor.rb +36 -0
  10. data/lib/grit/blame.rb +61 -0
  11. data/lib/grit/blob.rb +126 -0
  12. data/lib/grit/commit.rb +246 -0
  13. data/lib/grit/commit_stats.rb +128 -0
  14. data/lib/grit/config.rb +44 -0
  15. data/lib/grit/diff.rb +70 -0
  16. data/lib/grit/errors.rb +7 -0
  17. data/lib/grit/git-ruby.rb +186 -0
  18. data/lib/grit/git-ruby/commit_db.rb +52 -0
  19. data/lib/grit/git-ruby/file_index.rb +193 -0
  20. data/lib/grit/git-ruby/git_object.rb +350 -0
  21. data/lib/grit/git-ruby/internal/file_window.rb +58 -0
  22. data/lib/grit/git-ruby/internal/loose.rb +137 -0
  23. data/lib/grit/git-ruby/internal/pack.rb +382 -0
  24. data/lib/grit/git-ruby/internal/raw_object.rb +37 -0
  25. data/lib/grit/git-ruby/object.rb +325 -0
  26. data/lib/grit/git-ruby/repository.rb +740 -0
  27. data/lib/grit/git.rb +141 -0
  28. data/lib/grit/index.rb +122 -0
  29. data/lib/grit/lazy.rb +33 -0
  30. data/lib/grit/merge.rb +45 -0
  31. data/lib/grit/ref.rb +177 -0
  32. data/lib/grit/repo.rb +452 -0
  33. data/lib/grit/ruby1.9.rb +7 -0
  34. data/lib/grit/status.rb +151 -0
  35. data/lib/grit/submodule.rb +88 -0
  36. data/lib/grit/tag.rb +66 -0
  37. data/lib/grit/tree.rb +123 -0
  38. data/lib/open3_detach.rb +46 -0
  39. data/test/bench/benchmarks.rb +126 -0
  40. data/test/helper.rb +18 -0
  41. data/test/profile.rb +21 -0
  42. data/test/suite.rb +6 -0
  43. data/test/test_actor.rb +35 -0
  44. data/test/test_blame.rb +32 -0
  45. data/test/test_blame_tree.rb +33 -0
  46. data/test/test_blob.rb +83 -0
  47. data/test/test_commit.rb +207 -0
  48. data/test/test_commit_stats.rb +33 -0
  49. data/test/test_commit_write.rb +20 -0
  50. data/test/test_config.rb +58 -0
  51. data/test/test_diff.rb +18 -0
  52. data/test/test_file_index.rb +56 -0
  53. data/test/test_git.rb +94 -0
  54. data/test/test_grit.rb +32 -0
  55. data/test/test_head.rb +72 -0
  56. data/test/test_index_status.rb +40 -0
  57. data/test/test_merge.rb +17 -0
  58. data/test/test_raw.rb +16 -0
  59. data/test/test_real.rb +19 -0
  60. data/test/test_reality.rb +17 -0
  61. data/test/test_remote.rb +14 -0
  62. data/test/test_repo.rb +381 -0
  63. data/test/test_rubygit.rb +192 -0
  64. data/test/test_rubygit_alt.rb +40 -0
  65. data/test/test_rubygit_index.rb +76 -0
  66. data/test/test_rubygit_iv2.rb +28 -0
  67. data/test/test_submodule.rb +69 -0
  68. data/test/test_tag.rb +103 -0
  69. data/test/test_tree.rb +101 -0
  70. metadata +143 -0
@@ -0,0 +1,126 @@
1
+ require 'fileutils'
2
+ require 'benchmark'
3
+ require 'rubygems'
4
+ require 'ruby-prof'
5
+ require 'memcache'
6
+ require 'pp'
7
+
8
+ gem 'grit', '=0.7.0'
9
+ #require '../../lib/grit'
10
+
11
+ def main
12
+ @wbare = File.expand_path(File.join('../../', 'test', 'dot_git'))
13
+
14
+ in_temp_dir do
15
+ #result = RubyProf.profile do
16
+
17
+ git = Grit::Repo.new('.')
18
+ puts Grit::VERSION
19
+ #Grit::GitRuby.cache_client = MemCache.new 'localhost:11211', :namespace => 'grit'
20
+ #Grit.debug = true
21
+
22
+ #pp Grit::GitRuby.cache_client.stats
23
+
24
+ commit1 = '5e3ee1198672257164ce3fe31dea3e40848e68d5'
25
+ commit2 = 'ca8a30f5a7f0f163bbe3b6f0abf18a6c83b0687a'
26
+
27
+ Benchmark.bm(8) do |x|
28
+
29
+ run_code(x, 'packobj') do
30
+ @commit = git.commit('5e3ee1198672257164ce3fe31dea3e40848e68d5')
31
+ @tree = git.tree('cd7422af5a2e0fff3e94d6fb1a8fff03b2841881')
32
+ @blob = git.blob('4232d073306f01cf0b895864e5a5cfad7dd76fce')
33
+ @commit.parents[0].parents[0].parents[0]
34
+ end
35
+
36
+ run_code(x, 'commits 1') do
37
+ git.commits.size
38
+ end
39
+
40
+ run_code(x, 'commits 2') do
41
+ log = git.commits('master', 15)
42
+ log.size
43
+ log.size
44
+ log.first
45
+ git.commits('testing').map { |c| c.message }
46
+ end
47
+
48
+ run_code(x, 'big revlist') do
49
+ c = git.commits('master', 200)
50
+ end
51
+
52
+ run_code(x, 'log') do
53
+ log = git.log('master')
54
+ log.size
55
+ log.size
56
+ log.first
57
+ end
58
+
59
+ run_code(x, 'diff') do
60
+ c = git.diff(commit1, commit2)
61
+ end
62
+
63
+ run_code(x, 'commit-diff') do
64
+ c = git.commit_diff(commit1)
65
+ end
66
+
67
+ run_code(x, 'heads') do
68
+ c = git.heads.collect { |b| b.commit.id }
69
+ end
70
+
71
+ # run_code(x, 'config', 100) do
72
+ # c = git.config['user.name']
73
+ # c = git.config['user.email']
74
+ # end
75
+
76
+ #run_code(x, 'commit count') do
77
+ # c = git.commit_count('testing')
78
+ #end
79
+
80
+
81
+ end
82
+ #end
83
+
84
+ #printer = RubyProf::FlatPrinter.new(result)
85
+ #printer.print(STDOUT, 0)
86
+
87
+ end
88
+
89
+
90
+ end
91
+
92
+
93
+ def run_code(x, name, times = 30)
94
+ x.report(name.ljust(12)) do
95
+ for i in 1..times do
96
+ yield i
97
+ end
98
+ end
99
+
100
+ #end
101
+
102
+ # Print a graph profile to text
103
+ end
104
+
105
+ def new_file(name, contents)
106
+ File.open(name, 'w') do |f|
107
+ f.puts contents
108
+ end
109
+ end
110
+
111
+
112
+ def in_temp_dir(remove_after = true)
113
+ filename = 'git_test' + Time.now.to_i.to_s + rand(300).to_s.rjust(3, '0')
114
+ tmp_path = File.join("/tmp/", filename)
115
+ FileUtils.mkdir(tmp_path)
116
+ Dir.chdir tmp_path do
117
+ FileUtils.cp_r(@wbare, File.join(tmp_path, '.git'))
118
+ yield tmp_path
119
+ end
120
+ puts tmp_path
121
+ #FileUtils.rm_r(tmp_path) if remove_after
122
+ end
123
+
124
+ main()
125
+
126
+ ##pp Grit::GitRuby.cache_client.stats
data/test/helper.rb ADDED
@@ -0,0 +1,18 @@
1
+ require File.join(File.dirname(__FILE__), *%w[.. lib grit])
2
+
3
+ require 'rubygems'
4
+ require 'test/unit'
5
+ gem "mocha", ">=0"
6
+ require 'mocha'
7
+
8
+ GRIT_REPO = File.join(File.dirname(__FILE__), *%w[..])
9
+
10
+ include Grit
11
+
12
+ def fixture(name)
13
+ File.read(File.join(File.dirname(__FILE__), 'fixtures', name))
14
+ end
15
+
16
+ def absolute_project_path
17
+ File.expand_path(File.join(File.dirname(__FILE__), '..'))
18
+ 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/schacon/projects/ambition")
16
+ t = r.tree
17
+
18
+ recurse(t)
19
+ end
20
+
21
+ #500.times { puts `git --git-dir /Users/schacon/projects/ambition/.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
@@ -0,0 +1,32 @@
1
+ require File.dirname(__FILE__) + '/helper'
2
+ require 'pp'
3
+
4
+ class TestBlame < Test::Unit::TestCase
5
+
6
+ def setup
7
+ @r = Repo.new(File.join(File.dirname(__FILE__), *%w[dot_git]), :is_bare => true)
8
+ end
9
+
10
+ def test_simple_blame
11
+ commit = '2d3acf90f35989df8f262dc50beadc4ee3ae1560'
12
+ blame = @r.blame('History.txt', commit)
13
+ assert_equal 5, blame.lines.size
14
+ line = blame.lines[2]
15
+ assert_equal '* 1 major enhancement', line.line
16
+ assert_equal 3, line.lineno
17
+ assert_equal 3, line.oldlineno
18
+ assert_equal '634396b2f541a9f2d58b00be1a07f0c358b999b3', line.commit.id
19
+ end
20
+
21
+ def test_depth_blame
22
+ commit = '2d3acf90f35989df8f262dc50beadc4ee3ae1560'
23
+ blame = @r.blame('lib/grit.rb', commit)
24
+ assert_equal 37, blame.lines.size
25
+ line = blame.lines[24]
26
+ assert_equal "require 'grit/diff'", line.line
27
+ assert_equal 25, line.lineno
28
+ assert_equal 16, line.oldlineno
29
+ assert_equal '46291865ba0f6e0c9818b11be799fe2db6964d56', line.commit.id
30
+ end
31
+
32
+ end
@@ -0,0 +1,33 @@
1
+ require File.dirname(__FILE__) + '/helper'
2
+ require 'pp'
3
+
4
+ class TestBlameTree < Test::Unit::TestCase
5
+
6
+ def setup
7
+ @git = Git.new(File.join(File.dirname(__FILE__), *%w[dot_git]))
8
+ end
9
+
10
+ def test_blame_tree
11
+ commit = '2d3acf90f35989df8f262dc50beadc4ee3ae1560'
12
+ tree = @git.blame_tree(commit)
13
+ last_commit_sha = tree['History.txt']
14
+ assert_equal last_commit_sha, '7bcc0ee821cdd133d8a53e8e7173a334fef448aa'
15
+ end
16
+
17
+ def test_blame_tree_path
18
+ commit = '2d3acf90f35989df8f262dc50beadc4ee3ae1560'
19
+ tree = @git.blame_tree(commit, 'lib')
20
+ last_commit_sha = tree['lib/grit.rb']
21
+ assert_equal last_commit_sha, '5a0943123f6872e75a9b1dd0b6519dd42a186fda'
22
+ last_commit_sha = tree['lib/grit']
23
+ assert_equal last_commit_sha, '2d3acf90f35989df8f262dc50beadc4ee3ae1560'
24
+ end
25
+
26
+ def test_blame_tree_multi_path
27
+ commit = '2d3acf90f35989df8f262dc50beadc4ee3ae1560'
28
+ tree = @git.blame_tree(commit, 'lib/grit')
29
+ last_commit_sha = tree['lib/grit/diff.rb']
30
+ assert_equal last_commit_sha, '22825175e37f22c9418d756ca69b574d75602994'
31
+ end
32
+
33
+ end
data/test/test_blob.rb ADDED
@@ -0,0 +1,83 @@
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
+ def test_nosuch_blob
11
+ t = @r.blob('blahblah')
12
+ assert t.is_a?(Blob)
13
+ end
14
+
15
+ def test_data_should_return_blob_contents
16
+ Git.any_instance.expects(:cat_file).returns(fixture('cat_file_blob'))
17
+ blob = Blob.create(@r, :id => 'abc')
18
+ assert_equal "Hello world", blob.data
19
+ end
20
+
21
+ def test_data_should_cache
22
+ Git.any_instance.expects(:cat_file).returns(fixture('cat_file_blob')).times(1)
23
+ blob = Blob.create(@r, :id => 'abc')
24
+ blob.data
25
+ blob.data
26
+ end
27
+
28
+ # size
29
+
30
+ def test_size_should_return_file_size
31
+ Git.any_instance.expects(:cat_file).returns(fixture('cat_file_blob_size'))
32
+ blob = Blob.create(@r, :id => 'abc')
33
+ assert_equal 11, blob.size
34
+ end
35
+
36
+ # data
37
+
38
+ # mime_type
39
+
40
+ def test_mime_type_should_return_mime_type_for_known_types
41
+ blob = Blob.create(@r, :id => 'abc', :name => 'foo.png')
42
+ assert_equal "image/png", blob.mime_type
43
+ end
44
+
45
+ def test_mime_type_should_return_text_plain_for_unknown_types
46
+ blob = Blob.create(@r, :id => 'abc')
47
+ assert_equal "text/plain", blob.mime_type
48
+ end
49
+
50
+ # blame
51
+
52
+ def test_blame
53
+ Git.any_instance.expects(:blame).returns(fixture('blame'))
54
+ b = Blob.blame(@r, 'master', 'lib/grit.rb')
55
+ assert_equal 13, b.size
56
+ assert_equal 25, b.inject(0) { |acc, x| acc + x.last.size }
57
+ assert_equal b[0].first.object_id, b[9].first.object_id
58
+ c = b.first.first
59
+ c.expects(:__bake__).times(0)
60
+ assert_equal '634396b2f541a9f2d58b00be1a07f0c358b999b3', c.id
61
+ assert_equal 'Tom Preston-Werner', c.author.name
62
+ assert_equal 'tom@mojombo.com', c.author.email
63
+ assert_equal Time.at(1191997100), c.authored_date
64
+ assert_equal 'Tom Preston-Werner', c.committer.name
65
+ assert_equal 'tom@mojombo.com', c.committer.email
66
+ assert_equal Time.at(1191997100), c.committed_date
67
+ assert_equal 'initial grit setup', c.message
68
+ # c.expects(:__bake__).times(1)
69
+ # assert_equal Tree, c.tree.class
70
+ end
71
+
72
+ # inspect
73
+
74
+ def test_inspect
75
+ @b = Blob.create(@r, :id => 'abc')
76
+ assert_equal %Q{#<Grit::Blob "abc">}, @b.inspect
77
+ end
78
+
79
+ def test_basename
80
+ @b = Blob.create(@r, :name => 'foo/bar.rb')
81
+ assert_equal "bar.rb", @b.basename
82
+ end
83
+ end
@@ -0,0 +1,207 @@
1
+ require File.dirname(__FILE__) + '/helper'
2
+
3
+ class TestCommit < 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
+ # __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
+ assert_equal '80f136f', @r.commit('80f136f500dfdb8c3e8abf4ae716f875f0a1b57f').id_abbrev
23
+ end
24
+
25
+ # count
26
+
27
+ def test_count
28
+ assert_equal 107, Commit.count(@r, 'master')
29
+ end
30
+
31
+ # diff
32
+
33
+ def test_diff
34
+ # git diff --full-index 91169e1f5fa4de2eaea3f176461f5dc784796769 > test/fixtures/diff_p
35
+
36
+ Git.any_instance.expects(:diff).with({:full_index => true}, 'master').returns(fixture('diff_p'))
37
+ diffs = Commit.diff(@r, 'master')
38
+
39
+ assert_equal 15, diffs.size
40
+
41
+ assert_equal '.gitignore', diffs.first.a_path
42
+ assert_equal '.gitignore', diffs.first.b_path
43
+ assert_equal '4ebc8aea50e0a67e000ba29a30809d0a7b9b2666', diffs.first.a_blob.id
44
+ assert_equal '2dd02534615434d88c51307beb0f0092f21fd103', diffs.first.b_blob.id
45
+ assert_equal '100644', diffs.first.b_mode
46
+ assert_equal false, diffs.first.new_file
47
+ assert_equal false, diffs.first.deleted_file
48
+ assert_equal "--- a/.gitignore\n+++ b/.gitignore\n@@ -1 +1,2 @@\n coverage\n+pkg", diffs.first.diff
49
+
50
+ assert_equal 'lib/grit/actor.rb', diffs[5].a_path
51
+ assert_equal nil, diffs[5].a_blob
52
+ assert_equal 'f733bce6b57c0e5e353206e692b0e3105c2527f4', diffs[5].b_blob.id
53
+ assert_equal true, diffs[5].new_file
54
+ end
55
+
56
+ def test_diff_with_two_commits
57
+ # git diff --full-index 59ddc32 13d27d5 > test/fixtures/diff_2
58
+ Git.any_instance.expects(:diff).with({:full_index => true}, '59ddc32', '13d27d5').returns(fixture('diff_2'))
59
+ diffs = Commit.diff(@r, '59ddc32', '13d27d5')
60
+
61
+ assert_equal 3, diffs.size
62
+ assert_equal %w(lib/grit/commit.rb test/fixtures/show_empty_commit test/test_commit.rb), diffs.collect { |d| d.a_path }
63
+ end
64
+
65
+ def test_diff_with_files
66
+ # git diff --full-index 59ddc32 -- lib > test/fixtures/diff_f
67
+ Git.any_instance.expects(:diff).with({:full_index => true}, '59ddc32', '--', 'lib').returns(fixture('diff_f'))
68
+ diffs = Commit.diff(@r, '59ddc32', %w(lib))
69
+
70
+ assert_equal 1, diffs.size
71
+ assert_equal 'lib/grit/diff.rb', diffs.first.a_path
72
+ end
73
+
74
+ def test_diff_with_two_commits_and_files
75
+ # git diff --full-index 59ddc32 13d27d5 -- lib > test/fixtures/diff_2f
76
+ Git.any_instance.expects(:diff).with({:full_index => true}, '59ddc32', '13d27d5', '--', 'lib').returns(fixture('diff_2f'))
77
+ diffs = Commit.diff(@r, '59ddc32', '13d27d5', %w(lib))
78
+
79
+ assert_equal 1, diffs.size
80
+ assert_equal 'lib/grit/commit.rb', diffs.first.a_path
81
+ end
82
+
83
+ # diffs
84
+ def test_diffs
85
+ # git diff --full-index 91169e1f5fa4de2eaea3f176461f5dc784796769 > test/fixtures/diff_p
86
+
87
+ Git.any_instance.expects(:diff).returns(fixture('diff_p'))
88
+ @c = Commit.create(@r, :id => '91169e1f5fa4de2eaea3f176461f5dc784796769')
89
+ diffs = @c.diffs
90
+
91
+ assert_equal 15, diffs.size
92
+
93
+ assert_equal '.gitignore', diffs.first.a_path
94
+ assert_equal '.gitignore', diffs.first.b_path
95
+ assert_equal '4ebc8aea50e0a67e000ba29a30809d0a7b9b2666', diffs.first.a_blob.id
96
+ assert_equal '2dd02534615434d88c51307beb0f0092f21fd103', diffs.first.b_blob.id
97
+ assert_equal '100644', diffs.first.b_mode
98
+ assert_equal false, diffs.first.new_file
99
+ assert_equal false, diffs.first.deleted_file
100
+ assert_equal "--- a/.gitignore\n+++ b/.gitignore\n@@ -1 +1,2 @@\n coverage\n+pkg", diffs.first.diff
101
+
102
+ assert_equal 'lib/grit/actor.rb', diffs[5].a_path
103
+ assert_equal nil, diffs[5].a_blob
104
+ assert_equal 'f733bce6b57c0e5e353206e692b0e3105c2527f4', diffs[5].b_blob.id
105
+ assert_equal true, diffs[5].new_file
106
+ end
107
+
108
+ def test_diffs_on_initial_import
109
+ # git show --full-index 634396b2f541a9f2d58b00be1a07f0c358b999b3 > test/fixtures/diff_i
110
+
111
+ Git.any_instance.expects(:show).with({:full_index => true, :pretty => 'raw'}, '634396b2f541a9f2d58b00be1a07f0c358b999b3').returns(fixture('diff_i'))
112
+ @c = Commit.create(@r, :id => '634396b2f541a9f2d58b00be1a07f0c358b999b3')
113
+ diffs = @c.diffs
114
+
115
+ assert_equal 10, diffs.size
116
+
117
+ assert_equal 'History.txt', diffs.first.a_path
118
+ assert_equal 'History.txt', diffs.first.b_path
119
+ assert_equal nil, diffs.first.a_blob
120
+ assert_equal nil, diffs.first.b_mode
121
+ assert_equal '81d2c27608b352814cbe979a6acd678d30219678', diffs.first.b_blob.id
122
+ assert_equal true, diffs.first.new_file
123
+ assert_equal false, diffs.first.deleted_file
124
+ assert_equal "--- /dev/null\n+++ b/History.txt\n@@ -0,0 +1,5 @@\n+== 1.0.0 / 2007-10-09\n+\n+* 1 major enhancement\n+ * Birthday!\n+", diffs.first.diff
125
+
126
+
127
+ assert_equal 'lib/grit.rb', diffs[5].a_path
128
+ assert_equal nil, diffs[5].a_blob
129
+ assert_equal '32cec87d1e78946a827ddf6a8776be4d81dcf1d1', diffs[5].b_blob.id
130
+ assert_equal true, diffs[5].new_file
131
+ end
132
+
133
+ def test_diffs_on_initial_import_with_empty_commit
134
+ Git.any_instance.expects(:show).with(
135
+ {:full_index => true, :pretty => 'raw'},
136
+ '634396b2f541a9f2d58b00be1a07f0c358b999b3'
137
+ ).returns(fixture('show_empty_commit'))
138
+
139
+ @c = Commit.create(@r, :id => '634396b2f541a9f2d58b00be1a07f0c358b999b3')
140
+ diffs = @c.diffs
141
+
142
+ assert_equal [], diffs
143
+ end
144
+
145
+ def test_diffs_with_mode_only_change
146
+ Git.any_instance.expects(:diff).returns(fixture('diff_mode_only'))
147
+ @c = Commit.create(@r, :id => '91169e1f5fa4de2eaea3f176461f5dc784796769')
148
+ diffs = @c.diffs
149
+
150
+ assert_equal 23, diffs.size
151
+ assert_equal '100644', diffs[0].a_mode
152
+ assert_equal '100755', diffs[0].b_mode
153
+ end
154
+
155
+ # to_s
156
+
157
+ def test_to_s
158
+ @c = Commit.create(@r, :id => 'abc')
159
+ assert_equal "abc", @c.to_s
160
+ end
161
+
162
+ # to_patch
163
+
164
+ def test_to_patch
165
+ @c = Commit.create(@r, :id => '80f136f500dfdb8c3e8abf4ae716f875f0a1b57f')
166
+
167
+ patch = @c.to_patch
168
+
169
+ assert patch.include?('From 80f136f500dfdb8c3e8abf4ae716f875f0a1b57f Mon Sep 17 00:00:00 2001')
170
+ assert patch.include?('From: tom <tom@taco.(none)>')
171
+ assert patch.include?('Date: Tue, 20 Nov 2007 17:27:42 -0800')
172
+ assert patch.include?('Subject: [PATCH] fix tests on other machines')
173
+ assert patch.include?('test/test_reality.rb | 30 +++++++++++++++---------------')
174
+ assert patch.include?('@@ -1,17 +1,17 @@')
175
+ assert patch.include?('+# recurse(t)')
176
+ assert patch.include?("1.6.")
177
+ end
178
+
179
+ # inspect
180
+
181
+ def test_inspect
182
+ @c = Commit.create(@r, :id => 'abc')
183
+ assert_equal %Q{#<Grit::Commit "abc">}, @c.inspect
184
+ end
185
+
186
+ # to_hash
187
+
188
+ def test_to_hash
189
+ old_tz, ENV["TZ"] = ENV["TZ"], "US/Pacific"
190
+ @c = Commit.create(@r, :id => '4c8124ffcf4039d292442eeccabdeca5af5c5017')
191
+ date = Time.parse('Wed Oct 10 03:06:12 -0400 2007')
192
+ expected = {
193
+ 'parents' => ['id' => "634396b2f541a9f2d58b00be1a07f0c358b999b3"],
194
+ 'committed_date' => date.xmlschema,
195
+ 'tree' => "672eca9b7f9e09c22dcb128c283e8c3c8d7697a4",
196
+ 'authored_date' => date.xmlschema,
197
+ 'committer' => {'email' => "tom@mojombo.com", 'name' => "Tom Preston-Werner"},
198
+ 'message' => "implement Grit#heads",
199
+ 'author' => {'email' => "tom@mojombo.com", 'name' => "Tom Preston-Werner"},
200
+ 'id' => "4c8124ffcf4039d292442eeccabdeca5af5c5017"
201
+ }
202
+
203
+ assert_equal expected, @c.to_hash
204
+ ensure
205
+ ENV["TZ"] = old_tz
206
+ end
207
+ end