]> git.ipfire.org Git - thirdparty/git.git/commitdiff
merge: avoid write merge state when unable to write index
authorKyle Zhao <kylezhao@tencent.com>
Mon, 17 Jun 2024 03:08:37 +0000 (03:08 +0000)
committerJunio C Hamano <gitster@pobox.com>
Tue, 18 Jun 2024 15:13:35 +0000 (08:13 -0700)
Writing the merge state after the index write fails is meaningless and
could potentially cause Git to lose changes.

Signed-off-by: Kyle Zhao <kylezhao@tencent.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/merge.c
t/t7600-merge.sh

index fb3eb15b8955661586eeb76bc59d4532354739a9..888166d60446aec4db48a802b120a25691a02e34 100644 (file)
@@ -703,7 +703,7 @@ static int try_merge_strategy(const char *strategy, struct commit_list *common,
        if (repo_refresh_and_write_index(the_repository, REFRESH_QUIET,
                                         SKIP_IF_UNCHANGED, 0, NULL, NULL,
                                         NULL) < 0)
-               return error(_("Unable to write index."));
+               die(_("Unable to write index."));
 
        if (!strcmp(strategy, "recursive") || !strcmp(strategy, "subtree") ||
            !strcmp(strategy, "ort")) {
index e5ff073099a983d0da7205d3a3325af28caf8a9b..ef54cff4faa8d3916111a47fae48aee847323d46 100755 (executable)
@@ -236,6 +236,16 @@ test_expect_success 'merge c1 with c2' '
        verify_parents $c1 $c2
 '
 
+test_expect_success 'merge c1 with c2 when index.lock exists' '
+       test_when_finished rm .git/index.lock &&
+       git reset --hard c1 &&
+       >.git/index.lock &&
+       test_must_fail git merge c2 &&
+       test_path_is_missing .git/MERGE_HEAD &&
+       test_path_is_missing .git/MERGE_MODE &&
+       test_path_is_missing .git/MERGE_MSG
+'
+
 test_expect_success 'merge --squash c3 with c7' '
        git reset --hard c3 &&
        test_must_fail git merge --squash c7 &&