From 137adb6c1c68521215f3b75b577bee6030b788b8 Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Sat, 15 Mar 2025 16:02:56 +0800 Subject: [PATCH] vc-revert: Offer to save modified buffers (bug#55310) * lisp/vc/vc.el (vc-revert): Offer to save modified buffers that otherwise prevent proceeding with the revert (bug#55310). (cherry picked from commit 6f483ffdc217ea9f8dc079b2344f771214222273) --- lisp/vc/vc.el | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/lisp/vc/vc.el b/lisp/vc/vc.el index a2bd24a2042..dba487aa0a7 100644 --- a/lisp/vc/vc.el +++ b/lisp/vc/vc.el @@ -3241,14 +3241,21 @@ to the working revision (except for keyword expansion)." ;; show the changes and ask for confirmation to discard them. (when (or (not files) (memq (buffer-file-name) files)) (vc-buffer-sync nil)) - (dolist (file files) - (let ((buf (get-file-buffer file))) - (when (and buf (buffer-modified-p buf)) - (error "Please kill or save all modified buffers before reverting"))) - (when (vc-up-to-date-p file) - (if (yes-or-no-p (format "%s seems up-to-date. Revert anyway? " file)) - (setq queried t) - (error "Revert canceled")))) + (save-some-buffers nil (lambda () + (member (buffer-file-name) files))) + (let (needs-save) + (dolist (file files) + (let ((buf (get-file-buffer file))) + (when (and buf (buffer-modified-p buf)) + (push buf needs-save))) + (when (vc-up-to-date-p file) + (if (yes-or-no-p (format "%s seems up-to-date. Revert anyway? " + file)) + (setq queried t) + (error "Revert canceled")))) + (when needs-save + (error "Cannot revert with these buffers unsaved: %s" + (string-join (mapcar #'buffer-name needs-save) ", ")))) (unwind-protect (when (if vc-revert-show-diff (progn -- 2.39.5