Subject: Re: bug#60126: 30.0.50; vc-git-checkin: Offer to unstage conflicting changes

From: Sean Whitton <[email-masked]>
Date: Tue, 20 Dec 2022 16:10:00 -0700

Hello,

On Tue 20 Dec 2022 at 10:04AM -07, Sean Whitton wrote:

> On Tue 20 Dec 2022 at 05:13PM +02, Dmitry Gutov wrote:
>
>> On 20/12/2022 08:43, Sean Whitton wrote:
>>> So, I'm now thinking:
>>> - automatically stash index+worktree for any files with changes staged
>>>    that are*not*  modified by the patch to be committed
>>
>> I think it's possible to just skip those when checking the index area. And
>> then, when committing, specify individual files to commit from the index.
>
> Ah, so it is!

It turns out this doesn't work: if you specify individual files to
commit from the index, then git also includes any changes to those files
in the worktree too, and you can't ask it not to, because --only is
implied whenever files are supplied on the command line.

In other words, when vc-git-patch-string is non-nil, we mustn't pass a
list of files to git.  So if there are files not involved in the commit
with staged changes, we need to stash those.

I tried implementing that, which is not hard, but then we pop that
stash, the staged changes aren't restored to the index.  The result is
that if the user has a mixture of staged and unstaged changes to a file
which is not part of the commit, then afterwards the unstaged changes
will have been unstaged, mixed in with the staged changes again.  In
some circumstances this could constitute a loss of work.

There are a few ways to overcome this.  We can use the --staged option,
but that's only available in very recent versions of git.  We could
perform a complex double-stash:

- git stash push -k -- foo
- git reset -- foo
- git stash push -k -- foo
- [commit]
- git stash pop
- git add -- foo
- git stash pop

Or we could do something like what Magit does to stash only the index.

Any thoughts on what would be best?

In the meantime, I've pushed a version of my previous patch, as I think
it makes sense to implement the stashing, if we do, as a second change.

-- 
Sean Whitton