3 test_description
='git merge
5 Testing pull.* configuration parsing and other things.'
7 TEST_PASSES_SANITIZE_LEAK
=true
10 test_expect_success
'setup' '
19 git reset --hard c0 &&
24 git reset --hard c0 &&
31 test_expect_success
'pull.rebase not set, ff possible' '
32 git reset --hard c0 &&
33 git pull . c1 2>err &&
34 test_grep ! "You have divergent branches" err
37 test_expect_success
'pull.rebase not set and pull.ff=true' '
38 git reset --hard c0 &&
39 test_config pull.ff true &&
40 git pull . c1 2>err &&
41 test_grep ! "You have divergent branches" err
44 test_expect_success
'pull.rebase not set and pull.ff=false' '
45 git reset --hard c0 &&
46 test_config pull.ff false &&
47 git pull . c1 2>err &&
48 test_grep ! "You have divergent branches" err
51 test_expect_success
'pull.rebase not set and pull.ff=only' '
52 git reset --hard c0 &&
53 test_config pull.ff only &&
54 git pull . c1 2>err &&
55 test_grep ! "You have divergent branches" err
58 test_expect_success
'pull.rebase not set and --rebase given' '
59 git reset --hard c0 &&
60 git pull --rebase . c1 2>err &&
61 test_grep ! "You have divergent branches" err
64 test_expect_success
'pull.rebase not set and --no-rebase given' '
65 git reset --hard c0 &&
66 git pull --no-rebase . c1 2>err &&
67 test_grep ! "You have divergent branches" err
70 test_expect_success
'pull.rebase not set and --ff given' '
71 git reset --hard c0 &&
72 git pull --ff . c1 2>err &&
73 test_grep ! "You have divergent branches" err
76 test_expect_success
'pull.rebase not set and --no-ff given' '
77 git reset --hard c0 &&
78 git pull --no-ff . c1 2>err &&
79 test_grep ! "You have divergent branches" err
82 test_expect_success
'pull.rebase not set and --ff-only given' '
83 git reset --hard c0 &&
84 git pull --ff-only . c1 2>err &&
85 test_grep ! "You have divergent branches" err
88 test_expect_success
'pull.rebase not set (not-fast-forward)' '
89 git reset --hard c2 &&
90 test_must_fail git -c color.advice=always pull . c1 2>err &&
91 test_decode_color <err >decoded &&
92 test_grep "<YELLOW>hint: " decoded &&
93 test_grep "You have divergent branches" decoded
96 test_expect_success
'pull.rebase not set and pull.ff=true (not-fast-forward)' '
97 git reset --hard c2 &&
98 test_config pull.ff true &&
99 git pull . c1 2>err &&
100 test_grep ! "You have divergent branches" err
103 test_expect_success
'pull.rebase not set and pull.ff=false (not-fast-forward)' '
104 git reset --hard c2 &&
105 test_config pull.ff false &&
106 git pull . c1 2>err &&
107 test_grep ! "You have divergent branches" err
110 test_expect_success
'pull.rebase not set and pull.ff=only (not-fast-forward)' '
111 git reset --hard c2 &&
112 test_config pull.ff only &&
113 test_must_fail git pull . c1 2>err &&
114 test_grep ! "You have divergent branches" err
117 test_expect_success
'pull.rebase not set and --rebase given (not-fast-forward)' '
118 git reset --hard c2 &&
119 git pull --rebase . c1 2>err &&
120 test_grep ! "You have divergent branches" err
123 test_expect_success
'pull.rebase not set and --no-rebase given (not-fast-forward)' '
124 git reset --hard c2 &&
125 git pull --no-rebase . c1 2>err &&
126 test_grep ! "You have divergent branches" err
129 test_expect_success
'pull.rebase not set and --ff given (not-fast-forward)' '
130 git reset --hard c2 &&
131 git pull --ff . c1 2>err &&
132 test_grep ! "You have divergent branches" err
135 test_expect_success
'pull.rebase not set and --no-ff given (not-fast-forward)' '
136 git reset --hard c2 &&
137 git pull --no-ff . c1 2>err &&
138 test_grep ! "You have divergent branches" err
141 test_expect_success
'pull.rebase not set and --ff-only given (not-fast-forward)' '
142 git reset --hard c2 &&
143 test_must_fail git pull --ff-only . c1 2>err &&
144 test_grep ! "You have divergent branches" err
147 test_does_rebase
() {
148 git
reset --hard c2
&&
150 # Check that we actually did a rebase
151 git rev-list
--count HEAD
>actual
&&
152 git rev-list
--merges --count HEAD
>>actual
&&
153 test_write_lines
3 0 >expect
&&
154 test_cmp expect actual
&&
158 # Prefers merge over fast-forward
159 test_does_merge_when_ff_possible
() {
160 git
reset --hard c0
&&
162 # Check that we actually did a merge
163 git rev-list
--count HEAD
>actual
&&
164 git rev-list
--merges --count HEAD
>>actual
&&
165 test_write_lines
3 1 >expect
&&
166 test_cmp expect actual
&&
170 # Prefers fast-forward over merge or rebase
171 test_does_fast_forward
() {
172 git
reset --hard c0
&&
175 # Check that we did not get any merges
176 git rev-list
--count HEAD
>actual
&&
177 git rev-list
--merges --count HEAD
>>actual
&&
178 test_write_lines
2 0 >expect
&&
179 test_cmp expect actual
&&
181 # Check that we ended up at c1
182 git rev-parse HEAD
>actual
&&
183 git rev-parse c1^
{commit
} >expect
&&
184 test_cmp actual expect
&&
186 # Remove temporary files
190 # Doesn't fail when fast-forward not possible; does a merge
191 test_falls_back_to_full_merge
() {
192 git
reset --hard c2
&&
194 # Check that we actually did a merge
195 git rev-list
--count HEAD
>actual
&&
196 git rev-list
--merges --count HEAD
>>actual
&&
197 test_write_lines
4 1 >expect
&&
198 test_cmp expect actual
&&
202 # Attempts fast forward, which is impossible, and bails
203 test_attempts_fast_forward
() {
204 git
reset --hard c2
&&
205 test_must_fail git
"$@" . c1
2>err
&&
206 test_grep
"Not possible to fast-forward, aborting" err
210 # Group 1: Interaction of --ff-only with --[no-]rebase
211 # (And related interaction of pull.ff=only with pull.rebase)
213 test_expect_success
'--ff-only overrides --rebase' '
214 test_attempts_fast_forward pull --rebase --ff-only
217 test_expect_success
'--ff-only overrides --rebase even if first' '
218 test_attempts_fast_forward pull --ff-only --rebase
221 test_expect_success
'--ff-only overrides --no-rebase' '
222 test_attempts_fast_forward pull --ff-only --no-rebase
225 test_expect_success
'pull.ff=only overrides pull.rebase=true' '
226 test_attempts_fast_forward -c pull.ff=only -c pull.rebase=true pull
229 test_expect_success
'pull.ff=only overrides pull.rebase=false' '
230 test_attempts_fast_forward -c pull.ff=only -c pull.rebase=false pull
233 # Group 2: --rebase=[!false] overrides --no-ff and --ff
234 # (And related interaction of pull.rebase=!false and pull.ff=!only)
235 test_expect_success
'--rebase overrides --no-ff' '
236 test_does_rebase pull --rebase --no-ff
239 test_expect_success
'--rebase overrides --ff' '
240 test_does_rebase pull --rebase --ff
243 test_expect_success
'--rebase fast-forwards when possible' '
244 test_does_fast_forward pull --rebase --ff
247 test_expect_success
'pull.rebase=true overrides pull.ff=false' '
248 test_does_rebase -c pull.rebase=true -c pull.ff=false pull
251 test_expect_success
'pull.rebase=true overrides pull.ff=true' '
252 test_does_rebase -c pull.rebase=true -c pull.ff=true pull
255 # Group 3: command line flags take precedence over config
256 test_expect_success
'--ff-only takes precedence over pull.rebase=true' '
257 test_attempts_fast_forward -c pull.rebase=true pull --ff-only
260 test_expect_success
'--ff-only takes precedence over pull.rebase=false' '
261 test_attempts_fast_forward -c pull.rebase=false pull --ff-only
264 test_expect_success
'--no-rebase takes precedence over pull.ff=only' '
265 test_falls_back_to_full_merge -c pull.ff=only pull --no-rebase
268 test_expect_success
'--rebase takes precedence over pull.ff=only' '
269 test_does_rebase -c pull.ff=only pull --rebase
272 test_expect_success
'--rebase overrides pull.ff=true' '
273 test_does_rebase -c pull.ff=true pull --rebase
276 test_expect_success
'--rebase overrides pull.ff=false' '
277 test_does_rebase -c pull.ff=false pull --rebase
280 test_expect_success
'--rebase overrides pull.ff unset' '
281 test_does_rebase pull --rebase
284 # Group 4: --no-rebase heeds pull.ff=!only or explict --ff or --no-ff
286 test_expect_success
'--no-rebase works with --no-ff' '
287 test_does_merge_when_ff_possible pull --no-rebase --no-ff
290 test_expect_success
'--no-rebase works with --ff' '
291 test_does_fast_forward pull --no-rebase --ff
294 test_expect_success
'--no-rebase does ff if pull.ff unset' '
295 test_does_fast_forward pull --no-rebase
298 test_expect_success
'--no-rebase heeds pull.ff=true' '
299 test_does_fast_forward -c pull.ff=true pull --no-rebase
302 test_expect_success
'--no-rebase heeds pull.ff=false' '
303 test_does_merge_when_ff_possible -c pull.ff=false pull --no-rebase
306 # Group 5: pull.rebase=!false in combination with --no-ff or --ff
307 test_expect_success
'pull.rebase=true and --no-ff' '
308 test_does_rebase -c pull.rebase=true pull --no-ff
311 test_expect_success
'pull.rebase=true and --ff' '
312 test_does_rebase -c pull.rebase=true pull --ff
315 test_expect_success
'pull.rebase=false and --no-ff' '
316 test_does_merge_when_ff_possible -c pull.rebase=false pull --no-ff
319 test_expect_success
'pull.rebase=false and --ff, ff possible' '
320 test_does_fast_forward -c pull.rebase=false pull --ff
323 test_expect_success
'pull.rebase=false and --ff, ff not possible' '
324 test_falls_back_to_full_merge -c pull.rebase=false pull --ff
327 # End of groupings for conflicting merge vs. rebase flags/options
329 test_expect_success
'Multiple heads warns about inability to fast forward' '
330 git reset --hard c1 &&
331 test_must_fail git pull . c2 c3 2>err &&
332 test_grep "You have divergent branches" err
335 test_expect_success
'Multiple can never be fast forwarded' '
336 git reset --hard c0 &&
337 test_must_fail git -c pull.ff=only pull . c1 c2 c3 2>err &&
338 test_grep ! "You have divergent branches" err &&
339 # In addition to calling out "cannot fast-forward", we very much
340 # want the "multiple branches" piece to be called out to users.
341 test_grep "Cannot fast-forward to multiple branches" err
344 test_expect_success
'Cannot rebase with multiple heads' '
345 git reset --hard c0 &&
346 test_must_fail git -c pull.rebase=true pull . c1 c2 c3 2>err &&
347 test_grep ! "You have divergent branches" err &&
348 test_grep "Cannot rebase onto multiple branches." err
351 test_expect_success
'merge c1 with c2' '
352 git reset --hard c1 &&
353 test_path_is_file c0.c &&
354 test_path_is_file c1.c &&
355 test_path_is_missing c2.c &&
356 test_path_is_missing c3.c &&
358 test_path_is_file c1.c &&
359 test_path_is_file c2.c
362 test_expect_success
'fast-forward pull succeeds with "true" in pull.ff' '
363 git reset --hard c0 &&
364 test_config pull.ff true &&
366 test "$(git rev-parse HEAD)" = "$(git rev-parse c1)"
369 test_expect_success
'pull.ff=true overrides merge.ff=false' '
370 git reset --hard c0 &&
371 test_config merge.ff false &&
372 test_config pull.ff true &&
374 test "$(git rev-parse HEAD)" = "$(git rev-parse c1)"
377 test_expect_success
'fast-forward pull creates merge with "false" in pull.ff' '
378 git reset --hard c0 &&
379 test_config pull.ff false &&
381 test "$(git rev-parse HEAD^1)" = "$(git rev-parse c0)" &&
382 test "$(git rev-parse HEAD^2)" = "$(git rev-parse c1)"
385 test_expect_success
'pull prevents non-fast-forward with "only" in pull.ff' '
386 git reset --hard c1 &&
387 test_config pull.ff only &&
388 test_must_fail git pull . c3
391 test_expect_success
'already-up-to-date pull succeeds with unspecified pull.ff' '
392 git reset --hard c1 &&
394 test "$(git rev-parse HEAD)" = "$(git rev-parse c1)"
397 test_expect_success
'already-up-to-date pull succeeds with "only" in pull.ff' '
398 git reset --hard c1 &&
399 test_config pull.ff only &&
401 test "$(git rev-parse HEAD)" = "$(git rev-parse c1)"
404 test_expect_success
'already-up-to-date pull/rebase succeeds with "only" in pull.ff' '
405 git reset --hard c1 &&
406 test_config pull.ff only &&
407 git -c pull.rebase=true pull . c0 &&
408 test "$(git rev-parse HEAD)" = "$(git rev-parse c1)"
411 test_expect_success
'merge c1 with c2 (ours in pull.twohead)' '
412 git reset --hard c1 &&
413 git config pull.twohead ours &&
415 test_path_is_file c1.c &&
416 test_path_is_missing c2.c
419 test_expect_success
'merge c1 with c2 and c3 (recursive in pull.octopus)' '
420 git reset --hard c1 &&
421 git config pull.octopus "recursive" &&
422 test_must_fail git merge c2 c3 &&
423 test "$(git rev-parse c1)" = "$(git rev-parse HEAD)"
426 test_expect_success
'merge c1 with c2 and c3 (recursive and octopus in pull.octopus)' '
427 git reset --hard c1 &&
428 git config pull.octopus "recursive octopus" &&
430 test "$(git rev-parse c1)" != "$(git rev-parse HEAD)" &&
431 test "$(git rev-parse c1)" = "$(git rev-parse HEAD^1)" &&
432 test "$(git rev-parse c2)" = "$(git rev-parse HEAD^2)" &&
433 test "$(git rev-parse c3)" = "$(git rev-parse HEAD^3)" &&
434 git diff --exit-code &&
435 test_path_is_file c0.c &&
436 test_path_is_file c1.c &&
437 test_path_is_file c2.c &&
438 test_path_is_file c3.c
444 git diff-files
--name-only
445 git ls-files
--unmerged
452 # There are two conflicts here:
454 # 1) Because foo.c is renamed to bar.c, recursive will handle this,
457 # 2) One in conflict.c and that will always fail.
459 test_expect_success
'setup conflicted merge' '
460 git reset --hard c0 &&
461 echo A >conflict.c &&
462 git add conflict.c &&
463 echo contents >foo.c &&
467 echo B >conflict.c &&
468 git add conflict.c &&
469 git mv foo.c bar.c &&
472 git reset --hard c4 &&
473 echo C >conflict.c &&
474 git add conflict.c &&
475 echo secondline >> foo.c &&
481 # First do the merge with resolve and recursive then verify that
482 # recursive is chosen.
484 test_expect_success
'merge picks up the best result' '
485 git config --unset-all pull.twohead &&
486 git reset --hard c5 &&
487 test_must_fail git merge -s resolve c6 &&
488 resolve_count=$(conflict_count) &&
489 git reset --hard c5 &&
490 test_must_fail git merge -s recursive c6 &&
491 recursive_count=$(conflict_count) &&
492 git reset --hard c5 &&
493 test_must_fail git merge -s recursive -s resolve c6 &&
494 auto_count=$(conflict_count) &&
495 test $auto_count = $recursive_count &&
496 test $auto_count != $resolve_count
499 test_expect_success
'merge picks up the best result (from config)' '
500 git config pull.twohead "recursive resolve" &&
501 git reset --hard c5 &&
502 test_must_fail git merge -s resolve c6 &&
503 resolve_count=$(conflict_count) &&
504 git reset --hard c5 &&
505 test_must_fail git merge -s recursive c6 &&
506 recursive_count=$(conflict_count) &&
507 git reset --hard c5 &&
508 test_must_fail git merge c6 &&
509 auto_count=$(conflict_count) &&
510 test $auto_count = $recursive_count &&
511 test $auto_count != $resolve_count
514 test_expect_success
'merge errors out on invalid strategy' '
515 git config pull.twohead "foobar" &&
516 git reset --hard c5 &&
517 test_must_fail git merge c6
520 test_expect_success
'merge errors out on invalid strategy' '
521 git config --unset-all pull.twohead &&
522 git reset --hard c5 &&
523 test_must_fail git merge -s "resolve recursive" c6