Subject: [PATCH] * lisp/vc/vc-dispatcher.el (vc-buffer-sync): Check buffer-file-name

From: Lin Sun <[email-masked]>
Date: Tue, 26 Aug 2025 19:33:58 +0000

Hi,

I got an error when try to revert a buffer:
vc-revert: Wrong type argument: stringp, nil

Here is the backtrace:
Debugger entered--Lisp error: (wrong-type-argument stringp nil)
  vc-buffer-sync(nil)
  vc-revert()
  funcall-interactively(vc-revert)
  command-execute(vc-revert)

It caused by reverting a buffer which has no file name (like create a buffer but not saving it).
 
This patch will check the `` bebuffer-file-name` before call subsequent function.
Please help review the patch, thanks

Best Regards
Lin

From 7aa147e3b2f77efccfe7721c0be003173929541a Mon Sep 17 00:00:00 2001
From: Lin Sun <[email-masked]>
Date: Tue, 26 Aug 2025 06:30:03 +0000
Subject: [PATCH] * lisp/vc/vc-dispatcher.el (vc-buffer-sync): Check
 buffer-file-name

Ensure buffer-file-name is non-nil before passing it to file-exists-p,
preventing a type error when the buffer is not associated with a file.
---
 lisp/vc/vc-dispatcher.el | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lisp/vc/vc-dispatcher.el b/lisp/vc/vc-dispatcher.el
index c4ad148bdf1..c0c413db5d9 100644
--- a/lisp/vc/vc-dispatcher.el
+++ b/lisp/vc/vc-dispatcher.el
@@ -758,7 +758,8 @@ vc-buffer-sync
   (let (missing)
     (when (cond
            ((buffer-modified-p))
-           ((not (file-exists-p buffer-file-name))
+           ((not (and buffer-file-name
+                      (file-exists-p buffer-file-name)))
             (setq missing t)))
       (if (or vc-suppress-confirm
               (y-or-n-p (format "Buffer %s %s; save it? "
-- 
2.34.1