Skip to content

Commit 3a47790

Browse files
committed
Merge branch 'en/merge-unstash-only-on-clean-merge'
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 d528044 + d3a9295 commit 3a47790

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
@@ -503,7 +503,8 @@ static void finish(struct commit *head_commit,
503503
/* Run a post-merge hook */
504504
run_hooks_l("post-merge", squash ? "1" : "0", NULL);
505505

506-
apply_autostash(git_path_merge_autostash(the_repository));
506+
if (new_head)
507+
apply_autostash(git_path_merge_autostash(the_repository));
507508
strbuf_release(&reflog_message);
508509
}
509510

@@ -1781,6 +1782,8 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
17811782
"stopped before committing as requested\n"));
17821783
else
17831784
ret = suggest_conflicts();
1785+
if (autostash)
1786+
printf(_("When finished, apply stashed changes with `git stash pop`\n"));
17841787

17851788
done:
17861789
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)