From: Gustav HÃ¥llberg Date: Thu, 30 Jul 2009 22:57:57 +0000 (+0200) Subject: stgit.el: Add "U" for stgit-revert-file X-Git-Tag: v0.15-rc2~11^2~48 X-Git-Url: https://git.distorted.org.uk/~mdw/stgit/commitdiff_plain/3959a095fd98045de016b7261f5688e55f669070 stgit.el: Add "U" for stgit-revert-file Signed-off-by: Gustav HÃ¥llberg --- 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."