stgit.el: Add "B" for stgit-branch
[stgit] / contrib / stgit.el
index 3b63533..7fd3786 100644 (file)
@@ -541,7 +541,8 @@ find copied files."
           ("D" .        stgit-delete)
           ([(control ?/)] . stgit-undo)
           ("\C-_" .     stgit-undo)
-          ("q" . stgit-quit))))
+          ("B" .        stgit-branch)
+          ("q" .        stgit-quit))))
 
 (defun stgit-mode ()
   "Major mode for interacting with StGit.
@@ -677,6 +678,24 @@ If that patch cannot be found, return nil."
     (stgit-run "repair"))
   (stgit-reload))
 
+(defun stgit-available-branches ()
+  "Returns a list of the available stg branches"
+  (let ((output (with-output-to-string
+                  (stgit-run "branch" "--list")))
+        (start 0)
+        result)
+    (while (string-match "^>?\\s-+s\\s-+\\(\\S-+\\)" output start)
+      (setq result (cons (match-string 1 output) result))
+      (setq start (match-end 0)))
+    result))
+
+(defun stgit-branch (branch)
+  "Switch to branch BRANCH."
+  (interactive (list (completing-read "Switch to branch: "
+                                      (stgit-available-branches))))
+  (stgit-capture-output nil (stgit-run "branch" "--" branch))
+  (stgit-reload))
+
 (defun stgit-commit (count)
   "Run stg commit on COUNT commits.
 Interactively, the prefix argument is used as COUNT."