+(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))
+