git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alexandre Julliard <julliard@winehq.org>
To: git@vger.kernel.org
Subject: [PATCH 3/4] git.el: Check for existing buffers on revert.
Date: Thu, 07 Feb 2008 13:51:20 +0100	[thread overview]
Message-ID: <87r6fporp3.fsf@wine.dyndns.org> (raw)

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

             reply	other threads:[~2008-02-07 12:52 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-02-07 12:51 Alexandre Julliard [this message]
2008-02-08 14:30 ` [PATCH 3/4] git.el: Check for existing buffers on revert Sergei Organov
2008-02-08 14:54   ` Alexandre Julliard
2008-02-08 17:10     ` Sergei Organov
2008-02-09  5:41       ` Tommy Thorn

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87r6fporp3.fsf@wine.dyndns.org \
    --to=julliard@winehq.org \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).