unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* [PATCH] vc-git-revert: Execute commands from FILE's `vc-git-root'.
@ 2012-12-07  9:18 Dominique Quatravaux
  0 siblings, 0 replies; 2+ messages in thread
From: Dominique Quatravaux @ 2012-12-07  9:18 UTC (permalink / raw)
  To: emacs-devel; +Cc: Dominique Quatravaux, fishchman

"git checkout -q --" only works from a directory that is in the same Git
repository as the target file. `vc-git-command' runs the command from
buffer *vc*, in which the `default-directory' may be unsuitable depending
on the circumstances in which *vc* was created.
---
 lisp/vc/vc-git.el |   10 ++++++----
 1 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/lisp/vc/vc-git.el b/lisp/vc/vc-git.el
index 08b48fa..5683cab 100644
--- a/lisp/vc/vc-git.el
+++ b/lisp/vc/vc-git.el
@@ -677,10 +677,12 @@ It is based on `log-edit-mode', and has Git-specific extensions.")
 
 (defun vc-git-revert (file &optional contents-done)
   "Revert FILE to the version stored in the git repository."
-  (if contents-done
-      (vc-git-command nil 0 file "update-index" "--")
-    (vc-git-command nil 0 file "reset" "-q" "--")
-    (vc-git-command nil nil file "checkout" "-q" "--")))
+  (with-temp-buffer
+    (cd (vc-git-root file))
+    (if contents-done
+        (vc-git-command (current-buffer) 0 file "update-index" "--")
+      (vc-git-command (current-buffer) 0 file "reset" "-q" "--")
+      (vc-git-command (current-buffer) nil file "checkout" "-q" "--"))))
 
 (defvar vc-git-error-regexp-alist
   '(("^ \\(.+\\) |" 1 nil nil 0))
-- 
1.7.7.3




^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] vc-git-revert: Execute commands from FILE's `vc-git-root'.
       [not found] ` <1354872033-4313-2-git-send-email-domq@google.com>
@ 2012-12-11 10:08   ` Dominique Quatravaux
  0 siblings, 0 replies; 2+ messages in thread
From: Dominique Quatravaux @ 2012-12-11 10:08 UTC (permalink / raw)
  To: emacs-devel; +Cc: fischman

As per Ami's suggestion, here is how to reproduce the breakage that
this patch fixes:

* Create two different Git repositories, repo1 and repo2; add and
commit a test file in each (say repo1/test.txt and repo2/test.txt).

* Open repo1/test.txt in a pristine Emacs instance; add a line to it and save.

* Open repo2/test.txt from the same instance; add a line to it and save.

* Try to revert repo2/test.txt using C-x v u.

Tested with Emacs 24.2.50.1 from Ubuntu Precise (2:20121025-1~ppa1~precise1)

-- 
  Dominique Quatravaux
  +41 79 609 40 72



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-12-11 10:08 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-12-07  9:18 [PATCH] vc-git-revert: Execute commands from FILE's `vc-git-root' Dominique Quatravaux
     [not found] <1354872033-4313-1-git-send-email-domq@google.com>
     [not found] ` <1354872033-4313-2-git-send-email-domq@google.com>
2012-12-11 10:08   ` Dominique Quatravaux

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).