git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 3/4] git.el: Check for existing buffers on revert.

From
AJAlexandre Julliard <julliard@winehq.org>
Date
Feb 7, 2008, 12:51 UTC
Message-ID
<87r6fporp3.fsf@wine.dyndns.org>

Refuse to revert a file if it is modified in an existing buffer but not saved. On success, revert the buffers that contains the files that have been reverted.

Signed-off-by: Alexandre Julliard <julliard@winehq.org>
---
 contrib/emacs/git.el |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)
diff --git a/contrib/emacs/git.el b/contrib/emacs/git.el
index 5519ed1..e1058b9 100644
--- a/contrib/emacs/git.el
+++ b/contrib/emacs/git.el
@@ -1033,11 +1033,19 @@ Return the list of files that haven't been handled."
           ('deleted (push (git-fileinfo->name info) modified))
           ('unmerged (push (git-fileinfo->name info) modified))
           ('modified (push (git-fileinfo->name info) modified))))
+      ;; check if a buffer contains one of the files and isn't saved
+      (dolist (file (append added modified))
+        (let ((buffer (get-file-buffer file)))
+          (when (and buffer (buffer-modified-p buffer))
+            (error "Buffer %s is modified. Please kill or save modified buffers before reverting." (buffer-name buffer)))))
       (when added
         (apply #'git-call-process-env nil nil "update-index" "--force-remove" "--" added))
       (when modified
         (apply #'git-call-process-env nil nil "checkout" "HEAD" modified))
       (git-update-status-files (append added modified) 'uptodate)
+      (dolist (file (append added modified))
+        (let ((buffer (get-file-buffer file)))
+          (when buffer (with-current-buffer buffer (revert-buffer t t t)))))
       (git-success-message "Reverted" (git-get-filenames files)))))
 
 (defun git-resolve-file ()
-- 
1.5.4.38.g0d380

-- 
Alexandre Julliard
julliard@winehq.org
Next: Sergei Organov
Message 1 of 5 in “git.el: Check for existing buffers on revert.”
  1. 3/4 git.el: Check for existing buffers on revert.Alexandre Julliard, Feb 7, 2008
  2. Sergei OrganovFeb 8, 2008
  3. Alexandre JulliardFeb 8, 2008
  4. Sergei OrganovFeb 8, 2008
  5. Tommy ThornFeb 9, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.