337
test refs/heads/delete-me = "$(git symbolic-ref HEAD)" &&
338
test_must_fail git checkout --track -b track'
339
340
-test_expect_success 'checkout an unmerged path should fail' '
340
+setup_conflicting_index () {
341
rm -f .git/index &&
342
O=$(echo original | git hash-object -w --stdin) &&
343
A=$(echo ourside | git hash-object -w --stdin) &&
348
echo "100644 $A 2 file" &&
349
echo "100644 $B 3 file" &&
350
echo "100644 $A 0 filf"
351
- ) | git update-index --index-info &&
351
+ ) | git update-index --index-info
352
+}
353
+
354
+test_expect_success 'checkout an unmerged path should fail' '
355
+ setup_conflicting_index &&
356
echo "none of the above" >sample &&
357
cat sample >fild &&
358
cat sample >file &&
364
'
365
366
test_expect_success 'checkout with an unmerged path can be ignored' '
363
- rm -f .git/index &&
364
- O=$(echo original | git hash-object -w --stdin) &&
365
- A=$(echo ourside | git hash-object -w --stdin) &&
366
- B=$(echo theirside | git hash-object -w --stdin) &&
367
- (
368
- echo "100644 $A 0 fild" &&
369
- echo "100644 $O 1 file" &&
370
- echo "100644 $A 2 file" &&
371
- echo "100644 $B 3 file" &&
372
- echo "100644 $A 0 filf"
373
- ) | git update-index --index-info &&
367
+ setup_conflicting_index &&
368
echo "none of the above" >sample &&
369
echo ourside >expect &&
370
cat sample >fild &&
377
'
378
379
test_expect_success 'checkout unmerged stage' '
386
- rm -f .git/index &&
387
- O=$(echo original | git hash-object -w --stdin) &&
388
- A=$(echo ourside | git hash-object -w --stdin) &&
389
- B=$(echo theirside | git hash-object -w --stdin) &&
390
- (
391
- echo "100644 $A 0 fild" &&
392
- echo "100644 $O 1 file" &&
393
- echo "100644 $A 2 file" &&
394
- echo "100644 $B 3 file" &&
395
- echo "100644 $A 0 filf"
396
- ) | git update-index --index-info &&
380
+ setup_conflicting_index &&
381
echo "none of the above" >sample &&
382
echo ourside >expect &&
383
cat sample >fild &&
392
'
393
394
test_expect_success 'checkout with --merge' '
411
- rm -f .git/index &&
412
- O=$(echo original | git hash-object -w --stdin) &&
413
- A=$(echo ourside | git hash-object -w --stdin) &&
414
- B=$(echo theirside | git hash-object -w --stdin) &&
415
- (
416
- echo "100644 $A 0 fild" &&
417
- echo "100644 $O 1 file" &&
418
- echo "100644 $A 2 file" &&
419
- echo "100644 $B 3 file" &&
420
- echo "100644 $A 0 filf"
421
- ) | git update-index --index-info &&
395
+ setup_conflicting_index &&
396
echo "none of the above" >sample &&
397
echo ourside >expect &&
398
cat sample >fild &&
413
414
test_expect_success 'checkout with --merge, in diff3 -m style' '
415
git config merge.conflictstyle diff3 &&
442
- rm -f .git/index &&
443
- O=$(echo original | git hash-object -w --stdin) &&
444
- A=$(echo ourside | git hash-object -w --stdin) &&
445
- B=$(echo theirside | git hash-object -w --stdin) &&
446
- (
447
- echo "100644 $A 0 fild" &&
448
- echo "100644 $O 1 file" &&
449
- echo "100644 $A 2 file" &&
450
- echo "100644 $B 3 file" &&
451
- echo "100644 $A 0 filf"
452
- ) | git update-index --index-info &&
416
+ setup_conflicting_index &&
417
echo "none of the above" >sample &&
418
echo ourside >expect &&
419
cat sample >fild &&
434
test_cmp merged file
435
'
436
437
+test_expect_success 'checkout --conflict=merge, overriding config' '
438
+ git config merge.conflictstyle diff3 &&
439
+ setup_conflicting_index &&
440
+ echo "none of the above" >sample &&
441
+ echo ourside >expect &&
442
+ cat sample >fild &&
443
+ cat sample >file &&
444
+ cat sample >filf &&
445
+ git checkout --conflict=merge -- fild file filf &&
446
+ (
447
+ echo "<<<<<<< ours"
448
+ echo ourside
449
+ echo "======="
450
+ echo theirside
451
+ echo ">>>>>>> theirs"
452
+ ) >merged &&
453
+ test_cmp expect fild &&
454
+ test_cmp expect filf &&
455
+ test_cmp merged file
456
+'
457
+
458
+test_expect_success 'checkout --conflict=diff3' '
459
+ git config --unset merge.conflictstyle
460
+ setup_conflicting_index &&
461
+ echo "none of the above" >sample &&
462
+ echo ourside >expect &&
463
+ cat sample >fild &&
464
+ cat sample >file &&
465
+ cat sample >filf &&
466
+ git checkout --conflict=diff3 -- fild file filf &&
467
+ (
468
+ echo "<<<<<<< ours"
469
+ echo ourside
470
+ echo "|||||||"
471
+ echo original
472
+ echo "======="
473
+ echo theirside
474
+ echo ">>>>>>> theirs"
475
+ ) >merged &&
476
+ test_cmp expect fild &&
477
+ test_cmp expect filf &&
478
+ test_cmp merged file
479
+'
480
+
481
test_done