From 594a8673f227e9a00b3b0c4d6a26c97d68651666 Mon Sep 17 00:00:00 2001 From: Elijah Newren Date: Tue, 10 Jul 2018 20:56:57 -0700 Subject: t7405: add a file/submodule conflict In the case of a file/submodule conflict, although both cannot exist at the same path, we expect both to be present somewhere for the user to be able to resolve the conflict with. Add a testcase for this. Signed-off-by: Elijah Newren Signed-off-by: Junio C Hamano --- t/t7405-submodule-merge.sh | 54 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/t/t7405-submodule-merge.sh b/t/t7405-submodule-merge.sh index 7bfb2f498d..62888c2c51 100755 --- a/t/t7405-submodule-merge.sh +++ b/t/t7405-submodule-merge.sh @@ -279,4 +279,58 @@ test_expect_success 'recursive merge with submodule' ' grep "$(cat expect3)" actual > /dev/null) ' +# File/submodule conflict +# Commit O: +# Commit A: path (submodule) +# Commit B: path +# Expected: path/ is submodule and file contents for B's path are somewhere + +test_expect_success 'setup file/submodule conflict' ' + test_create_repo file-submodule && + ( + cd file-submodule && + + git commit --allow-empty -m O && + + git branch A && + git branch B && + + git checkout B && + echo content >path && + git add path && + git commit -m B && + + git checkout A && + test_create_repo path && + test_commit -C path world && + git submodule add ./path && + git commit -m A + ) +' + +test_expect_failure 'file/submodule conflict' ' + test_when_finished "git -C file-submodule reset --hard" && + ( + cd file-submodule && + + git checkout A^0 && + test_must_fail git merge B^0 && + + git ls-files -s >out && + test_line_count = 3 out && + git ls-files -u >out && + test_line_count = 2 out && + + # path/ is still a submodule + test_path_is_dir path/.git && + + # There is a submodule at "path", so B:path cannot be written + # there. We expect it to be written somewhere in the same + # directory, though, so just grep for its content in all + # files, and ignore "grep: path: Is a directory" message + echo Checking if contents from B:path showed up anywhere && + grep -q content * 2>/dev/null + ) +' + test_done -- cgit v1.2.3 From e81c7d414588e92e3bf871fe6c78a32176dcf995 Mon Sep 17 00:00:00 2001 From: Elijah Newren Date: Tue, 10 Jul 2018 20:56:58 -0700 Subject: t7405: add a directory/submodule conflict For a directory/submodule conflict, we want contents from both the directory and the submodule to be present for the user to use to resolve the conflict, but we do not want paths under the directory being written into the submodule and we do not want the merge being confused by paths under the submodule being in the way. Add testcases for these situations. Signed-off-by: Elijah Newren Signed-off-by: Junio C Hamano --- t/t7405-submodule-merge.sh | 88 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) diff --git a/t/t7405-submodule-merge.sh b/t/t7405-submodule-merge.sh index 62888c2c51..45d1779d29 100755 --- a/t/t7405-submodule-merge.sh +++ b/t/t7405-submodule-merge.sh @@ -333,4 +333,92 @@ test_expect_failure 'file/submodule conflict' ' ) ' +# Directory/submodule conflict +# Commit O: +# Commit A: path (submodule), with sole tracked file named 'world' +# Commit B1: path/file +# Commit B2: path/world +# +# Expected from merge of A & B1: +# Contents under path/ from commit B1 are renamed elsewhere; we do not +# want to write files from one of our tracked directories into a submodule +# +# Expected from merge of A & B2: +# Similar to last merge, but with a slight twist: we don't want paths +# under the submodule to be treated as untracked or in the way. + +test_expect_success 'setup directory/submodule conflict' ' + test_create_repo directory-submodule && + ( + cd directory-submodule && + + git commit --allow-empty -m O && + + git branch A && + git branch B1 && + git branch B2 && + + git checkout B1 && + mkdir path && + echo contents >path/file && + git add path/file && + git commit -m B1 && + + git checkout B2 && + mkdir path && + echo contents >path/world && + git add path/world && + git commit -m B2 && + + git checkout A && + test_create_repo path && + test_commit -C path hello world && + git submodule add ./path && + git commit -m A + ) +' + +test_expect_failure 'directory/submodule conflict; keep submodule clean' ' + test_when_finished "git -C directory-submodule reset --hard" && + ( + cd directory-submodule && + + git checkout A^0 && + test_must_fail git merge B1^0 && + + git ls-files -s >out && + test_line_count = 3 out && + git ls-files -u >out && + test_line_count = 1 out && + + # path/ is still a submodule + test_path_is_dir path/.git && + + echo Checking if contents from B1:path/file showed up && + # Would rather use grep -r, but that is GNU extension... + git ls-files -co | xargs grep -q contents 2>/dev/null && + + # However, B1:path/file should NOT have shown up at path/file, + # because we should not write into the submodule + test_path_is_missing path/file + ) +' + +test_expect_failure 'directory/submodule conflict; should not treat submodule files as untracked or in the way' ' + test_when_finished "git -C directory-submodule/path reset --hard" && + test_when_finished "git -C directory-submodule reset --hard" && + ( + cd directory-submodule && + + git checkout A^0 && + test_must_fail git merge B2^0 >out 2>err && + + # We do not want files within the submodule to prevent the + # merge from starting; we should not be writing to such paths + # anyway. + test_i18ngrep ! "refusing to lose untracked file at" err + + ) +' + test_done -- cgit v1.2.3 From 587421ebddec17e6e9aaf55b61aa40ad4ad9e43e Mon Sep 17 00:00:00 2001 From: Elijah Newren Date: Tue, 10 Jul 2018 20:56:59 -0700 Subject: t7405: verify 'merge --abort' works after submodule/path conflicts Signed-off-by: Elijah Newren Signed-off-by: Junio C Hamano --- t/t7405-submodule-merge.sh | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/t/t7405-submodule-merge.sh b/t/t7405-submodule-merge.sh index 45d1779d29..7855bd8648 100755 --- a/t/t7405-submodule-merge.sh +++ b/t/t7405-submodule-merge.sh @@ -333,6 +333,19 @@ test_expect_failure 'file/submodule conflict' ' ) ' +test_expect_success 'file/submodule conflict; merge --abort works afterward' ' + test_when_finished "git -C file-submodule reset --hard" && + ( + cd file-submodule && + + git checkout A^0 && + test_must_fail git merge B^0 >out 2>err && + + test_path_is_file .git/MERGE_HEAD && + git merge --abort + ) +' + # Directory/submodule conflict # Commit O: # Commit A: path (submodule), with sole tracked file named 'world' @@ -417,7 +430,25 @@ test_expect_failure 'directory/submodule conflict; should not treat submodule fi # merge from starting; we should not be writing to such paths # anyway. test_i18ngrep ! "refusing to lose untracked file at" err + ) +' + +test_expect_failure 'directory/submodule conflict; merge --abort works afterward' ' + test_when_finished "git -C directory-submodule/path reset --hard" && + test_when_finished "git -C directory-submodule reset --hard" && + ( + cd directory-submodule && + git checkout A^0 && + test_must_fail git merge B2^0 && + test_path_is_file .git/MERGE_HEAD && + + # merge --abort should succeed, should clear .git/MERGE_HEAD, + # and should not leave behind any conflicted files + git merge --abort && + test_path_is_missing .git/MERGE_HEAD && + git ls-files -u >conflicts && + test_must_be_empty conflicts ) ' -- cgit v1.2.3