1
1
require 'test_helper'
2
- require 'base64'
3
2
4
3
module 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
7
7
end
8
8
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
11
12
end
12
13
13
14
def blob_contents ( repo , path )
@@ -72,26 +73,39 @@ def test_apply_workdir
72
73
new_commit , new_content , original_content = update_file ( @repo , 'README' )
73
74
74
75
@repo . checkout_head ( :strategy => :force )
75
- assert_workdir_contents 'README' , new_content
76
+ assert_workdir_content 'README' , new_content
76
77
77
78
diff = @repo . diff ( new_commit , @original_commit )
78
79
79
80
assert_equal true , @repo . apply ( diff )
80
- assert_workdir_contents 'README' , original_content
81
+ assert_workdir_content 'README' , original_content
81
82
end
82
83
83
84
def test_apply_both
84
85
new_commit , new_content , original_content = update_file ( @repo , 'README' )
85
86
86
87
@repo . checkout_head ( :strategy => :force )
87
88
assert_index_content 'README' , new_content
88
- assert_workdir_contents 'README' , new_content
89
+ assert_workdir_content 'README' , new_content
89
90
90
91
diff = @repo . diff ( new_commit , @original_commit )
91
92
92
93
assert_equal true , @repo . apply ( diff , :location => :both )
93
94
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
95
109
end
96
110
97
111
def test_location_option
@@ -111,16 +125,21 @@ def test_callbacks
111
125
112
126
diff = @repo . diff ( new_commit , @original_commit )
113
127
128
+ callsback = 0
129
+
114
130
hunk_cb = Proc . new { |hunk |
131
+ callsback += 1
115
132
assert hunk . is_a? ( Rugged ::Diff ::Hunk )
116
133
}
117
134
118
135
delta_cb = Proc . new { |delta |
136
+ callsback += 1
119
137
assert delta . is_a? ( Rugged ::Diff ::Delta )
120
138
}
121
139
122
140
assert_equal true , @repo . apply ( diff , { :location => :index , :hunk_callback => hunk_cb , :delta_callback => delta_cb } )
123
141
assert_index_content 'README' , original_content
142
+ assert_equal callsback , 2
124
143
125
144
hunk_skip_all = Proc . new {
126
145
false
0 commit comments