diff options
Diffstat (limited to 't/t6437-submodule-merge.sh')
-rwxr-xr-x | t/t6437-submodule-merge.sh | 91 |
1 files changed, 79 insertions, 12 deletions
diff --git a/t/t6437-submodule-merge.sh b/t/t6437-submodule-merge.sh index 178413c..7a3f1cb 100755 --- a/t/t6437-submodule-merge.sh +++ b/t/t6437-submodule-merge.sh @@ -8,6 +8,7 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB=1 export GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh . "$TEST_DIRECTORY"/lib-merge.sh @@ -103,8 +104,25 @@ test_expect_success 'setup for merge search' ' echo "file-c" > file-c && git add file-c && git commit -m "sub-c") && - git commit -a -m "c" && + git commit -a -m "c") +' +test_expect_success 'merging should conflict for non fast-forward' ' + test_when_finished "git -C merge-search reset --hard" && + (cd merge-search && + git checkout -b test-nonforward-a b && + if test "$GIT_TEST_MERGE_ALGORITHM" = ort + then + test_must_fail git merge c 2>actual && + sub_expect="go to submodule (sub), and either merge commit $(git -C sub rev-parse --short sub-c)" && + grep "$sub_expect" actual + else + test_must_fail git merge c 2> actual + fi) +' + +test_expect_success 'finish setup for merge-search' ' + (cd merge-search && git checkout -b d a && (cd sub && git checkout -b sub-d sub-b && @@ -129,14 +147,16 @@ test_expect_success 'merge with one side as a fast-forward of the other' ' test_cmp expect actual) ' -test_expect_success 'merging should conflict for non fast-forward' ' +test_expect_success 'merging should conflict for non fast-forward (resolution exists)' ' (cd merge-search && - git checkout -b test-nonforward b && + git checkout -b test-nonforward-b b && (cd sub && - git rev-parse sub-d > ../expect) && + git rev-parse --short sub-d > ../expect) && if test "$GIT_TEST_MERGE_ALGORITHM" = ort then - test_must_fail git merge c >actual + test_must_fail git merge c >actual 2>sub-actual && + sub_expect="go to submodule (sub), and either merge commit $(git -C sub rev-parse --short sub-c)" && + grep "$sub_expect" sub-actual else test_must_fail git merge c 2> actual fi && @@ -161,7 +181,9 @@ test_expect_success 'merging should fail for ambiguous common parent' ' ) && if test "$GIT_TEST_MERGE_ALGORITHM" = ort then - test_must_fail git merge c >actual + test_must_fail git merge c >actual 2>sub-actual && + sub_expect="go to submodule (sub), and either merge commit $(git -C sub rev-parse --short sub-c)" && + grep "$sub_expect" sub-actual else test_must_fail git merge c 2> actual fi && @@ -205,7 +227,12 @@ test_expect_success 'merging should fail for changes that are backwards' ' git commit -a -m "f" && git checkout -b test-backward e && - test_must_fail git merge f) + test_must_fail git merge f 2>actual && + if test "$GIT_TEST_MERGE_ALGORITHM" = ort + then + sub_expect="go to submodule (sub), and either merge commit $(git -C sub rev-parse --short sub-d)" && + grep "$sub_expect" actual + fi) ' @@ -310,7 +337,7 @@ test_expect_success 'recursive merge with submodule' ' # 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 && + git init file-submodule && ( cd file-submodule && @@ -325,7 +352,7 @@ test_expect_success 'setup file/submodule conflict' ' git commit -m B && git checkout A && - test_create_repo path && + git init path && test_commit -C path world && git submodule add ./path && git commit -m A @@ -385,7 +412,7 @@ test_expect_success 'file/submodule conflict; merge --abort works afterward' ' # under the submodule to be treated as untracked or in the way. test_expect_success 'setup directory/submodule conflict' ' - test_create_repo directory-submodule && + git init directory-submodule && ( cd directory-submodule && @@ -408,7 +435,7 @@ test_expect_success 'setup directory/submodule conflict' ' git commit -m B2 && git checkout A && - test_create_repo path && + git init path && test_commit -C path hello world && git submodule add ./path && git commit -m A @@ -453,7 +480,7 @@ test_expect_merge_algorithm failure success !FAIL_PREREQS 'directory/submodule c # 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_grep ! "refusing to lose untracked file at" err ) ' @@ -476,4 +503,44 @@ test_expect_failure 'directory/submodule conflict; merge --abort works afterward ) ' +# Setup: +# - Submodule has 2 commits: a and b +# - Superproject branch 'a' adds and commits submodule pointing to 'commit a' +# - Superproject branch 'b' adds and commits submodule pointing to 'commit b' +# If these two branches are now merged, there is no merge base +test_expect_success 'setup for null merge base' ' + mkdir no-merge-base && + (cd no-merge-base && + git init && + mkdir sub && + (cd sub && + git init && + echo "file-a" > file-a && + git add file-a && + git commit -m "commit a") && + git commit --allow-empty -m init && + git branch init && + git checkout -b a init && + git add sub && + git commit -m "a" && + git switch main && + (cd sub && + echo "file-b" > file-b && + git add file-b && + git commit -m "commit b")) +' + +test_expect_success 'merging should fail with no merge base' ' + (cd no-merge-base && + git checkout -b b init && + git add sub && + git commit -m "b" && + test_must_fail git merge a 2>actual && + if test "$GIT_TEST_MERGE_ALGORITHM" = ort + then + sub_expect="go to submodule (sub), and either merge commit $(git -C sub rev-parse --short HEAD^1)" && + grep "$sub_expect" actual + fi) +' + test_done |