Merge branch 'jc/maint-combine-diff-pre-context'
[git] / t / t3030-merge-recursive.sh
1 #!/bin/sh
2
3 test_description='merge-recursive backend test'
4
5 . ./test-lib.sh
6
7 test_expect_success 'setup 1' '
8
9         echo hello >a &&
10         o0=$(git hash-object a) &&
11         cp a b &&
12         cp a c &&
13         mkdir d &&
14         cp a d/e &&
15
16         test_tick &&
17         git add a b c d/e &&
18         git commit -m initial &&
19         c0=$(git rev-parse --verify HEAD) &&
20         git branch side &&
21         git branch df-1 &&
22         git branch df-2 &&
23         git branch df-3 &&
24         git branch remove &&
25
26         echo hello >>a &&
27         cp a d/e &&
28         o1=$(git hash-object a) &&
29
30         git add a d/e &&
31
32         test_tick &&
33         git commit -m "master modifies a and d/e" &&
34         c1=$(git rev-parse --verify HEAD) &&
35         ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
36         (
37                 echo "100644 blob $o1   a"
38                 echo "100644 blob $o0   b"
39                 echo "100644 blob $o0   c"
40                 echo "100644 blob $o1   d/e"
41                 echo "100644 $o1 0      a"
42                 echo "100644 $o0 0      b"
43                 echo "100644 $o0 0      c"
44                 echo "100644 $o1 0      d/e"
45         ) >expected &&
46         test_cmp expected actual
47 '
48
49 test_expect_success 'setup 2' '
50
51         rm -rf [abcd] &&
52         git checkout side &&
53         ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
54         (
55                 echo "100644 blob $o0   a"
56                 echo "100644 blob $o0   b"
57                 echo "100644 blob $o0   c"
58                 echo "100644 blob $o0   d/e"
59                 echo "100644 $o0 0      a"
60                 echo "100644 $o0 0      b"
61                 echo "100644 $o0 0      c"
62                 echo "100644 $o0 0      d/e"
63         ) >expected &&
64         test_cmp expected actual &&
65
66         echo goodbye >>a &&
67         o2=$(git hash-object a) &&
68
69         git add a &&
70
71         test_tick &&
72         git commit -m "side modifies a" &&
73         c2=$(git rev-parse --verify HEAD) &&
74         ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
75         (
76                 echo "100644 blob $o2   a"
77                 echo "100644 blob $o0   b"
78                 echo "100644 blob $o0   c"
79                 echo "100644 blob $o0   d/e"
80                 echo "100644 $o2 0      a"
81                 echo "100644 $o0 0      b"
82                 echo "100644 $o0 0      c"
83                 echo "100644 $o0 0      d/e"
84         ) >expected &&
85         test_cmp expected actual
86 '
87
88 test_expect_success 'setup 3' '
89
90         rm -rf [abcd] &&
91         git checkout df-1 &&
92         ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
93         (
94                 echo "100644 blob $o0   a"
95                 echo "100644 blob $o0   b"
96                 echo "100644 blob $o0   c"
97                 echo "100644 blob $o0   d/e"
98                 echo "100644 $o0 0      a"
99                 echo "100644 $o0 0      b"
100                 echo "100644 $o0 0      c"
101                 echo "100644 $o0 0      d/e"
102         ) >expected &&
103         test_cmp expected actual &&
104
105         rm -f b && mkdir b && echo df-1 >b/c && git add b/c &&
106         o3=$(git hash-object b/c) &&
107
108         test_tick &&
109         git commit -m "df-1 makes b/c" &&
110         c3=$(git rev-parse --verify HEAD) &&
111         ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
112         (
113                 echo "100644 blob $o0   a"
114                 echo "100644 blob $o3   b/c"
115                 echo "100644 blob $o0   c"
116                 echo "100644 blob $o0   d/e"
117                 echo "100644 $o0 0      a"
118                 echo "100644 $o3 0      b/c"
119                 echo "100644 $o0 0      c"
120                 echo "100644 $o0 0      d/e"
121         ) >expected &&
122         test_cmp expected actual
123 '
124
125 test_expect_success 'setup 4' '
126
127         rm -rf [abcd] &&
128         git checkout df-2 &&
129         ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
130         (
131                 echo "100644 blob $o0   a"
132                 echo "100644 blob $o0   b"
133                 echo "100644 blob $o0   c"
134                 echo "100644 blob $o0   d/e"
135                 echo "100644 $o0 0      a"
136                 echo "100644 $o0 0      b"
137                 echo "100644 $o0 0      c"
138                 echo "100644 $o0 0      d/e"
139         ) >expected &&
140         test_cmp expected actual &&
141
142         rm -f a && mkdir a && echo df-2 >a/c && git add a/c &&
143         o4=$(git hash-object a/c) &&
144
145         test_tick &&
146         git commit -m "df-2 makes a/c" &&
147         c4=$(git rev-parse --verify HEAD) &&
148         ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
149         (
150                 echo "100644 blob $o4   a/c"
151                 echo "100644 blob $o0   b"
152                 echo "100644 blob $o0   c"
153                 echo "100644 blob $o0   d/e"
154                 echo "100644 $o4 0      a/c"
155                 echo "100644 $o0 0      b"
156                 echo "100644 $o0 0      c"
157                 echo "100644 $o0 0      d/e"
158         ) >expected &&
159         test_cmp expected actual
160 '
161
162 test_expect_success 'setup 5' '
163
164         rm -rf [abcd] &&
165         git checkout remove &&
166         ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
167         (
168                 echo "100644 blob $o0   a"
169                 echo "100644 blob $o0   b"
170                 echo "100644 blob $o0   c"
171                 echo "100644 blob $o0   d/e"
172                 echo "100644 $o0 0      a"
173                 echo "100644 $o0 0      b"
174                 echo "100644 $o0 0      c"
175                 echo "100644 $o0 0      d/e"
176         ) >expected &&
177         test_cmp expected actual &&
178
179         rm -f b &&
180         echo remove-conflict >a &&
181
182         git add a &&
183         git rm b &&
184         o5=$(git hash-object a) &&
185
186         test_tick &&
187         git commit -m "remove removes b and modifies a" &&
188         c5=$(git rev-parse --verify HEAD) &&
189         ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
190         (
191                 echo "100644 blob $o5   a"
192                 echo "100644 blob $o0   c"
193                 echo "100644 blob $o0   d/e"
194                 echo "100644 $o5 0      a"
195                 echo "100644 $o0 0      c"
196                 echo "100644 $o0 0      d/e"
197         ) >expected &&
198         test_cmp expected actual
199
200 '
201
202 test_expect_success 'setup 6' '
203
204         rm -rf [abcd] &&
205         git checkout df-3 &&
206         ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
207         (
208                 echo "100644 blob $o0   a"
209                 echo "100644 blob $o0   b"
210                 echo "100644 blob $o0   c"
211                 echo "100644 blob $o0   d/e"
212                 echo "100644 $o0 0      a"
213                 echo "100644 $o0 0      b"
214                 echo "100644 $o0 0      c"
215                 echo "100644 $o0 0      d/e"
216         ) >expected &&
217         test_cmp expected actual &&
218
219         rm -fr d && echo df-3 >d && git add d &&
220         o6=$(git hash-object d) &&
221
222         test_tick &&
223         git commit -m "df-3 makes d" &&
224         c6=$(git rev-parse --verify HEAD) &&
225         ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
226         (
227                 echo "100644 blob $o0   a"
228                 echo "100644 blob $o0   b"
229                 echo "100644 blob $o0   c"
230                 echo "100644 blob $o6   d"
231                 echo "100644 $o0 0      a"
232                 echo "100644 $o0 0      b"
233                 echo "100644 $o0 0      c"
234                 echo "100644 $o6 0      d"
235         ) >expected &&
236         test_cmp expected actual
237 '
238
239 test_expect_success 'merge-recursive simple' '
240
241         rm -fr [abcd] &&
242         git checkout -f "$c2" &&
243
244         git-merge-recursive "$c0" -- "$c2" "$c1"
245         status=$?
246         case "$status" in
247         1)
248                 : happy
249                 ;;
250         *)
251                 echo >&2 "why status $status!!!"
252                 false
253                 ;;
254         esac
255 '
256
257 test_expect_success 'merge-recursive result' '
258
259         git ls-files -s >actual &&
260         (
261                 echo "100644 $o0 1      a"
262                 echo "100644 $o2 2      a"
263                 echo "100644 $o1 3      a"
264                 echo "100644 $o0 0      b"
265                 echo "100644 $o0 0      c"
266                 echo "100644 $o1 0      d/e"
267         ) >expected &&
268         test_cmp expected actual
269
270 '
271
272 test_expect_success 'merge-recursive remove conflict' '
273
274         rm -fr [abcd] &&
275         git checkout -f "$c1" &&
276
277         git-merge-recursive "$c0" -- "$c1" "$c5"
278         status=$?
279         case "$status" in
280         1)
281                 : happy
282                 ;;
283         *)
284                 echo >&2 "why status $status!!!"
285                 false
286                 ;;
287         esac
288 '
289
290 test_expect_success 'merge-recursive remove conflict' '
291
292         git ls-files -s >actual &&
293         (
294                 echo "100644 $o0 1      a"
295                 echo "100644 $o1 2      a"
296                 echo "100644 $o5 3      a"
297                 echo "100644 $o0 0      c"
298                 echo "100644 $o1 0      d/e"
299         ) >expected &&
300         test_cmp expected actual
301
302 '
303
304 test_expect_success 'merge-recursive d/f simple' '
305         rm -fr [abcd] &&
306         git reset --hard &&
307         git checkout -f "$c1" &&
308
309         git-merge-recursive "$c0" -- "$c1" "$c3"
310 '
311
312 test_expect_success 'merge-recursive result' '
313
314         git ls-files -s >actual &&
315         (
316                 echo "100644 $o1 0      a"
317                 echo "100644 $o3 0      b/c"
318                 echo "100644 $o0 0      c"
319                 echo "100644 $o1 0      d/e"
320         ) >expected &&
321         test_cmp expected actual
322
323 '
324
325 test_expect_success 'merge-recursive d/f conflict' '
326
327         rm -fr [abcd] &&
328         git reset --hard &&
329         git checkout -f "$c1" &&
330
331         git-merge-recursive "$c0" -- "$c1" "$c4"
332         status=$?
333         case "$status" in
334         1)
335                 : happy
336                 ;;
337         *)
338                 echo >&2 "why status $status!!!"
339                 false
340                 ;;
341         esac
342 '
343
344 test_expect_success 'merge-recursive d/f conflict result' '
345
346         git ls-files -s >actual &&
347         (
348                 echo "100644 $o0 1      a"
349                 echo "100644 $o1 2      a"
350                 echo "100644 $o4 0      a/c"
351                 echo "100644 $o0 0      b"
352                 echo "100644 $o0 0      c"
353                 echo "100644 $o1 0      d/e"
354         ) >expected &&
355         test_cmp expected actual
356
357 '
358
359 test_expect_success 'merge-recursive d/f conflict the other way' '
360
361         rm -fr [abcd] &&
362         git reset --hard &&
363         git checkout -f "$c4" &&
364
365         git-merge-recursive "$c0" -- "$c4" "$c1"
366         status=$?
367         case "$status" in
368         1)
369                 : happy
370                 ;;
371         *)
372                 echo >&2 "why status $status!!!"
373                 false
374                 ;;
375         esac
376 '
377
378 test_expect_success 'merge-recursive d/f conflict result the other way' '
379
380         git ls-files -s >actual &&
381         (
382                 echo "100644 $o0 1      a"
383                 echo "100644 $o1 3      a"
384                 echo "100644 $o4 0      a/c"
385                 echo "100644 $o0 0      b"
386                 echo "100644 $o0 0      c"
387                 echo "100644 $o1 0      d/e"
388         ) >expected &&
389         test_cmp expected actual
390
391 '
392
393 test_expect_success 'merge-recursive d/f conflict' '
394
395         rm -fr [abcd] &&
396         git reset --hard &&
397         git checkout -f "$c1" &&
398
399         git-merge-recursive "$c0" -- "$c1" "$c6"
400         status=$?
401         case "$status" in
402         1)
403                 : happy
404                 ;;
405         *)
406                 echo >&2 "why status $status!!!"
407                 false
408                 ;;
409         esac
410 '
411
412 test_expect_success 'merge-recursive d/f conflict result' '
413
414         git ls-files -s >actual &&
415         (
416                 echo "100644 $o1 0      a"
417                 echo "100644 $o0 0      b"
418                 echo "100644 $o0 0      c"
419                 echo "100644 $o6 3      d"
420                 echo "100644 $o0 1      d/e"
421                 echo "100644 $o1 2      d/e"
422         ) >expected &&
423         test_cmp expected actual
424
425 '
426
427 test_expect_success 'merge-recursive d/f conflict' '
428
429         rm -fr [abcd] &&
430         git reset --hard &&
431         git checkout -f "$c6" &&
432
433         git-merge-recursive "$c0" -- "$c6" "$c1"
434         status=$?
435         case "$status" in
436         1)
437                 : happy
438                 ;;
439         *)
440                 echo >&2 "why status $status!!!"
441                 false
442                 ;;
443         esac
444 '
445
446 test_expect_success 'merge-recursive d/f conflict result' '
447
448         git ls-files -s >actual &&
449         (
450                 echo "100644 $o1 0      a"
451                 echo "100644 $o0 0      b"
452                 echo "100644 $o0 0      c"
453                 echo "100644 $o6 2      d"
454                 echo "100644 $o0 1      d/e"
455                 echo "100644 $o1 3      d/e"
456         ) >expected &&
457         test_cmp expected actual
458
459 '
460
461 test_expect_success 'reset and 3-way merge' '
462
463         git reset --hard "$c2" &&
464         git read-tree -m "$c0" "$c2" "$c1"
465
466 '
467
468 test_expect_success 'reset and bind merge' '
469
470         git reset --hard master &&
471         git read-tree --prefix=M/ master &&
472         git ls-files -s >actual &&
473         (
474                 echo "100644 $o1 0      M/a"
475                 echo "100644 $o0 0      M/b"
476                 echo "100644 $o0 0      M/c"
477                 echo "100644 $o1 0      M/d/e"
478                 echo "100644 $o1 0      a"
479                 echo "100644 $o0 0      b"
480                 echo "100644 $o0 0      c"
481                 echo "100644 $o1 0      d/e"
482         ) >expected &&
483         test_cmp expected actual &&
484
485         git read-tree --prefix=a1/ master &&
486         git ls-files -s >actual &&
487         (
488                 echo "100644 $o1 0      M/a"
489                 echo "100644 $o0 0      M/b"
490                 echo "100644 $o0 0      M/c"
491                 echo "100644 $o1 0      M/d/e"
492                 echo "100644 $o1 0      a"
493                 echo "100644 $o1 0      a1/a"
494                 echo "100644 $o0 0      a1/b"
495                 echo "100644 $o0 0      a1/c"
496                 echo "100644 $o1 0      a1/d/e"
497                 echo "100644 $o0 0      b"
498                 echo "100644 $o0 0      c"
499                 echo "100644 $o1 0      d/e"
500         ) >expected &&
501         test_cmp expected actual
502
503         git read-tree --prefix=z/ master &&
504         git ls-files -s >actual &&
505         (
506                 echo "100644 $o1 0      M/a"
507                 echo "100644 $o0 0      M/b"
508                 echo "100644 $o0 0      M/c"
509                 echo "100644 $o1 0      M/d/e"
510                 echo "100644 $o1 0      a"
511                 echo "100644 $o1 0      a1/a"
512                 echo "100644 $o0 0      a1/b"
513                 echo "100644 $o0 0      a1/c"
514                 echo "100644 $o1 0      a1/d/e"
515                 echo "100644 $o0 0      b"
516                 echo "100644 $o0 0      c"
517                 echo "100644 $o1 0      d/e"
518                 echo "100644 $o1 0      z/a"
519                 echo "100644 $o0 0      z/b"
520                 echo "100644 $o0 0      z/c"
521                 echo "100644 $o1 0      z/d/e"
522         ) >expected &&
523         test_cmp expected actual
524
525 '
526
527 test_done