{"thread":{"id":"57899","subject":"[PATCH] t6424: make sure a failed merge preserves local changes","startedAt":"2022-05-19T19:00:05Z","lastAt":"2022-05-19T19:00:05Z","messageCount":1,"participants":["Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"455526","messageId":"xmqqbkvtnyae.fsf@gitster.g","threadId":"57899","inReplyTo":null,"subject":"[PATCH] t6424: make sure a failed merge preserves local changes","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2022-05-19T18:59:53Z","receivedAt":"2022-05-19T19:00:05Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"We do make sure that an attempt to merge with various forms of local\nchanges will \"fail\", but the point of stopping the merge is so that\nwe refrain from discarding uncommitted local changes that could be\nprecious.  Add a few more checks for each case to make sure the\nlocal changes are left intact.\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n\n * A recent \"should failing 'git merge' clean the mess _it_\n   created?\" topic was over-eager to clean _all_ local changes, but\n   we didn't seem to have any test to protect against such breakage.\n\n t/t6424-merge-unrelated-index-changes.sh | 32 ++++++++++++++++++++++--\n 1 file changed, 30 insertions(+), 2 deletions(-)\n\ndiff --git a/t/t6424-merge-unrelated-index-changes.sh b/t/t6424-merge-unrelated-index-changes.sh\nindex 89dd544f38..b6e424a427 100755\n--- a/t/t6424-merge-unrelated-index-changes.sh\n+++ b/t/t6424-merge-unrelated-index-changes.sh\n@@ -71,7 +71,9 @@ test_expect_success 'ff update' '\n \tgit merge E^0 &&\n \n \ttest_must_fail git rev-parse HEAD:random_file &&\n-\ttest \"$(git diff --name-only --cached E)\" = \"random_file\"\n+\ttest \"$(git diff --name-only --cached E)\" = \"random_file\" &&\n+\ttest_path_is_file random_file &&\n+\tgit rev-parse --verify :random_file\n '\n \n test_expect_success 'ff update, important file modified' '\n@@ -83,6 +85,8 @@ test_expect_success 'ff update, important file modified' '\n \tgit add subdir/e &&\n \n \ttest_must_fail git merge E^0 &&\n+\ttest_path_is_file subdir/e &&\n+\tgit rev-parse --verify :subdir/e &&\n \ttest_path_is_missing .git/MERGE_HEAD\n '\n \n@@ -93,6 +97,8 @@ test_expect_success 'resolve, trivial' '\n \ttouch random_file && git add random_file &&\n \n \ttest_must_fail git merge -s resolve C^0 &&\n+\ttest_path_is_file random_file &&\n+\tgit rev-parse --verify :random_file &&\n \ttest_path_is_missing .git/MERGE_HEAD\n '\n \n@@ -103,6 +109,8 @@ test_expect_success 'resolve, non-trivial' '\n \ttouch random_file && git add random_file &&\n \n \ttest_must_fail git merge -s resolve D^0 &&\n+\ttest_path_is_file random_file &&\n+\tgit rev-parse --verify :random_file &&\n \ttest_path_is_missing .git/MERGE_HEAD\n '\n \n@@ -113,6 +121,8 @@ test_expect_success 'recursive' '\n \ttouch random_file && git add random_file &&\n \n \ttest_must_fail git merge -s recursive C^0 &&\n+\ttest_path_is_file random_file &&\n+\tgit rev-parse --verify :random_file &&\n \ttest_path_is_missing .git/MERGE_HEAD\n '\n \n@@ -145,9 +155,12 @@ test_expect_success 'recursive, when file has staged changes not matching HEAD n\n \tmkdir subdir &&\n \ttest_seq 1 10 >subdir/a &&\n \tgit add subdir/a &&\n+\tgit rev-parse --verify :subdir/a >expect &&\n \n \t# We have staged changes; merge should error out\n \ttest_must_fail git merge -s recursive E^0 2>err &&\n+\tgit rev-parse --verify :subdir/a >actual &&\n+\ttest_cmp expect actual &&\n \ttest_i18ngrep \"changes to the following files would be overwritten\" err\n '\n \n@@ -158,9 +171,12 @@ test_expect_success 'recursive, when file has staged changes matching what a mer\n \tmkdir subdir &&\n \ttest_seq 1 11 >subdir/a &&\n \tgit add subdir/a &&\n+\tgit rev-parse --verify :subdir/a >expect &&\n \n \t# We have staged changes; merge should error out\n \ttest_must_fail git merge -s recursive E^0 2>err &&\n+\tgit rev-parse --verify :subdir/a >actual &&\n+\ttest_cmp expect actual &&\n \ttest_i18ngrep \"changes to the following files would be overwritten\" err\n '\n \n@@ -171,7 +187,9 @@ test_expect_success 'octopus, unrelated file touched' '\n \ttouch random_file && git add random_file &&\n \n \ttest_must_fail git merge C^0 D^0 &&\n-\ttest_path_is_missing .git/MERGE_HEAD\n+\ttest_path_is_missing .git/MERGE_HEAD &&\n+\tgit rev-parse --verify :random_file &&\n+\ttest_path_exists random_file\n '\n \n test_expect_success 'octopus, related file removed' '\n@@ -181,6 +199,8 @@ test_expect_success 'octopus, related file removed' '\n \tgit rm b &&\n \n \ttest_must_fail git merge C^0 D^0 &&\n+\ttest_path_is_missing b &&\n+\ttest_must_fail git rev-parse --verify :b &&\n \ttest_path_is_missing .git/MERGE_HEAD\n '\n \n@@ -189,8 +209,12 @@ test_expect_success 'octopus, related file modified' '\n \tgit checkout B^0 &&\n \n \techo 12 >>a && git add a &&\n+\tgit rev-parse --verify :a >expect &&\n \n \ttest_must_fail git merge C^0 D^0 &&\n+\ttest_path_is_file a &&\n+\tgit rev-parse --verify :a >actual &&\n+\ttest_cmp expect actual &&\n \ttest_path_is_missing .git/MERGE_HEAD\n '\n \n@@ -201,6 +225,8 @@ test_expect_success 'ours' '\n \ttouch random_file && git add random_file &&\n \n \ttest_must_fail git merge -s ours C^0 &&\n+\ttest_path_is_file random_file &&\n+\tgit rev-parse --verify :random_file &&\n \ttest_path_is_missing .git/MERGE_HEAD\n '\n \n@@ -211,6 +237,8 @@ test_expect_success 'subtree' '\n \ttouch random_file && git add random_file &&\n \n \ttest_must_fail git merge -s subtree E^0 &&\n+\ttest_path_is_file random_file &&\n+\tgit rev-parse --verify :random_file &&\n \ttest_path_is_missing .git/MERGE_HEAD\n '\n \n-- \n2.36.1-387-g2cf831bf19\n\n"}]}