]>
Commit | Line | Data |
---|---|---|
c8596009 JH |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2005 Junio C Hamano | |
4 | # | |
5 | ||
6 | test_description='Two way merge with read-tree -m -u $H $M | |
7 | ||
8 | This is identical to t1001, but uses -u to update the work tree as well. | |
9 | ||
10 | ' | |
4ea08416 | 11 | |
6ab75ac8 | 12 | TEST_PASSES_SANITIZE_LEAK=true |
c8596009 | 13 | . ./test-lib.sh |
ea5070c9 | 14 | . "$TEST_DIRECTORY"/lib-read-tree.sh |
c8596009 | 15 | |
c8596009 JH |
16 | compare_change () { |
17 | sed >current \ | |
26e08a01 BC |
18 | -e '1{/^diff --git /d;}' \ |
19 | -e '2{/^index /d;}' \ | |
c8596009 | 20 | -e '/^--- /d; /^+++ /d; /^@@ /d;' \ |
2ece6ad2 | 21 | -e 's/^\(.[0-7][0-7][0-7][0-7][0-7][0-7]\) '"$OID_REGEX"' /\1 X /' "$1" |
3af82863 | 22 | test_cmp expected current |
c8596009 JH |
23 | } |
24 | ||
25 | check_cache_at () { | |
277ce796 ÆAB |
26 | git diff-files -- "$1" >out && |
27 | clean_if_empty=$(cat out) && | |
c8596009 JH |
28 | case "$clean_if_empty" in |
29 | '') echo "$1: clean" ;; | |
30 | ?*) echo "$1: dirty" ;; | |
277ce796 | 31 | esac && |
c8596009 JH |
32 | case "$2,$clean_if_empty" in |
33 | clean,) : ;; | |
34 | clean,?*) false ;; | |
35 | dirty,) false ;; | |
36 | dirty,?*) : ;; | |
37 | esac | |
38 | } | |
39 | ||
a10bb2de JC |
40 | test_expect_success setup ' |
41 | echo frotz >frotz && | |
42 | echo nitfol >nitfol && | |
43 | echo bozbar >bozbar && | |
44 | echo rezrov >rezrov && | |
45 | git update-index --add nitfol bozbar rezrov && | |
46 | treeH=$(git write-tree) && | |
47 | echo treeH $treeH && | |
48 | git ls-tree $treeH && | |
49 | ||
50 | echo gnusto >bozbar && | |
51 | git update-index --add frotz bozbar --force-remove rezrov && | |
52 | git ls-files --stage >M.out && | |
53 | treeM=$(git write-tree) && | |
54 | echo treeM $treeM && | |
55 | git ls-tree $treeM && | |
56 | cp bozbar bozbar.M && | |
57 | cp frotz frotz.M && | |
58 | cp nitfol nitfol.M && | |
59 | git diff-tree $treeH $treeM | |
70ec6bd6 | 60 | ' |
c8596009 | 61 | |
a10bb2de JC |
62 | test_expect_success '1, 2, 3 - no carry forward' ' |
63 | rm -f .git/index nitfol bozbar rezrov frotz && | |
64 | read_tree_u_must_succeed --reset -u $treeH && | |
65 | read_tree_u_must_succeed -m -u $treeH $treeM && | |
66 | git ls-files --stage >1-3.out && | |
67 | cmp M.out 1-3.out && | |
68 | test_cmp bozbar.M bozbar && | |
69 | test_cmp frotz.M frotz && | |
70 | test_cmp nitfol.M nitfol && | |
71 | check_cache_at bozbar clean && | |
72 | check_cache_at frotz clean && | |
73 | check_cache_at nitfol clean | |
74 | ' | |
75 | ||
76 | test_expect_success '4 - carry forward local addition.' ' | |
77 | rm -f .git/index nitfol bozbar rezrov frotz && | |
78 | read_tree_u_must_succeed --reset -u $treeH && | |
79 | echo "+100644 X 0 yomin" >expected && | |
80 | echo yomin >yomin && | |
81 | git update-index --add yomin && | |
82 | read_tree_u_must_succeed -m -u $treeH $treeM && | |
83 | git ls-files --stage >4.out && | |
84 | test_might_fail git diff -U0 --no-index M.out 4.out >4diff.out && | |
85 | compare_change 4diff.out expected && | |
86 | check_cache_at yomin clean && | |
87 | test_cmp bozbar.M bozbar && | |
88 | test_cmp frotz.M frotz && | |
89 | test_cmp nitfol.M nitfol && | |
90 | echo yomin >yomin1 && | |
91 | diff yomin yomin1 && | |
92 | rm -f yomin1 | |
93 | ' | |
94 | ||
95 | test_expect_success '5 - carry forward local addition.' ' | |
96 | rm -f .git/index nitfol bozbar rezrov frotz && | |
97 | read_tree_u_must_succeed --reset -u $treeH && | |
98 | read_tree_u_must_succeed -m -u $treeH && | |
99 | echo yomin >yomin && | |
100 | git update-index --add yomin && | |
101 | echo yomin yomin >yomin && | |
102 | read_tree_u_must_succeed -m -u $treeH $treeM && | |
103 | git ls-files --stage >5.out && | |
104 | test_might_fail git diff -U0 --no-index M.out 5.out >5diff.out && | |
105 | compare_change 5diff.out expected && | |
106 | check_cache_at yomin dirty && | |
107 | test_cmp bozbar.M bozbar && | |
108 | test_cmp frotz.M frotz && | |
109 | test_cmp nitfol.M nitfol && | |
110 | : dirty index should have prevented -u from checking it out. && | |
111 | echo yomin yomin >yomin1 && | |
112 | diff yomin yomin1 && | |
113 | rm -f yomin1 | |
114 | ' | |
115 | ||
116 | test_expect_success '6 - local addition already has the same.' ' | |
117 | rm -f .git/index nitfol bozbar rezrov frotz && | |
118 | read_tree_u_must_succeed --reset -u $treeH && | |
119 | echo frotz >frotz && | |
120 | git update-index --add frotz && | |
121 | read_tree_u_must_succeed -m -u $treeH $treeM && | |
122 | git ls-files --stage >6.out && | |
123 | test_cmp M.out 6.out && | |
124 | check_cache_at frotz clean && | |
125 | test_cmp bozbar.M bozbar && | |
126 | test_cmp frotz.M frotz && | |
127 | test_cmp nitfol.M nitfol && | |
128 | echo frotz >frotz1 && | |
129 | diff frotz frotz1 && | |
130 | rm -f frotz1 | |
131 | ' | |
132 | ||
133 | test_expect_success '7 - local addition already has the same.' ' | |
134 | rm -f .git/index nitfol bozbar rezrov frotz && | |
135 | read_tree_u_must_succeed --reset -u $treeH && | |
136 | echo frotz >frotz && | |
137 | git update-index --add frotz && | |
138 | echo frotz frotz >frotz && | |
139 | read_tree_u_must_succeed -m -u $treeH $treeM && | |
140 | git ls-files --stage >7.out && | |
141 | test_cmp M.out 7.out && | |
142 | check_cache_at frotz dirty && | |
143 | test_cmp bozbar.M bozbar && | |
144 | test_cmp nitfol.M nitfol && | |
145 | : dirty index should have prevented -u from checking it out. && | |
146 | echo frotz frotz >frotz1 && | |
147 | diff frotz frotz1 && | |
148 | rm -f frotz1 | |
149 | ' | |
150 | ||
151 | test_expect_success '8 - conflicting addition.' ' | |
152 | rm -f .git/index nitfol bozbar rezrov frotz && | |
153 | read_tree_u_must_succeed --reset -u $treeH && | |
154 | echo frotz frotz >frotz && | |
155 | git update-index --add frotz && | |
156 | ! read_tree_u_must_succeed -m -u $treeH $treeM | |
157 | ' | |
158 | ||
159 | test_expect_success '9 - conflicting addition.' ' | |
160 | rm -f .git/index nitfol bozbar rezrov frotz && | |
161 | read_tree_u_must_succeed --reset -u $treeH && | |
162 | echo frotz frotz >frotz && | |
163 | git update-index --add frotz && | |
164 | echo frotz >frotz && | |
165 | ! read_tree_u_must_succeed -m -u $treeH $treeM | |
166 | ' | |
167 | ||
168 | test_expect_success '10 - path removed.' ' | |
169 | rm -f .git/index nitfol bozbar rezrov frotz && | |
170 | read_tree_u_must_succeed --reset -u $treeH && | |
171 | echo rezrov >rezrov && | |
172 | git update-index --add rezrov && | |
173 | read_tree_u_must_succeed -m -u $treeH $treeM && | |
174 | git ls-files --stage >10.out && | |
175 | cmp M.out 10.out && | |
176 | test_cmp bozbar.M bozbar && | |
177 | test_cmp frotz.M frotz && | |
178 | test_cmp nitfol.M nitfol | |
179 | ' | |
180 | ||
181 | test_expect_success '11 - dirty path removed.' ' | |
182 | rm -f .git/index nitfol bozbar rezrov frotz && | |
183 | read_tree_u_must_succeed --reset -u $treeH && | |
184 | echo rezrov >rezrov && | |
185 | git update-index --add rezrov && | |
186 | echo rezrov rezrov >rezrov && | |
187 | ! read_tree_u_must_succeed -m -u $treeH $treeM | |
188 | ' | |
189 | ||
190 | test_expect_success '12 - unmatching local changes being removed.' ' | |
191 | rm -f .git/index nitfol bozbar rezrov frotz && | |
192 | read_tree_u_must_succeed --reset -u $treeH && | |
193 | echo rezrov rezrov >rezrov && | |
194 | git update-index --add rezrov && | |
195 | ! read_tree_u_must_succeed -m -u $treeH $treeM | |
196 | ' | |
197 | ||
198 | test_expect_success '13 - unmatching local changes being removed.' ' | |
199 | rm -f .git/index nitfol bozbar rezrov frotz && | |
200 | read_tree_u_must_succeed --reset -u $treeH && | |
201 | echo rezrov rezrov >rezrov && | |
202 | git update-index --add rezrov && | |
203 | echo rezrov >rezrov && | |
204 | ! read_tree_u_must_succeed -m -u $treeH $treeM | |
205 | ' | |
c8596009 JH |
206 | |
207 | cat >expected <<EOF | |
208 | -100644 X 0 nitfol | |
209 | +100644 X 0 nitfol | |
210 | EOF | |
211 | ||
a10bb2de JC |
212 | test_expect_success '14 - unchanged in two heads.' ' |
213 | rm -f .git/index nitfol bozbar rezrov frotz && | |
214 | read_tree_u_must_succeed --reset -u $treeH && | |
215 | echo nitfol nitfol >nitfol && | |
216 | git update-index --add nitfol && | |
217 | read_tree_u_must_succeed -m -u $treeH $treeM && | |
218 | git ls-files --stage >14.out && | |
219 | test_must_fail git diff -U0 --no-index M.out 14.out >14diff.out && | |
220 | compare_change 14diff.out expected && | |
221 | test_cmp bozbar.M bozbar && | |
222 | test_cmp frotz.M frotz && | |
223 | check_cache_at nitfol clean && | |
224 | echo nitfol nitfol >nitfol1 && | |
225 | diff nitfol nitfol1 && | |
226 | rm -f nitfol1 | |
70ec6bd6 | 227 | ' |
c8596009 | 228 | |
a10bb2de JC |
229 | test_expect_success '15 - unchanged in two heads.' ' |
230 | rm -f .git/index nitfol bozbar rezrov frotz && | |
231 | read_tree_u_must_succeed --reset -u $treeH && | |
232 | echo nitfol nitfol >nitfol && | |
233 | git update-index --add nitfol && | |
234 | echo nitfol nitfol nitfol >nitfol && | |
235 | read_tree_u_must_succeed -m -u $treeH $treeM && | |
236 | git ls-files --stage >15.out && | |
237 | test_must_fail git diff -U0 --no-index M.out 15.out >15diff.out && | |
238 | compare_change 15diff.out expected && | |
239 | check_cache_at nitfol dirty && | |
240 | test_cmp bozbar.M bozbar && | |
241 | test_cmp frotz.M frotz && | |
242 | echo nitfol nitfol nitfol >nitfol1 && | |
243 | diff nitfol nitfol1 && | |
244 | rm -f nitfol1 | |
70ec6bd6 | 245 | ' |
c8596009 | 246 | |
a10bb2de JC |
247 | test_expect_success '16 - conflicting local change.' ' |
248 | rm -f .git/index nitfol bozbar rezrov frotz && | |
249 | read_tree_u_must_succeed --reset -u $treeH && | |
250 | echo bozbar bozbar >bozbar && | |
251 | git update-index --add bozbar && | |
252 | ! read_tree_u_must_succeed -m -u $treeH $treeM | |
253 | ' | |
254 | ||
255 | test_expect_success '17 - conflicting local change.' ' | |
256 | rm -f .git/index nitfol bozbar rezrov frotz && | |
257 | read_tree_u_must_succeed --reset -u $treeH && | |
258 | echo bozbar bozbar >bozbar && | |
259 | git update-index --add bozbar && | |
260 | echo bozbar bozbar bozbar >bozbar && | |
261 | ! read_tree_u_must_succeed -m -u $treeH $treeM | |
262 | ' | |
263 | ||
264 | test_expect_success '18 - local change already having a good result.' ' | |
265 | rm -f .git/index nitfol bozbar rezrov frotz && | |
266 | read_tree_u_must_succeed --reset -u $treeH && | |
267 | echo gnusto >bozbar && | |
268 | git update-index --add bozbar && | |
269 | read_tree_u_must_succeed -m -u $treeH $treeM && | |
270 | git ls-files --stage >18.out && | |
271 | test_cmp M.out 18.out && | |
272 | check_cache_at bozbar clean && | |
273 | test_cmp bozbar.M bozbar && | |
274 | test_cmp frotz.M frotz && | |
275 | test_cmp nitfol.M nitfol | |
276 | ' | |
277 | ||
278 | test_expect_success '19 - local change already having a good result, further modified.' ' | |
279 | rm -f .git/index nitfol bozbar rezrov frotz && | |
280 | read_tree_u_must_succeed --reset -u $treeH && | |
281 | echo gnusto >bozbar && | |
282 | git update-index --add bozbar && | |
283 | echo gnusto gnusto >bozbar && | |
284 | read_tree_u_must_succeed -m -u $treeH $treeM && | |
285 | git ls-files --stage >19.out && | |
286 | test_cmp M.out 19.out && | |
287 | check_cache_at bozbar dirty && | |
288 | test_cmp frotz.M frotz && | |
289 | test_cmp nitfol.M nitfol && | |
290 | echo gnusto gnusto >bozbar1 && | |
291 | diff bozbar bozbar1 && | |
292 | rm -f bozbar1 | |
293 | ' | |
294 | ||
295 | test_expect_success '20 - no local change, use new tree.' ' | |
296 | rm -f .git/index nitfol bozbar rezrov frotz && | |
297 | read_tree_u_must_succeed --reset -u $treeH && | |
298 | echo bozbar >bozbar && | |
299 | git update-index --add bozbar && | |
300 | read_tree_u_must_succeed -m -u $treeH $treeM && | |
301 | git ls-files --stage >20.out && | |
302 | test_cmp M.out 20.out && | |
303 | check_cache_at bozbar clean && | |
304 | test_cmp bozbar.M bozbar && | |
305 | test_cmp frotz.M frotz && | |
306 | test_cmp nitfol.M nitfol | |
307 | ' | |
308 | ||
309 | test_expect_success '21 - no local change, dirty cache.' ' | |
310 | rm -f .git/index nitfol bozbar rezrov frotz && | |
311 | read_tree_u_must_succeed --reset -u $treeH && | |
312 | echo bozbar >bozbar && | |
313 | git update-index --add bozbar && | |
314 | echo gnusto gnusto >bozbar && | |
315 | ! read_tree_u_must_succeed -m -u $treeH $treeM | |
316 | ' | |
c8596009 JH |
317 | |
318 | # Also make sure we did not break DF vs DF/DF case. | |
a10bb2de JC |
319 | test_expect_success 'DF vs DF/DF case setup.' ' |
320 | rm -f .git/index && | |
321 | echo DF >DF && | |
322 | git update-index --add DF && | |
323 | treeDF=$(git write-tree) && | |
324 | echo treeDF $treeDF && | |
325 | git ls-tree $treeDF && | |
326 | ||
327 | rm -f DF && | |
328 | mkdir DF && | |
329 | echo DF/DF >DF/DF && | |
330 | git update-index --add --remove DF DF/DF && | |
331 | treeDFDF=$(git write-tree) && | |
332 | echo treeDFDF $treeDFDF && | |
333 | git ls-tree $treeDFDF && | |
334 | git ls-files --stage >DFDF.out | |
335 | ' | |
336 | ||
337 | test_expect_success 'DF vs DF/DF case test.' ' | |
338 | rm -f .git/index && | |
339 | rm -fr DF && | |
340 | echo DF >DF && | |
341 | git update-index --add DF && | |
342 | read_tree_u_must_succeed -m -u $treeDF $treeDFDF && | |
343 | git ls-files --stage >DFDFcheck.out && | |
344 | test_cmp DFDF.out DFDFcheck.out && | |
345 | check_cache_at DF/DF clean | |
346 | ' | |
c8596009 JH |
347 | |
348 | test_done |