Subject: [Bug] Stashing during merge loses MERGING state

From: Tassilo Horn <[email-masked]>
Date: Thu, 11 Mar 2021 15:00:58 +0100

Thank you for filling out a Git bug report!
Please answer the following questions to help us understand your issue.

What did you do before the bug happened? (Steps to reproduce your issue)

I did a large merge, resolved the conflicts but still had compile
errors.  In order to check how stuff has worked before the merge, I
stashed all changes, and eventually popped the stash.  Then the MERGING
state was gone and committing created a single-parent commit rather than
a merge commit with two parents.  I was lucky to see that before
pushing, so all is good.

Here is a simple recipe with a publicly available repo:

```sh
git clone https://github.com/magit/magit.git
# Current master is 4735b9254105eb7dd538f979d8b4c6ab96b827b9
cd magit
git merge origin/km/reshelve-rewrite # currently 0073bff21c826a57a4b48076074bdbba092d4b67
# Conflict in magit-extras.el
git add lisp/magit-extras.el
git stash
# The MERGING state is gone
git stash pop
# And it won't come back, so when I commit now, my "merge" has just
# one parent.
```

What did you expect to happen? (Expected behavior)

I expected that stashing during a merge will keep the MERGING state.
Or that popping the stash again would also restore the MERGING state.

What happened instead? (Actual behavior)

The MERGING state is lost.

What's different between what you expected and what actually happened?

I've lost the MERGING state, thus committing results in a one-parent
commit rather than a 2-parent merge commit.

Anything else you want to add:

In my original situation, I've copied the working tree to /tmp, resetted
to origin/master, re-initiated the merge, copied the modified files from
the /tmp backup, staged the changes, committed, and pushed.

I wonder if there would have been a better approach to come from the
"accidentally having a single-parent commit containing all merged and
resolution changes" state to a proper merge commit state.  In the end,
the tree was correct, just the second parent to the commit on the merged
branch was missing.

Please review the rest of the bug report below.
You can delete any lines you don't wish to share.

[System Info]
git version:
git version 2.30.2
cpu: x86_64
no commit associated with this build
sizeof-long: 8
sizeof-size_t: 8
shell-path: /bin/sh
uname: Linux 5.11.4-arch1-1 #1 SMP PREEMPT Sun, 07 Mar 2021 18:00:49 +0000 x86_64
compiler info: gnuc: 10.2
libc info: glibc: 2.33
$SHELL (typically, interactive shell): /usr/bin/fish

[Enabled Hooks]