t6423: note improved ort handling with untracked files

Similar to the previous commit, since the "recursive" backend relies on unpack_trees() to check if unstaged or untracked files would be overwritten by a merge, and unpack_trees() does not understand renames -- it has false positives and false negatives. Once it has run, since it updates as it goes, merge-recursive then has to handle completing the merge as best it can despite extra changes in the working copy. However, this is not just an issue for dirty files, but also for untracked files because directory renames can cause file contents to need to be written to a location that was not tracked on either side of history. Since the "ort" backend does the complete merge inmemory, and only updates the index and working copy as a post-processing step, if there are untracked files in the way it can simply abort the merge much like checkout does. Update t6423 to reflect the better merge abilities and expectations for ort, while still leaving the best-case-as-good-as-recursive-can-do expectations there for the recursive backend so we retain its stability until we are ready to deprecate and remove it. Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Elijah Newren committed Oct 26, 2020 at 17:01 UTC fd15863ec8a90a4c2b4429f5f5de370c8599e700
1 file changed +124 -71
t/t6423-merge-rename-directories.sh
+124 -71
@@ -3214,6 +3214,7 @@ test_expect_success '10a: Overwrite untracked with normal rename/delete' '
3214 echo important >z/d &&
3215
3216 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
3217 + test_path_is_missing .git/MERGE_HEAD &&
3218 test_i18ngrep "The following untracked working tree files would be overwritten by merge" err &&
3219
3220 git ls-files -s >out &&
@@ -3283,21 +3284,34 @@ test_expect_success '10b: Overwrite untracked with dir rename + delete' '
3284 echo contents >y/e &&
3285
3286 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
3286 - test_i18ngrep "CONFLICT (rename/delete).*Version B\^0 of y/d left in tree at y/d~B\^0" out &&
3287 - test_i18ngrep "Error: Refusing to lose untracked file at y/e; writing to y/e~B\^0 instead" out &&
3287 + if test "$GIT_TEST_MERGE_ALGORITHM" = ort
3288 + then
3289 + test_path_is_missing .git/MERGE_HEAD &&
3290 + test_i18ngrep "error: The following untracked working tree files would be overwritten by merge" err &&
3291
3289 - git ls-files -s >out &&
3290 - test_line_count = 3 out &&
3291 - git ls-files -u >out &&
3292 - test_line_count = 2 out &&
3293 - git ls-files -o >out &&
3294 - test_line_count = 5 out &&
3292 + git ls-files -s >out &&
3293 + test_line_count = 1 out &&
3294 + git ls-files -u >out &&
3295 + test_line_count = 0 out &&
3296 + git ls-files -o >out &&
3297 + test_line_count = 5 out
3298 + else
3299 + test_i18ngrep "CONFLICT (rename/delete).*Version B\^0 of y/d left in tree at y/d~B\^0" out &&
3300 + test_i18ngrep "Error: Refusing to lose untracked file at y/e; writing to y/e~B\^0 instead" out &&
3301
3296 - git rev-parse >actual \
3297 - :0:y/b :3:y/d :3:y/e &&
3298 - git rev-parse >expect \
3299 - O:z/b O:z/c B:z/e &&
3300 - test_cmp expect actual &&
3302 + git ls-files -s >out &&
3303 + test_line_count = 3 out &&
3304 + git ls-files -u >out &&
3305 + test_line_count = 2 out &&
3306 + git ls-files -o >out &&
3307 + test_line_count = 5 out &&
3308 +
3309 + git rev-parse >actual \
3310 + :0:y/b :3:y/d :3:y/e &&
3311 + git rev-parse >expect \
3312 + O:z/b O:z/c B:z/e &&
3313 + test_cmp expect actual
3314 + fi &&
3315
3316 echo very >expect &&
3317 test_cmp expect y/c &&
@@ -3360,25 +3374,38 @@ test_expect_success '10c1: Overwrite untracked with dir rename/rename(1to2)' '
3374 echo important >y/c &&
3375
3376 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
3363 - test_i18ngrep "CONFLICT (rename/rename)" out &&
3364 - test_i18ngrep "Refusing to lose untracked file at y/c; adding as y/c~B\^0 instead" out &&
3377 + if test "$GIT_TEST_MERGE_ALGORITHM" = ort
3378 + then
3379 + test_path_is_missing .git/MERGE_HEAD &&
3380 + test_i18ngrep "error: The following untracked working tree files would be overwritten by merge" err &&
3381
3366 - git ls-files -s >out &&
3367 - test_line_count = 6 out &&
3368 - git ls-files -u >out &&
3369 - test_line_count = 3 out &&
3370 - git ls-files -o >out &&
3371 - test_line_count = 3 out &&
3382 + git ls-files -s >out &&
3383 + test_line_count = 4 out &&
3384 + git ls-files -u >out &&
3385 + test_line_count = 0 out &&
3386 + git ls-files -o >out &&
3387 + test_line_count = 3 out
3388 + else
3389 + test_i18ngrep "CONFLICT (rename/rename)" out &&
3390 + test_i18ngrep "Refusing to lose untracked file at y/c; adding as y/c~B\^0 instead" out &&
3391
3373 - git rev-parse >actual \
3374 - :0:y/a :0:y/b :0:x/d :1:x/c :2:w/c :3:y/c &&
3375 - git rev-parse >expect \
3376 - O:z/a O:z/b O:x/d O:x/c O:x/c O:x/c &&
3377 - test_cmp expect actual &&
3392 + git ls-files -s >out &&
3393 + test_line_count = 6 out &&
3394 + git ls-files -u >out &&
3395 + test_line_count = 3 out &&
3396 + git ls-files -o >out &&
3397 + test_line_count = 3 out &&
3398
3379 - git hash-object y/c~B^0 >actual &&
3380 - git rev-parse O:x/c >expect &&
3381 - test_cmp expect actual &&
3399 + git rev-parse >actual \
3400 + :0:y/a :0:y/b :0:x/d :1:x/c :2:w/c :3:y/c &&
3401 + git rev-parse >expect \
3402 + O:z/a O:z/b O:x/d O:x/c O:x/c O:x/c &&
3403 + test_cmp expect actual &&
3404 +
3405 + git hash-object y/c~B^0 >actual &&
3406 + git rev-parse O:x/c >expect &&
3407 + test_cmp expect actual
3408 + fi &&
3409
3410 echo important >expect &&
3411 test_cmp expect y/c
@@ -3398,25 +3425,38 @@ test_expect_success '10c2: Overwrite untracked with dir rename/rename(1to2), oth
3425 echo important >y/c &&
3426
3427 test_must_fail git -c merge.directoryRenames=true merge -s recursive A^0 >out 2>err &&
3401 - test_i18ngrep "CONFLICT (rename/rename)" out &&
3402 - test_i18ngrep "Refusing to lose untracked file at y/c; adding as y/c~HEAD instead" out &&
3428 + if test "$GIT_TEST_MERGE_ALGORITHM" = ort
3429 + then
3430 + test_path_is_missing .git/MERGE_HEAD &&
3431 + test_i18ngrep "error: The following untracked working tree files would be overwritten by merge" err &&
3432
3404 - git ls-files -s >out &&
3405 - test_line_count = 6 out &&
3406 - git ls-files -u >out &&
3407 - test_line_count = 3 out &&
3408 - git ls-files -o >out &&
3409 - test_line_count = 3 out &&
3433 + git ls-files -s >out &&
3434 + test_line_count = 4 out &&
3435 + git ls-files -u >out &&
3436 + test_line_count = 0 out &&
3437 + git ls-files -o >out &&
3438 + test_line_count = 3 out
3439 + else
3440 + test_i18ngrep "CONFLICT (rename/rename)" out &&
3441 + test_i18ngrep "Refusing to lose untracked file at y/c; adding as y/c~HEAD instead" out &&
3442
3411 - git rev-parse >actual \
3412 - :0:y/a :0:y/b :0:x/d :1:x/c :3:w/c :2:y/c &&
3413 - git rev-parse >expect \
3414 - O:z/a O:z/b O:x/d O:x/c O:x/c O:x/c &&
3415 - test_cmp expect actual &&
3443 + git ls-files -s >out &&
3444 + test_line_count = 6 out &&
3445 + git ls-files -u >out &&
3446 + test_line_count = 3 out &&
3447 + git ls-files -o >out &&
3448 + test_line_count = 3 out &&
3449
3417 - git hash-object y/c~HEAD >actual &&
3418 - git rev-parse O:x/c >expect &&
3419 - test_cmp expect actual &&
3450 + git rev-parse >actual \
3451 + :0:y/a :0:y/b :0:x/d :1:x/c :3:w/c :2:y/c &&
3452 + git rev-parse >expect \
3453 + O:z/a O:z/b O:x/d O:x/c O:x/c O:x/c &&
3454 + test_cmp expect actual &&
3455 +
3456 + git hash-object y/c~HEAD >actual &&
3457 + git rev-parse O:x/c >expect &&
3458 + test_cmp expect actual
3459 + fi &&
3460
3461 echo important >expect &&
3462 test_cmp expect y/c
@@ -3474,37 +3514,50 @@ test_expect_success '10d: Delete untracked with dir rename/rename(2to1)' '
3514 echo important >y/wham &&
3515
3516 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
3477 - test_i18ngrep "CONFLICT (rename/rename)" out &&
3478 - test_i18ngrep "Refusing to lose untracked file at y/wham" out &&
3517 + if test "$GIT_TEST_MERGE_ALGORITHM" = ort
3518 + then
3519 + test_path_is_missing .git/MERGE_HEAD &&
3520 + test_i18ngrep "error: The following untracked working tree files would be overwritten by merge" err &&
3521
3480 - git ls-files -s >out &&
3481 - test_line_count = 6 out &&
3482 - git ls-files -u >out &&
3483 - test_line_count = 2 out &&
3484 - git ls-files -o >out &&
3485 - test_line_count = 3 out &&
3522 + git ls-files -s >out &&
3523 + test_line_count = 6 out &&
3524 + git ls-files -u >out &&
3525 + test_line_count = 0 out &&
3526 + git ls-files -o >out &&
3527 + test_line_count = 3 out
3528 + else
3529 + test_i18ngrep "CONFLICT (rename/rename)" out &&
3530 + test_i18ngrep "Refusing to lose untracked file at y/wham" out &&
3531
3487 - git rev-parse >actual \
3488 - :0:y/a :0:y/b :0:y/d :0:y/e :2:y/wham :3:y/wham &&
3489 - git rev-parse >expect \
3490 - O:z/a O:z/b O:x/d O:x/e O:z/c O:x/f &&
3491 - test_cmp expect actual &&
3532 + git ls-files -s >out &&
3533 + test_line_count = 6 out &&
3534 + git ls-files -u >out &&
3535 + test_line_count = 2 out &&
3536 + git ls-files -o >out &&
3537 + test_line_count = 3 out &&
3538 +
3539 + git rev-parse >actual \
3540 + :0:y/a :0:y/b :0:y/d :0:y/e :2:y/wham :3:y/wham &&
3541 + git rev-parse >expect \
3542 + O:z/a O:z/b O:x/d O:x/e O:z/c O:x/f &&
3543 + test_cmp expect actual &&
3544
3493 - test_must_fail git rev-parse :1:y/wham &&
3545 + test_must_fail git rev-parse :1:y/wham &&
3546
3495 - echo important >expect &&
3496 - test_cmp expect y/wham &&
3547 + # Test that two-way merge in y/wham~merged is as expected
3548 + git cat-file -p :2:y/wham >expect &&
3549 + git cat-file -p :3:y/wham >other &&
3550 + >empty &&
3551 + test_must_fail git merge-file \
3552 + -L "HEAD" \
3553 + -L "" \
3554 + -L "B^0" \
3555 + expect empty other &&
3556 + test_cmp expect y/wham~merged
3557 + fi &&
3558
3498 - # Test that the two-way merge in y/wham~merged is as expected
3499 - git cat-file -p :2:y/wham >expect &&
3500 - git cat-file -p :3:y/wham >other &&
3501 - >empty &&
3502 - test_must_fail git merge-file \
3503 - -L "HEAD" \
3504 - -L "" \
3505 - -L "B^0" \
3506 - expect empty other &&
3507 - test_cmp expect y/wham~merged
3559 + echo important >expect &&
3560 + test_cmp expect y/wham
3561 )
3562 '
3563