Skip to content

Commit 5a2d67a

Browse files
committed
Merge branch 'kz/merge-fail-early-upon-refresh-failure' into jch
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
2 parents c546bcd + 2e5a636 commit 5a2d67a

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

builtin/merge.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,7 @@ static int try_merge_strategy(const char *strategy, struct commit_list *common,
703703
if (repo_refresh_and_write_index(the_repository, REFRESH_QUIET,
704704
SKIP_IF_UNCHANGED, 0, NULL, NULL,
705705
NULL) < 0)
706-
return error(_("Unable to write index."));
706+
die(_("Unable to write index."));
707707

708708
if (!strcmp(strategy, "recursive") || !strcmp(strategy, "subtree") ||
709709
!strcmp(strategy, "ort")) {

t/t7600-merge.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,16 @@ test_expect_success 'merge c1 with c2' '
236236
verify_parents $c1 $c2
237237
'
238238

239+
test_expect_success 'merge c1 with c2 when index.lock exists' '
240+
test_when_finished rm .git/index.lock &&
241+
git reset --hard c1 &&
242+
>.git/index.lock &&
243+
test_must_fail git merge c2 &&
244+
test_path_is_missing .git/MERGE_HEAD &&
245+
test_path_is_missing .git/MERGE_MODE &&
246+
test_path_is_missing .git/MERGE_MSG
247+
'
248+
239249
test_expect_success 'merge --squash c3 with c7' '
240250
git reset --hard c3 &&
241251
test_must_fail git merge --squash c7 &&

0 commit comments

Comments
 (0)