Skip to content

Commit 2c75b32

Browse files
committed
Merge branch 'en/merge-unstash-only-on-clean-merge' into maint
The auto-stashed local changes created by "git merge --autostash" was mixed into a conflicted state left in the working tree, which has been corrected. * en/merge-unstash-only-on-clean-merge: merge: only apply autostash when appropriate
2 parents 4f06dfd + d3a9295 commit 2c75b32

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

builtin/merge.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,8 @@ static void finish(struct commit *head_commit,
493493
/* Run a post-merge hook */
494494
run_hooks_l("post-merge", squash ? "1" : "0", NULL);
495495

496-
apply_autostash(git_path_merge_autostash(the_repository));
496+
if (new_head)
497+
apply_autostash(git_path_merge_autostash(the_repository));
497498
strbuf_release(&reflog_message);
498499
}
499500

@@ -1756,6 +1757,8 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
17561757
"stopped before committing as requested\n"));
17571758
else
17581759
ret = suggest_conflicts();
1760+
if (autostash)
1761+
printf(_("When finished, apply stashed changes with `git stash pop`\n"));
17591762

17601763
done:
17611764
if (!automerge_was_ok) {

t/t7600-merge.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,15 @@ test_expect_success 'merge --squash c3 with c7' '
255255
test_cmp expect actual
256256
'
257257

258+
test_expect_success 'merge --squash --autostash conflict does not attempt to apply autostash' '
259+
git reset --hard c3 &&
260+
>unrelated &&
261+
git add unrelated &&
262+
test_must_fail git merge --squash c7 --autostash >out 2>err &&
263+
! grep "Applying autostash resulted in conflicts." err &&
264+
grep "When finished, apply stashed changes with \`git stash pop\`" out
265+
'
266+
258267
test_expect_success 'merge c3 with c7 with commit.cleanup = scissors' '
259268
git config commit.cleanup scissors &&
260269
git reset --hard c3 &&

0 commit comments

Comments
 (0)