stgit.el: Handle negative argument to stgit-{un,}commit
authorGustav Hållberg <gustav@virtutech.com>
Sat, 1 Aug 2009 17:32:12 +0000 (19:32 +0200)
committerGustav Hållberg <gustav@virtutech.com>
Thu, 6 Aug 2009 20:49:07 +0000 (22:49 +0200)
Signed-off-by: Gustav Hållberg <gustav@virtutech.com>
contrib/stgit.el

index 0d99467..99f9203 100644 (file)
@@ -903,10 +903,23 @@ was modified with git commands (`stgit-repair')."
 
 (defun stgit-commit (count)
   "Run stg commit on COUNT commits.
-Interactively, the prefix argument is used as COUNT."
+Interactively, the prefix argument is used as COUNT.
+A negative COUNT will uncommit instead."
   (interactive "p")
-  (stgit-capture-output nil (stgit-run "commit" "-n" count))
-  (stgit-reload))
+  (if (< count 0)
+      (stgit-uncommit (- count))
+    (stgit-capture-output nil (stgit-run "commit" "-n" count))
+    (stgit-reload)))
+
+(defun stgit-uncommit (count)
+  "Run stg uncommit on COUNT commits.
+Interactively, the prefix argument is used as COUNT.
+A negative COUNT will commit instead."
+  (interactive "p")
+  (if (< count 0)
+      (stgit-commit (- count))
+    (stgit-capture-output nil (stgit-run "uncommit" "-n" count))
+    (stgit-reload)))
 
 (defun stgit-revert-file ()
   "Revert the file at point, which must be in the index or the
@@ -964,13 +977,6 @@ working tree."
 
     (stgit-reload)))
 
-(defun stgit-uncommit (count)
-  "Run stg uncommit on COUNT commits.
-Interactively, the prefix argument is used as COUNT."
-  (interactive "p")
-  (stgit-capture-output nil (stgit-run "uncommit" "-n" count))
-  (stgit-reload))
-
 (defun stgit-push-next (npatches)
   "Push the first unapplied patch.
 With numeric prefix argument, push that many patches."