From: David Kågedal Date: Thu, 30 Jul 2009 14:54:50 +0000 (+0200) Subject: stgit.el: Add the stgit-file-toggle-index command X-Git-Tag: v0.15-rc2~11^2~60 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~mdw/git/stgit/commitdiff_plain/37cb5766267f6bca518dee62eaa95556303a5fbd?ds=inline stgit.el: Add the stgit-file-toggle-index command Based on a patch from Gustav Hållberg. Signed-off-by: David Kågedal Signed-off-by: Gustav Hållberg --- diff --git a/contrib/stgit.el b/contrib/stgit.el index 0a1aefb..b47dbae 100644 --- a/contrib/stgit.el +++ b/contrib/stgit.el @@ -594,6 +594,7 @@ (unless stgit-mode-map ("U" . stgit-uncommit) ("\r" . stgit-select) ("o" . stgit-find-file-other-window) + ("i" . stgit-file-toggle-index) (">" . stgit-push-next) ("<" . stgit-pop-next) ("P" . stgit-push-or-pop) @@ -855,6 +856,35 @@ (defun stgit-show () (goto-char (point-min)) (diff-mode)))) +(defun stgit-move-change-to-index (file status) + "Copies the workspace state of FILE to index, using git add or git rm" + (let ((op (if (file-exists-p file) "add" "rm"))) + (stgit-capture-output "*git output*" + (stgit-run-git op "--" file)))) + +(defun stgit-remove-change-from-index (file status) + "Unstages the change in FILE from the index" + (stgit-capture-output "*git output*" + (stgit-run-git "reset" "-q" "--" file))) + +(defun stgit-file-toggle-index () + "Move modified file in or out of the index." + (interactive) + (let ((patched-file (stgit-patched-file-at-point))) + (unless patched-file + (error "No file on the current line")) + (let ((patch-name (stgit-patch-name-at-point))) + (cond ((eq patch-name :work) + (stgit-move-change-to-index (stgit-file-file patched-file) + (stgit-file-status patched-file))) + ((eq patch-name :index) + (stgit-remove-change-from-index (stgit-file-file patched-file) + (stgit-file-status patched-file))) + (t + (error "Can only move files in the working tree to index"))))) + ;; FIXME: invalidate ewoc + (stgit-reload)) + (defun stgit-edit () "Edit the patch on the current line." (interactive)