git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] merge --abort: don't delete autostash before reset succeeds

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 8, 2026, 17:46 UTC
Message-ID
<xmqq8q7lv0g5.fsf@gitster.g>
In-Reply-To
<0b7e6d74-0287-4be5-a19f-ed8c5fbc9217@gmail.com>
Phillip Wood <phillip.wood123@gmail.com> writes:
Show 8 quoted lines
> I'm afraid I don't think this is the right solution. We only want to 
> save the stash if there are conflicts when we apply it - that is why 
> MERGE_AUTOSTASH is deleted before we do the reset - we want to prevent 
> remove_branch_state() from saving it. If the stash applies cleanly then 
> we should not save it. If the reset fails then we should keep 
> MERGE_AUTOSTASH along with the other merge state files rather than 
> saving the stash (which is actually what happens after this patch 
> because cmd_reset() dies before it calls remove_branch_state()).

Thanks for pointing it out that reset calls remove_branch_state(), which in turn calls remove_merge_branch_state(), which in turn calls save_autostash_ref(). We end up (when cmd_reset() is successful) applying the autostash (which is good) but also saving a new stash.

> I think the solution is probably to stop calling 
> builtin/reset.c:cmd_reset() and instead ...

Great. In general, it is a bad pattern we should find and fix for cmd_A() to call cmd_B() in its implementation as a subroutine. To clean any such instance is a great thing to do.

Show 9 quoted lines
> ...
> So we only delete MERGE_AUTOSTASH after a successful reset and we only 
> save the stash if it applies with conflicts. That's all a bit more 
> involved than the patch here - please do give me a shout if you want 
> some more information.
>
> Thanks
>
> Phillip
Thanks.
Previous: Phillip Wood
Message 3 of 3 in “merge --abort: don't delete autostash before reset succeeds”
  1. merge --abort: don't delete autostash before reset succeedsKris Point, Jul 8, 2026
  2. Phillip WoodJul 8, 2026
  3. Junio C HamanoJul 8, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.