11require 'test_helper'
2- require 'base64'
32
43module RepositoryApplyTestHelpers
5- def assert_workdir_contents ( path , test_value )
6- assert_equal File . read ( File . join ( @repo . workdir , path ) ) , test_value
4+ def assert_workdir_content ( path , test_value , repo = nil )
5+ repo = @repo if repo . nil?
6+ assert_equal File . read ( File . join ( repo . workdir , path ) ) , test_value
77 end
88
9- def assert_index_content ( path , test_value )
10- assert_equal @repo . lookup ( @repo . index [ path ] [ :oid ] ) . content , test_value
9+ def assert_index_content ( path , test_value , repo = nil )
10+ repo = @repo if repo . nil?
11+ assert_equal repo . lookup ( repo . index [ path ] [ :oid ] ) . content , test_value
1112 end
1213
1314 def blob_contents ( repo , path )
@@ -72,26 +73,39 @@ def test_apply_workdir
7273 new_commit , new_content , original_content = update_file ( @repo , 'README' )
7374
7475 @repo . checkout_head ( :strategy => :force )
75- assert_workdir_contents 'README' , new_content
76+ assert_workdir_content 'README' , new_content
7677
7778 diff = @repo . diff ( new_commit , @original_commit )
7879
7980 assert_equal true , @repo . apply ( diff )
80- assert_workdir_contents 'README' , original_content
81+ assert_workdir_content 'README' , original_content
8182 end
8283
8384 def test_apply_both
8485 new_commit , new_content , original_content = update_file ( @repo , 'README' )
8586
8687 @repo . checkout_head ( :strategy => :force )
8788 assert_index_content 'README' , new_content
88- assert_workdir_contents 'README' , new_content
89+ assert_workdir_content 'README' , new_content
8990
9091 diff = @repo . diff ( new_commit , @original_commit )
9192
9293 assert_equal true , @repo . apply ( diff , :location => :both )
9394 assert_index_content 'README' , original_content
94- assert_workdir_contents 'README' , original_content
95+ assert_workdir_content 'README' , original_content
96+ end
97+
98+ def test_bare_repository_defaults_to_index
99+ bare_repo = Rugged ::Repository . clone_at ( @repo . path , Dir . mktmpdir ( 'rugged-apply_bare' ) , :bare => true )
100+ original_commit = bare_repo . head . target . oid
101+
102+ new_commit , new_content , original_content = update_file ( bare_repo , 'README' )
103+ assert_index_content 'README' , new_content , bare_repo
104+
105+ diff = bare_repo . diff ( new_commit , original_commit )
106+
107+ assert_equal true , bare_repo . apply ( diff )
108+ assert_index_content 'README' , original_content , bare_repo
95109 end
96110
97111 def test_location_option
@@ -111,16 +125,21 @@ def test_callbacks
111125
112126 diff = @repo . diff ( new_commit , @original_commit )
113127
128+ callsback = 0
129+
114130 hunk_cb = Proc . new { |hunk |
131+ callsback += 1
115132 assert hunk . is_a? ( Rugged ::Diff ::Hunk )
116133 }
117134
118135 delta_cb = Proc . new { |delta |
136+ callsback += 1
119137 assert delta . is_a? ( Rugged ::Diff ::Delta )
120138 }
121139
122140 assert_equal true , @repo . apply ( diff , { :location => :index , :hunk_callback => hunk_cb , :delta_callback => delta_cb } )
123141 assert_index_content 'README' , original_content
142+ assert_equal callsback , 2
124143
125144 hunk_skip_all = Proc . new {
126145 false
0 commit comments