Subject: Re: bug#73387: 30.0.90; C-x v v in diff-mode doesn't work after C-c C-n

From: Dmitry Gutov <[email-masked]>
Date: Tue, 1 Oct 2024 04:15:19 +0300

On 01/10/2024 04:01, Sean Whitton wrote:
> I don't think that's quite right.
 >
> If you use C-c C-n in a diff-mode buffer with current master, then
> C-x v v doesn't get far enough to call the user-error I added.
> "No next file" is not the error message that you should get.

Ah, okay.

Building the list and then not using it feels kind of wasteful, though.

Should we move the check earlier?

I.e. do this (and probably remove it from vc-next-action):

diff --git a/lisp/vc/diff-mode.el b/lisp/vc/diff-mode.el
index 25c6238765d..33bd8b607f7 100644
--- a/lisp/vc/diff-mode.el
+++ b/lisp/vc/diff-mode.el
@@ -3168,6 +3168,17 @@ diff-syntax-fontify-props

  ;;;###autoload
  (defun diff-vc-deduce-fileset ()
+  (when (buffer-narrowed-p)
+    ;; If user used `diff-restrict-view' then we may not have the
+    ;; file header and the commit will not succeed (bug#73387).
+    (user-error "Cannot commit patch when narrowed; consider %s"
+                (mapconcat (lambda (c)
+                             (key-description
+                              (where-is-internal c nil t)))
+                           '(widen
+                             diff-delete-other-hunks
+                             vc-next-action)
+                           " ")))
    (let ((backend (vc-responsible-backend default-directory))
          files)
      (save-excursion