chiark / gitweb /
stgit.el: Add C-c C-b for stgit-rebase
authorGustav Hållberg <gustav@virtutech.com>
Sat, 8 Aug 2009 18:59:49 +0000 (20:59 +0200)
committerGustav Hållberg <gustav@virtutech.com>
Sat, 8 Aug 2009 21:42:18 +0000 (23:42 +0200)
Signed-off-by: Gustav Hållberg <gustav@virtutech.com>
contrib/stgit.el

index df1656e549b9a1178cc683a7c2c11bcc89e7b5a4..827b139f3d8fdc3382b537028118d1876fad3c41 100644 (file)
@@ -771,6 +771,7 @@ (unless stgit-mode-map
             ([?\C-c ?\C-/] . stgit-redo)
             ("\C-c\C-_" . stgit-redo)
             ("B" .        stgit-branch)
+            ("\C-c\C-b" . stgit-rebase)
             ("t" .        ,toggle-map)
             ("d" .        ,diff-map)
             ("q" .        stgit-quit)))))
@@ -855,6 +856,7 @@ (defun stgit-mode ()
 
 Commands for branches:
 \\[stgit-branch]       Switch to another branch
+\\[stgit-rebase]       Rebase the current branch
 
 Customization variables:
 `stgit-abbreviate-copies-and-renames'
@@ -1049,6 +1051,31 @@ (defun stgit-branch (branch)
   (stgit-capture-output nil (stgit-run "branch" "--" branch))
   (stgit-reload))
 
+(defun stgit-available-refs (&optional omit-stgit)
+  "Returns a list of the available git refs.
+If OMIT-STGIT is not nil, filter out \"resf/heads/*.stgit\"."
+  (let* ((output (with-output-to-string
+                   (stgit-run-git-silent "for-each-ref" "--format=%(refname)"
+                                         "refs/tags" "refs/heads"
+                                         "refs/remotes")))
+         (result (split-string output "\n" t)))
+    (mapcar (lambda (s)
+              (if (string-match "^refs/\\(heads\\|tags\\|remotes\\)/" s)
+                  (substring s (match-end 0))
+                s))
+            (if omit-stgit
+                (delete-if (lambda (s)
+                             (string-match "^refs/heads/.*\\.stgit$" s))
+                           result)
+              result))))
+
+(defun stgit-rebase (new-base)
+  "Rebase to NEW-BASE."
+  (interactive (list (completing-read "Rebase to: "
+                                      (stgit-available-refs t))))
+  (stgit-capture-output nil (stgit-run "rebase" new-base))
+  (stgit-reload))
+
 (defun stgit-commit (count)
   "Run stg commit on COUNT commits.
 Interactively, the prefix argument is used as COUNT.