aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGustav Hållberg <gustav@gmail.com>2012-04-07 21:43:10 +0200
committerGustav Hållberg <gustav@gmail.com>2012-04-07 21:43:10 +0200
commitf8c77f23c0c6126839ca1bd36bee5af6f458e8b1 (patch)
treeb567d24a5e55b078ef5aa905c65901a0d773b31c
parent5cabf6cfb3c543853ba3e87cd88309f3fe3479dd (diff)
downloadstgit-f8c77f23c0c6126839ca1bd36bee5af6f458e8b1.tar.gz
stgit.el: Make stgit-branch ask whether to merge uncommitted changes
Signed-off-by: Gustav Hållberg <gustav@gmail.com>
-rw-r--r--contrib/stgit.el55
1 files changed, 36 insertions, 19 deletions
diff --git a/contrib/stgit.el b/contrib/stgit.el
index 83ff806..0e84644 100644
--- a/contrib/stgit.el
+++ b/contrib/stgit.el
@@ -1777,26 +1777,43 @@ If ALL is not nil, also return non-stgit branches."
"Switch to or create branch BRANCH."
(interactive (list (completing-read "Switch to branch: "
(stgit-available-branches))))
+
(stgit-assert-mode)
- (when (cond ((equal branch (stgit-current-branch))
- (error "Branch is already current"))
- ((member branch (stgit-available-branches t))
- (stgit-capture-output nil (stgit-run "branch" "--" branch))
- t)
- ((not (string-match stgit-allowed-branch-name-re branch))
- (error "Invalid branch name"))
- ((yes-or-no-p (format "Create branch \"%s\"? " branch))
- (let ((branch-point (completing-read
- "Branch from (default current branch): "
- (stgit-available-branches))))
- (stgit-capture-output nil
- (apply 'stgit-run
- `("branch" "--create" "--"
- ,branch
- ,@(unless (zerop (length branch-point))
- (list branch-point)))))
- t)))
- (stgit-reload)))
+
+ (when (equal branch (stgit-current-branch))
+ (error "Branch is already current"))
+
+ (let ((merge (not (and (stgit-index-empty-p) (stgit-work-tree-empty-p)))))
+
+ (when (cond ((and merge
+ (not (yes-or-no-p
+ "Attempt to merge uncommitted changes? ")))
+ nil)
+
+ ((member branch (stgit-available-branches t))
+ (stgit-capture-output nil
+ (apply 'stgit-run
+ (append '("branch")
+ (and merge '("--merge"))
+ '("--")
+ (list branch))))
+ t)
+ ((not (string-match stgit-allowed-branch-name-re branch))
+ (error "Invalid branch name"))
+ (merge
+ (error "Cannot merge changes into a new branch"))
+ ((yes-or-no-p (format "Create branch \"%s\"? " branch))
+ (let ((branch-point (completing-read
+ "Branch from (default current branch): "
+ (stgit-available-branches))))
+ (stgit-capture-output nil
+ (apply 'stgit-run
+ `("branch" "--create" "--"
+ ,branch
+ ,@(unless (zerop (length branch-point))
+ (list branch-point)))))
+ t)))
+ (stgit-reload))))
(defun stgit-available-refs (&optional omit-stgit)
"Returns a list of the available git refs.