From 3959a095fd98045de016b7261f5688e55f669070 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Gustav=20H=C3=A5llberg?= Date: Fri, 31 Jul 2009 00:57:57 +0200 Subject: [PATCH] stgit.el: Add "U" for stgit-revert-file MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Gustav HÃ¥llberg --- contrib/stgit.el | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/contrib/stgit.el b/contrib/stgit.el index 2a72189..c475fc2 100644 --- a/contrib/stgit.el +++ b/contrib/stgit.el @@ -616,6 +616,7 @@ at point." ("R" . stgit-repair) ("\C-c\C-c" . stgit-commit) ("\C-c\C-u" . stgit-uncommit) + ("U" . stgit-revert-file) ("\r" . stgit-select) ("o" . stgit-find-file-other-window) ("i" . stgit-file-toggle-index) @@ -792,6 +793,37 @@ Interactively, the prefix argument is used as COUNT." (stgit-capture-output nil (stgit-run "commit" "-n" count)) (stgit-reload)) +(defun stgit-revert-file () + "Revert the file at point, which must be in the index or the +working tree." + (interactive) + (let* ((patched-file (or (stgit-patched-file-at-point) + (error "No file on the current line"))) + (patch-name (stgit-patch-name-at-point)) + (file-status (stgit-file-status patched-file)) + (rm-file (cond ((stgit-file-copy-or-rename patched-file) + (stgit-file-cr-to patched-file)) + ((eq file-status 'add) + (stgit-file-file patched-file)))) + (co-file (cond ((eq file-status 'rename) + (stgit-file-cr-from patched-file)) + ((not (memq file-status '(copy add))) + (stgit-file-file patched-file))))) + + (unless (memq patch-name '(:work :index)) + (error "No index or working tree file on this line")) + + (let ((nfiles (+ (if rm-file 1 0) (if co-file 1 0)))) + (when (yes-or-no-p (format "Revert %d file%s? " + nfiles + (if (= nfiles 1) "" "s"))) + (stgit-capture-output nil + (when rm-file + (stgit-run-git "rm" "-f" "-q" "--" rm-file)) + (when co-file + (stgit-run-git "checkout" "HEAD" co-file))) + (stgit-reload))))) + (defun stgit-uncommit (count) "Run stg uncommit on COUNT commits. Interactively, the prefix argument is used as COUNT." -- 2.11.0