mojombo-grit 0.8.1 → 0.9.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. data/History.txt +7 -0
  2. data/Manifest.txt +18 -1
  3. data/grit.gemspec +56 -10
  4. data/lib/{mojombo-grit.rb → grit.rb} +20 -4
  5. data/lib/grit/commit.rb +32 -11
  6. data/lib/grit/commit_stats.rb +104 -0
  7. data/lib/grit/git-ruby.rb +182 -0
  8. data/lib/grit/git-ruby/commit_db.rb +52 -0
  9. data/lib/grit/git-ruby/file_index.rb +186 -0
  10. data/lib/grit/git-ruby/git_object.rb +344 -0
  11. data/lib/grit/git-ruby/internal/loose.rb +136 -0
  12. data/lib/grit/git-ruby/internal/mmap.rb +58 -0
  13. data/lib/grit/git-ruby/internal/pack.rb +382 -0
  14. data/lib/grit/git-ruby/internal/raw_object.rb +37 -0
  15. data/lib/grit/git-ruby/object.rb +319 -0
  16. data/lib/grit/git-ruby/repository.rb +729 -0
  17. data/lib/grit/git.rb +33 -15
  18. data/lib/grit/head.rb +6 -15
  19. data/lib/grit/index.rb +121 -0
  20. data/lib/grit/ref.rb +95 -0
  21. data/lib/grit/repo.rb +95 -6
  22. data/lib/grit/status.rb +151 -0
  23. data/lib/grit/tree.rb +3 -2
  24. data/test/test_blob.rb +5 -0
  25. data/test/test_commit.rb +7 -5
  26. data/test/test_diff.rb +1 -1
  27. data/test/test_git.rb +20 -2
  28. data/test/test_grit.rb +32 -0
  29. data/test/test_head.rb +30 -5
  30. data/test/test_real.rb +8 -6
  31. data/test/test_remote.rb +14 -0
  32. data/test/test_repo.rb +86 -79
  33. data/test/test_tag.rb +2 -6
  34. data/test/test_tree.rb +5 -0
  35. metadata +40 -40
  36. data/test/fixtures/blame +0 -131
  37. data/test/fixtures/cat_file_blob +0 -1
  38. data/test/fixtures/cat_file_blob_size +0 -1
  39. data/test/fixtures/diff_2 +0 -54
  40. data/test/fixtures/diff_2f +0 -19
  41. data/test/fixtures/diff_f +0 -15
  42. data/test/fixtures/diff_i +0 -201
  43. data/test/fixtures/diff_mode_only +0 -1152
  44. data/test/fixtures/diff_new_mode +0 -17
  45. data/test/fixtures/diff_p +0 -610
  46. data/test/fixtures/for_each_ref +0 -0
  47. data/test/fixtures/for_each_ref_tags +0 -0
  48. data/test/fixtures/ls_tree_a +0 -7
  49. data/test/fixtures/ls_tree_b +0 -2
  50. data/test/fixtures/ls_tree_commit +0 -3
  51. data/test/fixtures/rev_list +0 -26
  52. data/test/fixtures/rev_list_count +0 -655
  53. data/test/fixtures/rev_list_single +0 -7
  54. data/test/fixtures/rev_parse +0 -1
  55. data/test/fixtures/show_empty_commit +0 -6
  56. data/test/fixtures/simple_config +0 -2
  57. data/test/helper.rb +0 -17
  58. data/test/profile.rb +0 -21
  59. data/test/suite.rb +0 -6
@@ -0,0 +1,151 @@
1
+ module Grit
2
+
3
+ class Status
4
+ include Enumerable
5
+
6
+ @base = nil
7
+ @files = nil
8
+
9
+ def initialize(base)
10
+ @base = base
11
+ construct_status
12
+ end
13
+
14
+ def changed
15
+ @files.select { |k, f| f.type == 'M' }
16
+ end
17
+
18
+ def added
19
+ @files.select { |k, f| f.type == 'A' }
20
+ end
21
+
22
+ def deleted
23
+ @files.select { |k, f| f.type == 'D' }
24
+ end
25
+
26
+ def untracked
27
+ @files.select { |k, f| f.untracked }
28
+ end
29
+
30
+ def pretty
31
+ out = ''
32
+ self.each do |file|
33
+ out << file.path
34
+ out << "\n\tsha(r) " + file.sha_repo.to_s + ' ' + file.mode_repo.to_s
35
+ out << "\n\tsha(i) " + file.sha_index.to_s + ' ' + file.mode_index.to_s
36
+ out << "\n\ttype " + file.type.to_s
37
+ out << "\n\tstage " + file.stage.to_s
38
+ out << "\n\tuntrac " + file.untracked.to_s
39
+ out << "\n"
40
+ end
41
+ out << "\n"
42
+ out
43
+ end
44
+
45
+ # enumerable method
46
+
47
+ def [](file)
48
+ @files[file]
49
+ end
50
+
51
+ def each
52
+ @files.each do |k, file|
53
+ yield file
54
+ end
55
+ end
56
+
57
+ class StatusFile
58
+ attr_accessor :path, :type, :stage, :untracked
59
+ attr_accessor :mode_index, :mode_repo
60
+ attr_accessor :sha_index, :sha_repo
61
+
62
+ @base = nil
63
+
64
+ def initialize(base, hash)
65
+ @base = base
66
+ @path = hash[:path]
67
+ @type = hash[:type]
68
+ @stage = hash[:stage]
69
+ @mode_index = hash[:mode_index]
70
+ @mode_repo = hash[:mode_repo]
71
+ @sha_index = hash[:sha_index]
72
+ @sha_repo = hash[:sha_repo]
73
+ @untracked = hash[:untracked]
74
+ end
75
+
76
+ def blob(type = :index)
77
+ if type == :repo
78
+ @base.object(@sha_repo)
79
+ else
80
+ @base.object(@sha_index) rescue @base.object(@sha_repo)
81
+ end
82
+ end
83
+
84
+ end
85
+
86
+ private
87
+
88
+ def construct_status
89
+ @files = ls_files
90
+
91
+ Dir.chdir(@base.working_dir) do
92
+ # find untracked in working dir
93
+ Dir.glob('**/*') do |file|
94
+ if !@files[file]
95
+ @files[file] = {:path => file, :untracked => true} if !File.directory?(file)
96
+ end
97
+ end
98
+
99
+ # find modified in tree
100
+ diff_files.each do |path, data|
101
+ @files[path] ? @files[path].merge!(data) : @files[path] = data
102
+ end
103
+
104
+ # find added but not committed - new files
105
+ diff_index('HEAD').each do |path, data|
106
+ @files[path] ? @files[path].merge!(data) : @files[path] = data
107
+ end
108
+
109
+ @files.each do |k, file_hash|
110
+ @files[k] = StatusFile.new(@base, file_hash)
111
+ end
112
+ end
113
+ end
114
+
115
+ # compares the index and the working directory
116
+ def diff_files
117
+ hsh = {}
118
+ @base.git.diff_files.split("\n").each do |line|
119
+ (info, file) = line.split("\t")
120
+ (mode_src, mode_dest, sha_src, sha_dest, type) = info.split
121
+ hsh[file] = {:path => file, :mode_file => mode_src.to_s[1, 7], :mode_index => mode_dest,
122
+ :sha_file => sha_src, :sha_index => sha_dest, :type => type}
123
+ end
124
+ hsh
125
+ end
126
+
127
+ # compares the index and the repository
128
+ def diff_index(treeish)
129
+ hsh = {}
130
+ @base.git.diff_index({}, treeish).split("\n").each do |line|
131
+ (info, file) = line.split("\t")
132
+ (mode_src, mode_dest, sha_src, sha_dest, type) = info.split
133
+ hsh[file] = {:path => file, :mode_repo => mode_src.to_s[1, 7], :mode_index => mode_dest,
134
+ :sha_repo => sha_src, :sha_index => sha_dest, :type => type}
135
+ end
136
+ hsh
137
+ end
138
+
139
+ def ls_files
140
+ hsh = {}
141
+ lines = @base.git.ls_files({:stage => true})
142
+ lines.split("\n").each do |line|
143
+ (info, file) = line.split("\t")
144
+ (mode, sha, stage) = info.split
145
+ hsh[file] = {:path => file, :mode_index => mode, :sha_index => sha, :stage => stage}
146
+ end
147
+ hsh
148
+ end
149
+ end
150
+
151
+ end
data/lib/grit/tree.rb CHANGED
@@ -14,7 +14,6 @@ module Grit
14
14
  # Returns Grit::Tree (baked)
15
15
  def self.construct(repo, treeish, paths = [])
16
16
  output = repo.git.ls_tree({}, treeish, *paths)
17
-
18
17
  self.allocate.construct_initialize(repo, treeish, output)
19
18
  end
20
19
 
@@ -70,6 +69,8 @@ module Grit
70
69
  Tree.create(repo, :id => id, :mode => mode, :name => name)
71
70
  when "blob"
72
71
  Blob.create(repo, :id => id, :mode => mode, :name => name)
72
+ when "link"
73
+ Blob.create(repo, :id => id, :mode => mode, :name => name)
73
74
  when "commit"
74
75
  nil
75
76
  else
@@ -87,7 +88,7 @@ module Grit
87
88
  #
88
89
  # Returns Grit::Blob or Grit::Tree or nil if not found
89
90
  def /(file)
90
- self.contents.select { |c| c.name == file }.first
91
+ self.contents.find { |c| c.name == file }
91
92
  end
92
93
 
93
94
  # Pretty object inspection
data/test/test_blob.rb CHANGED
@@ -7,6 +7,11 @@ class TestBlob < Test::Unit::TestCase
7
7
  end
8
8
 
9
9
  # blob
10
+ def test_nosuch_blob
11
+ t = @r.blob('blahblah')
12
+ puts t.data
13
+ assert t.is_a?(Blob)
14
+ end
10
15
 
11
16
  def test_data_should_return_blob_contents
12
17
  Git.any_instance.expects(:cat_file).returns(fixture('cat_file_blob'))
data/test/test_commit.rb CHANGED
@@ -2,7 +2,7 @@ require File.dirname(__FILE__) + '/helper'
2
2
 
3
3
  class TestCommit < Test::Unit::TestCase
4
4
  def setup
5
- @r = Repo.new(GRIT_REPO)
5
+ @r = Repo.new(File.join(File.dirname(__FILE__), *%w[dot_git]), :is_bare => true)
6
6
  end
7
7
 
8
8
  # __bake__
@@ -19,7 +19,6 @@ class TestCommit < Test::Unit::TestCase
19
19
  # short_name
20
20
 
21
21
  def test_id_abbrev
22
- Git.any_instance.expects(:rev_parse).returns(fixture('rev_parse'))
23
22
  assert_equal '80f136f', @r.commit('80f136f500dfdb8c3e8abf4ae716f875f0a1b57f').id_abbrev
24
23
  end
25
24
 
@@ -164,13 +163,14 @@ class TestCommit < Test::Unit::TestCase
164
163
  # to_hash
165
164
 
166
165
  def test_to_hash
166
+ old_tz, ENV["TZ"] = ENV["TZ"], "US/Pacific"
167
167
  @c = Commit.create(@r, :id => '4c8124ffcf4039d292442eeccabdeca5af5c5017')
168
-
168
+ date = Time.parse('Wed Oct 10 03:06:12 -0400 2007')
169
169
  expected = {
170
170
  'parents' => ['id' => "634396b2f541a9f2d58b00be1a07f0c358b999b3"],
171
- 'committed_date' => "2007-10-10T00:06:12-07:00",
171
+ 'committed_date' => date.xmlschema,
172
172
  'tree' => "672eca9b7f9e09c22dcb128c283e8c3c8d7697a4",
173
- 'authored_date' => "2007-10-10T00:06:12-07:00",
173
+ 'authored_date' => date.xmlschema,
174
174
  'committer' => {'email' => "tom@mojombo.com", 'name' => "Tom Preston-Werner"},
175
175
  'message' => "implement Grit#heads",
176
176
  'author' => {'email' => "tom@mojombo.com", 'name' => "Tom Preston-Werner"},
@@ -178,5 +178,7 @@ class TestCommit < Test::Unit::TestCase
178
178
  }
179
179
 
180
180
  assert_equal expected, @c.to_hash
181
+ ensure
182
+ ENV["TZ"] = old_tz
181
183
  end
182
184
  end
data/test/test_diff.rb CHANGED
@@ -10,7 +10,7 @@ class TestDiff < Test::Unit::TestCase
10
10
  def test_list_from_string_new_mode
11
11
  output = fixture('diff_new_mode')
12
12
 
13
- diffs = Diff.list_from_string(@r, output)
13
+ diffs = Grit::Diff.list_from_string(@r, output)
14
14
  assert_equal 2, diffs.size
15
15
  assert_equal 10, diffs.first.diff.split("\n").size
16
16
  assert_equal nil, diffs.last.diff
data/test/test_git.rb CHANGED
@@ -5,10 +5,28 @@ class TestGit < Test::Unit::TestCase
5
5
  @git = Git.new(File.join(File.dirname(__FILE__), *%w[..]))
6
6
  end
7
7
 
8
+ def teardown
9
+ Grit.debug = false
10
+ end
11
+
8
12
  def test_method_missing
9
13
  assert_match(/^git version [\w\.]*$/, @git.version)
10
14
  end
11
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
+
12
30
  def test_transform_options
13
31
  assert_equal ["-s"], @git.transform_options({:s => true})
14
32
  assert_equal ["-s '5'"], @git.transform_options({:s => 5})
@@ -38,7 +56,7 @@ class TestGit < Test::Unit::TestCase
38
56
 
39
57
  def test_raises_on_slow_shell
40
58
  Grit::Git.git_timeout = 0.5
41
- Open4.expects(:popen4).returns([ nil, nil, mock(:read => proc { sleep 1 }), nil ])
59
+ Open4.expects(:popen4).yields( nil, nil, mock(:read => proc { sleep 1 }), nil )
42
60
  assert_raises Grit::Git::GitTimeout do
43
61
  @git.something
44
62
  end
@@ -46,7 +64,7 @@ class TestGit < Test::Unit::TestCase
46
64
 
47
65
  def test_works_fine_if_quick
48
66
  output = 'output'
49
- Open4.expects(:popen4).returns([ nil, nil, mock(:read => output), nil ])
67
+ Open4.expects(:popen4).yields( nil, nil, mock(:read => output), stub(:read => nil) )
50
68
  assert_equal output, @git.something
51
69
  end
52
70
  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 CHANGED
@@ -2,21 +2,46 @@ require File.dirname(__FILE__) + '/helper'
2
2
 
3
3
  class TestHead < Test::Unit::TestCase
4
4
  def setup
5
- @r = Repo.new(GRIT_REPO)
6
- Git.any_instance.expects(:for_each_ref).returns(fixture('for_each_ref'))
5
+ @r = Repo.new(File.join(File.dirname(__FILE__), *%w[dot_git]), :is_bare => true)
7
6
  end
8
7
 
9
8
  # inspect
10
9
 
11
10
  def test_inspect
12
11
  head = @r.heads.first
13
- assert_equal %Q{#<Grit::Head "#{head.name}">}, head.inspect
12
+ assert_equal %Q{#<Grit::Head "test/master">}, head.inspect
14
13
  end
15
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
+
16
25
  # heads with slashes
17
26
 
18
27
  def test_heads_with_slashes
19
- head = @r.heads.last
20
- assert_equal %Q{#<Grit::Head "mojombo/master">}, head.inspect
28
+ head = @r.heads[2]
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')
21
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
+
22
47
  end
data/test/test_real.rb CHANGED
@@ -2,16 +2,18 @@
2
2
  #
3
3
  # class TestReal < Test::Unit::TestCase
4
4
  # def setup
5
- # @repo = Repo.new('/Users/tom/dev/sandbox/ruby-on-rails-tmbundle')
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')
6
8
  # end
7
9
  #
8
10
  # def test_real
9
- # # Grit.debug = true
11
+ # Grit.debug = true
10
12
  #
11
- # p @repo.commits
13
+ # index = @repo.index
14
+ # index.add('foo/bar/baz.txt', 'hello!')
15
+ # index.add('foo/qux/bam.txt', 'world!')
12
16
  #
13
- # # p (@repo.tree/'Syntaxes/Ruby on Rails.plist').data
14
- # # p @repo.tree('master', ['Snippets/rea.plist']).contents.first
15
- # p @repo.tree('master', ['Syntaxes/Ruby on Rails.plist']).contents.first
17
+ # puts index.commit('first commit')
16
18
  # end
17
19
  # end
@@ -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 CHANGED
@@ -4,57 +4,64 @@ class TestRepo < Test::Unit::TestCase
4
4
  def setup
5
5
  @r = Repo.new(GRIT_REPO)
6
6
  end
7
-
7
+
8
8
  # new
9
-
9
+
10
10
  def test_new_should_raise_on_invalid_repo_location
11
11
  assert_raise(InvalidGitRepositoryError) do
12
12
  Repo.new("/tmp")
13
13
  end
14
14
  end
15
-
15
+
16
16
  def test_new_should_raise_on_non_existant_path
17
17
  assert_raise(NoSuchPathError) do
18
18
  Repo.new("/foobar")
19
19
  end
20
20
  end
21
-
21
+
22
22
  # descriptions
23
-
23
+
24
24
  def test_description
25
25
  assert_equal "Unnamed repository; edit this file to name it for gitweb.", @r.description
26
26
  end
27
-
27
+
28
+ # refs
29
+
30
+ def test_refs_should_return_array_of_ref_objects
31
+ @r.refs.each do |ref|
32
+ assert ref.is_a? Grit::Ref
33
+ end
34
+ end
35
+
28
36
  # heads
29
-
37
+
30
38
  def test_heads_should_return_array_of_head_objects
31
39
  @r.heads.each do |head|
32
40
  assert_equal Grit::Head, head.class
33
41
  end
34
42
  end
35
-
43
+
36
44
  def test_heads_should_populate_head_data
37
- Git.any_instance.expects(:for_each_ref).returns(fixture('for_each_ref'))
38
-
45
+ @r = Repo.new(File.join(File.dirname(__FILE__), *%w[dot_git]), :is_bare => true)
39
46
  head = @r.heads.first
40
47
 
41
- assert_equal 'master', head.name
42
- assert_equal '634396b2f541a9f2d58b00be1a07f0c358b999b3', head.commit.id
48
+ assert_equal 'test/master', head.name
49
+ assert_equal '2d3acf90f35989df8f262dc50beadc4ee3ae1560', head.commit.id
43
50
  end
44
-
51
+
45
52
  # branches
46
-
53
+
47
54
  def test_branches
48
55
  # same as heads
49
56
  end
50
-
57
+
51
58
  # commits
52
-
59
+
53
60
  def test_commits
54
61
  Git.any_instance.expects(:rev_list).returns(fixture('rev_list'))
55
-
62
+
56
63
  commits = @r.commits('master', 10)
57
-
64
+
58
65
  c = commits[0]
59
66
  assert_equal '4c8124ffcf4039d292442eeccabdeca5af5c5017', c.id
60
67
  assert_equal ["634396b2f541a9f2d58b00be1a07f0c358b999b3"], c.parents.map { |p| p.id }
@@ -66,190 +73,190 @@ class TestRepo < Test::Unit::TestCase
66
73
  assert_equal "tom@mojombo.com", c.committer.email
67
74
  assert_equal Time.at(1191999972), c.committed_date
68
75
  assert_equal "implement Grit#heads", c.message
69
-
76
+
70
77
  c = commits[1]
71
78
  assert_equal [], c.parents
72
-
79
+
73
80
  c = commits[2]
74
81
  assert_equal ["6e64c55896aabb9a7d8e9f8f296f426d21a78c2c", "7f874954efb9ba35210445be456c74e037ba6af2"], c.parents.map { |p| p.id }
75
82
  assert_equal "Merge branch 'site'\n\n * Some other stuff\n * just one more", c.message
76
83
  assert_equal "Merge branch 'site'", c.short_message
77
84
  end
78
-
85
+
79
86
  # commit_count
80
-
87
+
81
88
  def test_commit_count
82
89
  Git.any_instance.expects(:rev_list).with({}, 'master').returns(fixture('rev_list_count'))
83
-
90
+
84
91
  assert_equal 655, @r.commit_count('master')
85
92
  end
86
-
93
+
87
94
  # commit
88
-
95
+
89
96
  def test_commit
90
97
  commit = @r.commit('634396b2f541a9f2d58b00be1a07f0c358b999b3')
91
-
98
+
92
99
  assert_equal "634396b2f541a9f2d58b00be1a07f0c358b999b3", commit.id
93
100
  end
94
-
101
+
95
102
  # tree
96
-
103
+
97
104
  def test_tree
98
105
  Git.any_instance.expects(:ls_tree).returns(fixture('ls_tree_a'))
99
106
  tree = @r.tree('master')
100
-
107
+
101
108
  assert_equal 4, tree.contents.select { |c| c.instance_of?(Blob) }.size
102
109
  assert_equal 3, tree.contents.select { |c| c.instance_of?(Tree) }.size
103
110
  end
104
-
111
+
105
112
  # blob
106
-
113
+
107
114
  def test_blob
108
115
  Git.any_instance.expects(:cat_file).returns(fixture('cat_file_blob'))
109
116
  blob = @r.blob("abc")
110
117
  assert_equal "Hello world", blob.data
111
118
  end
112
-
119
+
113
120
  # init_bare
114
-
121
+
115
122
  def test_init_bare
116
123
  Git.any_instance.expects(:init).returns(true)
117
- Repo.expects(:new).with("/foo/bar.git")
124
+ Repo.expects(:new).with("/foo/bar.git", {})
118
125
  Repo.init_bare("/foo/bar.git")
119
126
  end
120
-
127
+
121
128
  def test_init_bare_with_options
122
129
  Git.any_instance.expects(:init).with(
123
130
  :template => "/baz/sweet").returns(true)
124
- Repo.expects(:new).with("/foo/bar.git")
131
+ Repo.expects(:new).with("/foo/bar.git", {})
125
132
  Repo.init_bare("/foo/bar.git", :template => "/baz/sweet")
126
133
  end
127
-
134
+
128
135
  # fork_bare
129
-
136
+
130
137
  def test_fork_bare
131
138
  Git.any_instance.expects(:clone).with(
132
- {:bare => true, :shared => true},
139
+ {:bare => true, :shared => true},
133
140
  "#{absolute_project_path}/.git",
134
141
  "/foo/bar.git").returns(nil)
135
142
  Repo.expects(:new)
136
-
143
+
137
144
  @r.fork_bare("/foo/bar.git")
138
145
  end
139
-
146
+
140
147
  def test_fork_bare_with_options
141
148
  Git.any_instance.expects(:clone).with(
142
- {:bare => true, :shared => true, :template => '/awesome'},
149
+ {:bare => true, :shared => true, :template => '/awesome'},
143
150
  "#{absolute_project_path}/.git",
144
151
  "/foo/bar.git").returns(nil)
145
152
  Repo.expects(:new)
146
-
153
+
147
154
  @r.fork_bare("/foo/bar.git", :template => '/awesome')
148
155
  end
149
-
156
+
150
157
  # diff
151
-
158
+
152
159
  def test_diff
153
160
  Git.any_instance.expects(:diff).with({}, 'master^', 'master', '--')
154
161
  @r.diff('master^', 'master')
155
-
162
+
156
163
  Git.any_instance.expects(:diff).with({}, 'master^', 'master', '--', 'foo/bar')
157
164
  @r.diff('master^', 'master', 'foo/bar')
158
-
165
+
159
166
  Git.any_instance.expects(:diff).with({}, 'master^', 'master', '--', 'foo/bar', 'foo/baz')
160
167
  @r.diff('master^', 'master', 'foo/bar', 'foo/baz')
161
168
  end
162
-
169
+
163
170
  # commit_diff
164
-
171
+
165
172
  def test_diff
166
173
  Git.any_instance.expects(:diff).returns(fixture('diff_p'))
167
174
  diffs = @r.commit_diff('master')
168
-
175
+
169
176
  assert_equal 15, diffs.size
170
177
  end
171
-
178
+
172
179
  # init bare
173
-
180
+
174
181
  # archive
175
-
182
+
176
183
  def test_archive_tar
177
- @r.archive_tar
184
+ #@r.archive_tar -- no assertion being done here
178
185
  end
179
-
186
+
180
187
  # archive_tar_gz
181
-
188
+
182
189
  def test_archive_tar_gz
183
- @r.archive_tar_gz
190
+ #@r.archive_tar_gz -- again, no assertion
184
191
  end
185
-
192
+
186
193
  # enable_daemon_serve
187
-
194
+
188
195
  def test_enable_daemon_serve
189
196
  FileUtils.expects(:touch).with(File.join(@r.path, 'git-daemon-export-ok'))
190
197
  @r.enable_daemon_serve
191
198
  end
192
-
199
+
193
200
  # disable_daemon_serve
194
-
201
+
195
202
  def test_disable_daemon_serve
196
203
  FileUtils.expects(:rm_f).with(File.join(@r.path, 'git-daemon-export-ok'))
197
204
  @r.disable_daemon_serve
198
205
  end
199
-
206
+
200
207
  # alternates
201
-
208
+
202
209
  def test_alternates_with_two_alternates
203
210
  File.expects(:exist?).with("#{absolute_project_path}/.git/objects/info/alternates").returns(true)
204
211
  File.expects(:read).returns("/path/to/repo1/.git/objects\n/path/to/repo2.git/objects\n")
205
-
212
+
206
213
  assert_equal ["/path/to/repo1/.git/objects", "/path/to/repo2.git/objects"], @r.alternates
207
214
  end
208
-
215
+
209
216
  def test_alternates_no_file
210
217
  File.expects(:exist?).returns(false)
211
-
218
+
212
219
  assert_equal [], @r.alternates
213
220
  end
214
-
221
+
215
222
  # alternates=
216
-
223
+
217
224
  def test_alternates_setter_ok
218
225
  alts = %w{/path/to/repo.git/objects /path/to/repo2.git/objects}
219
-
226
+
220
227
  alts.each do |alt|
221
228
  File.expects(:exist?).with(alt).returns(true)
222
229
  end
223
-
230
+
224
231
  File.any_instance.expects(:write).with(alts.join("\n"))
225
-
232
+
226
233
  assert_nothing_raised do
227
234
  @r.alternates = alts
228
235
  end
229
236
  end
230
-
237
+
231
238
  def test_alternates_setter_bad
232
239
  alts = %w{/path/to/repo.git/objects}
233
-
240
+
234
241
  alts.each do |alt|
235
242
  File.expects(:exist?).with(alt).returns(false)
236
243
  end
237
-
244
+
238
245
  File.any_instance.expects(:write).never
239
-
246
+
240
247
  assert_raise RuntimeError do
241
248
  @r.alternates = alts
242
249
  end
243
250
  end
244
-
251
+
245
252
  def test_alternates_setter_empty
246
253
  File.expects(:delete)
247
-
254
+
248
255
  @r.alternates = []
249
256
  end
250
-
257
+
251
258
  # inspect
252
-
259
+
253
260
  def test_inspect
254
261
  assert_equal %Q{#<Grit::Repo "#{File.expand_path(GRIT_REPO)}/.git">}, @r.inspect
255
262
  end