merge tests: expect improved directory/file conflict handling in ort

merge-recursive.c is built on the idea of running unpack_trees() and
then "doing minor touch-ups" to get the result.  Unfortunately,
unpack_trees() was run in an update-as-it-goes mode, leading
merge-recursive.c to follow suit and end up with an immediate evaluation
and fix-it-up-as-you-go design.  Some things like directory/file
conflicts are not well representable in the index data structure, and
required special extra code to handle.  But then when it was discovered
that rename/delete conflicts could also be involved in directory/file
conflicts, the special directory/file conflict handling code had to be
copied to the rename/delete codepath.  ...and then it had to be copied
for modify/delete, and for rename/rename(1to2) conflicts, ...and yet it
still missed some.  Further, when it was discovered that there were also
file/submodule conflicts and submodule/directory conflicts, we needed to
copy the special submodule handling code to all the special cases
throughout the codebase.

And then it was discovered that our handling of directory/file conflicts
was suboptimal because it would create untracked files to store the
contents of the conflicting file, which would not be cleaned up if
someone were to run a 'git merge --abort' or 'git rebase --abort'.  It
was also difficult or scary to try to add or remove the index entries
corresponding to these files given the directory/file conflict in the
index.  But changing merge-recursive.c to handle these correctly was a
royal pain because there were so many sites in the code with similar but
not identical code for handling directory/file/submodule conflicts that
would all need to be updated.

I have worked hard to push all directory/file/submodule conflict
handling in merge-ort through a single codepath, and avoid creating
untracked files for storing tracked content (it does record things at
alternate paths, but makes sure they have higher-order stages in the
index).

Since updating merge-recursive is too much work and we don't want to
destabilize it, instead update the testsuite to have different
expectations for relevant directory/file/submodule conflict tests.

Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Elijah Newren
2020-10-26 17:01:37 +00:00
committed by Junio C Hamano
parent f06481f127
commit ef52778708
6 changed files with 308 additions and 102 deletions

View File

@ -397,7 +397,12 @@ test_expect_success 'Rename+D/F conflict; renamed file cannot merge and dir in t
test_must_fail git merge --strategy=recursive dir-in-way &&
test 5 -eq "$(git ls-files -u | wc -l)" &&
test 3 -eq "$(git ls-files -u dir | grep -v file-in-the-way | wc -l)" &&
if test "$GIT_TEST_MERGE_ALGORITHM" = ort
then
test 3 -eq "$(git ls-files -u dir~HEAD | wc -l)"
else
test 3 -eq "$(git ls-files -u dir | grep -v file-in-the-way | wc -l)"
fi &&
test 2 -eq "$(git ls-files -u dir/file-in-the-way | wc -l)" &&
test_must_fail git diff --quiet &&
@ -415,7 +420,12 @@ test_expect_success 'Same as previous, but merged other way' '
test_must_fail git merge --strategy=recursive renamed-file-has-conflicts &&
test 5 -eq "$(git ls-files -u | wc -l)" &&
test 3 -eq "$(git ls-files -u dir | grep -v file-in-the-way | wc -l)" &&
if test "$GIT_TEST_MERGE_ALGORITHM" = ort
then
test 3 -eq "$(git ls-files -u dir~renamed-file-has-conflicts | wc -l)"
else
test 3 -eq "$(git ls-files -u dir | grep -v file-in-the-way | wc -l)"
fi &&
test 2 -eq "$(git ls-files -u dir/file-in-the-way | wc -l)" &&
test_must_fail git diff --quiet &&
@ -471,7 +481,12 @@ test_expect_success 'both rename source and destination involved in D/F conflict
git checkout -q rename-dest^0 &&
test_must_fail git merge --strategy=recursive source-conflict &&
test 1 -eq "$(git ls-files -u | wc -l)" &&
if test "$GIT_TEST_MERGE_ALGORITHM" = ort
then
test 2 -eq "$(git ls-files -u | wc -l)"
else
test 1 -eq "$(git ls-files -u | wc -l)"
fi &&
test_must_fail git diff --quiet &&
@ -505,34 +520,63 @@ test_expect_success 'setup pair rename to parent of other (D/F conflicts)' '
git commit -m "Rename one/file -> two"
'
test_expect_success 'pair rename to parent of other (D/F conflicts) w/ untracked dir' '
git checkout -q rename-one^0 &&
mkdir one &&
test_must_fail git merge --strategy=recursive rename-two &&
if test "$GIT_TEST_MERGE_ALGORITHM" = ort
then
test_expect_success 'pair rename to parent of other (D/F conflicts) w/ untracked dir' '
git checkout -q rename-one^0 &&
mkdir one &&
test_must_fail git merge --strategy=recursive rename-two &&
test 2 -eq "$(git ls-files -u | wc -l)" &&
test 1 -eq "$(git ls-files -u one | wc -l)" &&
test 1 -eq "$(git ls-files -u two | wc -l)" &&
test 4 -eq "$(git ls-files -u | wc -l)" &&
test 2 -eq "$(git ls-files -u one | wc -l)" &&
test 2 -eq "$(git ls-files -u two | wc -l)" &&
test_must_fail git diff --quiet &&
test_must_fail git diff --quiet &&
test 4 -eq $(find . | grep -v .git | wc -l) &&
test 3 -eq $(find . | grep -v .git | wc -l) &&
test_path_is_dir one &&
test_path_is_file one~rename-two &&
test_path_is_file two &&
test "other" = $(cat one~rename-two) &&
test "stuff" = $(cat two)
'
test_path_is_file one &&
test_path_is_file two &&
test "other" = $(cat one) &&
test "stuff" = $(cat two)
'
else
test_expect_success 'pair rename to parent of other (D/F conflicts) w/ untracked dir' '
git checkout -q rename-one^0 &&
mkdir one &&
test_must_fail git merge --strategy=recursive rename-two &&
test 2 -eq "$(git ls-files -u | wc -l)" &&
test 1 -eq "$(git ls-files -u one | wc -l)" &&
test 1 -eq "$(git ls-files -u two | wc -l)" &&
test_must_fail git diff --quiet &&
test 4 -eq $(find . | grep -v .git | wc -l) &&
test_path_is_dir one &&
test_path_is_file one~rename-two &&
test_path_is_file two &&
test "other" = $(cat one~rename-two) &&
test "stuff" = $(cat two)
'
fi
test_expect_success 'pair rename to parent of other (D/F conflicts) w/ clean start' '
git reset --hard &&
git clean -fdqx &&
test_must_fail git merge --strategy=recursive rename-two &&
test 2 -eq "$(git ls-files -u | wc -l)" &&
test 1 -eq "$(git ls-files -u one | wc -l)" &&
test 1 -eq "$(git ls-files -u two | wc -l)" &&
if test "$GIT_TEST_MERGE_ALGORITHM" = ort
then
test 4 -eq "$(git ls-files -u | wc -l)" &&
test 2 -eq "$(git ls-files -u one | wc -l)" &&
test 2 -eq "$(git ls-files -u two | wc -l)"
else
test 2 -eq "$(git ls-files -u | wc -l)" &&
test 1 -eq "$(git ls-files -u one | wc -l)" &&
test 1 -eq "$(git ls-files -u two | wc -l)"
fi &&
test_must_fail git diff --quiet &&
@ -572,12 +616,22 @@ test_expect_success 'check handling of differently renamed file with D/F conflic
git checkout -q first-rename^0 &&
test_must_fail git merge --strategy=recursive second-rename &&
test 5 -eq "$(git ls-files -s | wc -l)" &&
test 3 -eq "$(git ls-files -u | wc -l)" &&
test 1 -eq "$(git ls-files -u one | wc -l)" &&
test 1 -eq "$(git ls-files -u two | wc -l)" &&
test 1 -eq "$(git ls-files -u original | wc -l)" &&
test 2 -eq "$(git ls-files -o | wc -l)" &&
if test "$GIT_TEST_MERGE_ALGORITHM" = ort
then
test 5 -eq "$(git ls-files -s | wc -l)" &&
test 3 -eq "$(git ls-files -u | wc -l)" &&
test 1 -eq "$(git ls-files -u one~HEAD | wc -l)" &&
test 1 -eq "$(git ls-files -u two~second-rename | wc -l)" &&
test 1 -eq "$(git ls-files -u original | wc -l)" &&
test 0 -eq "$(git ls-files -o | wc -l)"
else
test 5 -eq "$(git ls-files -s | wc -l)" &&
test 3 -eq "$(git ls-files -u | wc -l)" &&
test 1 -eq "$(git ls-files -u one | wc -l)" &&
test 1 -eq "$(git ls-files -u two | wc -l)" &&
test 1 -eq "$(git ls-files -u original | wc -l)" &&
test 2 -eq "$(git ls-files -o | wc -l)"
fi &&
test_path_is_file one/file &&
test_path_is_file two/file &&