Subject: bug#52349: 29.0.50; vc-git and diff-mode: stage hunks

From: Juri Linkov <[email-masked]>
Date: Sun, 13 Feb 2022 21:56:28 +0200

>> There is a new problem however.  After starting vc-log-edit from *vc-diff*,
>> and using log-edit-show-diff, it reuses the original buffer *vc-diff*.
>> This is not a problem, because the buffer-local variable ‘vc-patch-string’
>> is saved in the *vc-log* buffer.  But after deleting *vc-diff*, log-edit-done
>> fails on the deleted vc-parent-buffer with
>>    Debugger entered--Lisp error: (error "Selecting deleted buffer")
>>      vc-finish-logentry()
>>      funcall-interactively(vc-finish-logentry)
>>      log-edit-done()
>> But this is an old problem.  The same error is signaled
>> after typing ‘v’ in *vc-dir* buffer, then deleting the
>> original *vc-dir* buffer, and trying to type ‘C-c C-c’
>> (log-edit-done) in the *vc-log* buffer.
>
> Seems like a slightly different issue, though. Speaking of myself only,
> I can see myself casually killing the vc-diff buffer (especially if I just
> displayed it with C-c C-d), but it seems less likely that I would kill the
> vc-dir buffer when completing the commit.
>
> I suppose 'vc-diff-patch' could use a different buffer name than
> "*vc-diff*" and thus avoid reusing that buffer?
>
> If it brings other problems somehow, oh well. An old bug is something we
> can live with.

Indeed, other buffer names might break user configuration.

> But also note that if the patch string was passed as an argument to the
> backend action, this problem might be avoided as well.

I can't imagine how the problem might be avoided using an argument.
The problem is in these lines in vc-finish-logentry:

    (pop-to-buffer vc-parent-buffer)
    ;; OK, do it to it
    (save-excursion
      (funcall log-operation
	       log-fileset
	       log-entry))

It expects to pop to the original buffer where vc-next-action was initiated.