Git development
 help / color / mirror / Atom feed
From: Phillip Wood <phillip.wood123@gmail.com>
To: "D. Ben Knoble" <ben.knoble@gmail.com>, Eli Barzilay <eli@barzilay.org>
Cc: git <git@vger.kernel.org>
Subject: Re: [BUG] stash.index=true leaves a redundant stash entry after an autostash fast-forward
Date: Wed, 16 Sep 2026 14:35:26 +0100	[thread overview]
Message-ID: <56991232-5d16-41d1-9c7d-ca7ebdd9fce7@gmail.com> (raw)
In-Reply-To: <CALnO6CCkq7mjBUKxOYcwKX8=SrH441FuWopoGZutPk99JRTGUA@mail.gmail.com>

Hi Ben

On 15/09/2026 22:16, D. Ben Knoble wrote:
> 
> I'm experimenting with something that swaps that out for a call to
> reset_working_tree(), but I don't think I've gotten it quite right for
> this bug yet (let alone run other test cases that might be affected by
> this change).

It looks like stash has its own unpack_trees() wrapper, so I think the 
simplest fix is to replace reset_head() with

	reset_tree(&c_tree, 0, 1);

Taking a step back, this code applies the stashed index changes into the 
current index, writes the result to a tree and then resets the index to 
HEAD. We could avoid touching the index at all if we used 
merge_incore_nonrecursive() to cherry pick the index changes instead. 
That way we'd get a proper three-way merge and avoid spawning 
subprocesses for "git diff-tree", "git apply --cached", and "git reset". 
We're already using merge_ort_nonrecursive() to merge the working tree 
changes in that function so we have nearly everything we need already 
set up to merge the index changes as well. Essentially, when merging the 
index, we just need to call merge_incore_nonrecursive() instead of 
merge_ort_nonrecursive() and use info->i_tree instead of info->w_tree.

> BTW, it's really weird to me that the reset manual doesn't mention all
> these "extra" cleanups reset does via remove_merge_branch_state()!

Agreed, I think it comes from "git foo --abort" calling "git reset 
(--merge|--hard)" though that doesn't really explain why a mixed reset 
also removes the branch state.

Thanks

Phillip
>> Possible directions, in case they are useful: remove_merge_branch_state()
>> is about ending a merge, and `git stash apply --index` is not ending
>> one -- having stash's reset_head() avoid the branch-state cleanup, or
>> teaching an in-flight autostash apply to shield MERGE_AUTOSTASH, would
>> both close it.  Making apply_save_autostash_ref() tolerate a missing
>> ref would silence the error but leave the duplicate entry.
> 
> I also thought briefly about disabling stash.index for a merge
> autostash, but that's really papering over things, I think.
> 
> I'll keep noodling on this (hopefully tomorrow morning), but in the
> meantime input from others welcome :)
> 


  reply	other threads:[~2026-09-16 13:35 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-07  4:44 [BUG] stash.index=true leaves a redundant stash entry after an autostash fast-forward Eli Barzilay
2026-09-15 21:16 ` D. Ben Knoble
2026-09-16 13:35   ` Phillip Wood [this message]
2026-09-16 14:30     ` Ben Knoble
2026-09-16 19:57       ` Eli Barzilay
2026-09-17 12:04         ` D. Ben Knoble
2026-09-17  9:24       ` Phillip Wood
2026-09-17 13:15         ` D. Ben Knoble
2026-09-17 15:55           ` Phillip Wood
2026-09-19 15:22             ` Phillip Wood
2026-09-19 20:02             ` D. Ben Knoble
2026-09-19 21:32           ` D. Ben Knoble

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=56991232-5d16-41d1-9c7d-ca7ebdd9fce7@gmail.com \
    --to=phillip.wood123@gmail.com \
    --cc=ben.knoble@gmail.com \
    --cc=eli@barzilay.org \
    --cc=git@vger.kernel.org \
    --cc=phillip.wood@dunelm.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox