diff --git a/builtin/merge.c b/builtin/merge.c index 788a6b0cd55334..d44c14a21a3b30 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -1709,6 +1709,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix) else fprintf(stderr, _("Merge with strategy %s failed.\n"), use_strategies[0]->name); + apply_autostash(git_path_merge_autostash(the_repository)); ret = 2; goto done; } else if (best_strategy == wt_strategy) diff --git a/t/t7600-merge.sh b/t/t7600-merge.sh index 216113d3537de8..2ef39d3088e806 100755 --- a/t/t7600-merge.sh +++ b/t/t7600-merge.sh @@ -732,6 +732,14 @@ test_expect_success 'octopus merge with --autostash' ' test_cmp result.1-3-5-9 file ' +test_expect_success 'failed merge (exit 2) with --autostash' ' + git reset --hard c1 && + git merge-file file file.orig file.5 && + test_must_fail git merge -s recursive --autostash c2 c3 2>err && + test_i18ngrep "Applied autostash." err && + test_cmp result.1-5 file +' + test_expect_success 'conflicted merge with --autostash, --abort restores stash' ' git reset --hard c3 && cp file.1 file &&