Skip to content

Commit

Permalink
Merge branch 'kz/merge-fail-early-upon-refresh-failure'
Browse files Browse the repository at this point in the history
When "git merge" sees that the index cannot be refreshed (e.g. due
to another process doing the same in the background), it died but
after writing MERGE_HEAD etc. files, which was useless for the
purpose to recover from the failure.

* kz/merge-fail-early-upon-refresh-failure:
  merge: avoid write merge state when unable to write index
  • Loading branch information
gitster committed Jun 27, 2024
2 parents 1e1586e + 2e5a636 commit 6c0bfce
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion builtin/merge.c
Original file line number Diff line number Diff line change
Expand Up @@ -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")) {
Expand Down
10 changes: 10 additions & 0 deletions t/t7600-merge.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down

0 comments on commit 6c0bfce

Please sign in to comment.