Git development
 help / color / mirror / Atom feed
From: Phillip Wood <phillip.wood123@gmail.com>
To: "D. Ben Knoble" <ben.knoble@gmail.com>, phillip.wood@dunelm.org.uk
Cc: Eli Barzilay <eli@barzilay.org>, git <git@vger.kernel.org>
Subject: Re: [BUG] stash.index=true leaves a redundant stash entry after an autostash fast-forward
Date: Sat, 19 Sep 2026 16:22:08 +0100	[thread overview]
Message-ID: <9ae2cb8a-7f2d-4c79-937b-170b8937bd8c@gmail.com> (raw)
In-Reply-To: <44881557-f15e-4ec5-b1c5-4112752f757c@gmail.com>

On 17/09/2026 16:55, Phillip Wood wrote:
> On 17/09/2026 14:15, D. Ben Knoble wrote:
>>> 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);
>>
>> I'm not sure if that is a pre-merge reset, post-merge reset, or
>> something in between.
>> Unfortunately, a whole bunch of tests fail (6 files) with this 
>> suggestion :/
>>
>> Summary of Failures:
>>
>>   339/1062 git:t3904-stash-patch                              ERROR
>>        0.45s   exit status 1
>>   503/1062 git:t3903-stash                                    ERROR
>>        4.40s   exit status 1
>>   763/1062 git:t6424-merge-unrelated-index-changes            ERROR
>>        0.90s   exit status 1
>>   778/1062 git:t6402-merge-rename                             ERROR
>>        2.06s   exit status 1
>>   864/1062 git:t1092-sparse-checkout-compatibility            ERROR
>>       26.19s   exit status 1
>>   868/1062 git:t7611-merge-abort                              ERROR
>>        0.45s   exit status 1
>>
>> It _also_ doesn't make the bug go away, hm.
> 
> Oh, I wonder what's happening there.

So the tests fail because when git tries to merge the stashed worktree 
changes it thinks there are unstaged changes in the worktree. That's 
because when we merge the stashed index changes the stat data and 
CE_UPTODATE flag are cleared for paths that are updated by the merge. 
When we remove those merged changes from the index we need to refresh 
the index to restore the stat data. Adding a call to refresh_index() 
after reset_tree() makes the tests pass.

Anyway that's all a bit irrelevant if we're going to start using 
merge_incore_nonrecursive() but the test failures were bugging me so I 
thought I'd have a look at what was causing them.

Thanks

Phillip


>>>>> 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.
>>
>> If I'm following this, the suggestion is to replace (parts of) the
>> early "if (index)" block with a merge_incore_nonrecursive() to merge
>> index changes, reporting conflicts as we do today, and saving the tree
>> for later… and this would not touch the real index, so we wouldn't
>> have to reset at all? Interesting!
>>
>> The attached patch [Gmail headaches, sorry], which needs some
>> polishing [*], passes tests and fixes the bug! Yahoo. I'll send a
>> series later, tomorrow probably.
>> (It won't apply directly, because it's on top of the experimental
>> reset_tree() version, but resolving conflicts should be easy.)
> 
> I had a quick look at the patch, it looks good, but I think we can 
> simplify it a bit. As we abort if there are conflicts I don't think we 
> need to spend any effort setting the conflict labels (I'm not sure if we 
> can pass NULL, but "" would certainly suffice). Does the current code 
> print any errors from apply when the patch does not apply? If not we 
> should silence the merge by setting verbosity=0. Also I think we should 
> use oidcpy to copy the merged tree (it probably does not matter in this 
> case, but it I think it does some extra checks on the hash function 
> which a simple assignment does not)
> 
> Thanks for working on this, it will be a nice improvement
> 
> Phillip
> 
>> [*] namely, the log message, some tiny first cleanups, and removing
>> now-unused functions
>>
> 


  reply	other threads:[~2026-09-19 15:22 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
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 [this message]
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=9ae2cb8a-7f2d-4c79-937b-170b8937bd8c@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