summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lisp/km-magit.el40
1 files changed, 23 insertions, 17 deletions
diff --git a/lisp/km-magit.el b/lisp/km-magit.el
index fa7d3af..7162e8e 100644
--- a/lisp/km-magit.el
+++ b/lisp/km-magit.el
@@ -209,24 +209,30 @@ START-POINT set to the current branch.
(concat it "-tmp")))))
(magit-run-git "checkout" "-b" branch))
-(defun km/magit-branch-backup-current ()
+(defun km/magit-branch-backup-current (&optional choose-name)
"Create a backup branch for the current branch.
-\n(git branch b/<current-branch>__vN)"
- (interactive)
- (let* ((current (or (magit-get-current-branch)
- (user-error "No current branch")))
- (version-re (format "\\`b/%s__v\\([[:digit:]]+\\)\\'" current))
- (versions (delq nil
- (mapcar
- (lambda (s)
- (and (string-match version-re s)
- (string-to-number
- (match-string-no-properties 1 s))))
- (magit-list-local-branch-names))))
- (vbranch (format "b/%s__v%d"
- current
- (if (null versions) 1 (1+ (apply #'max versions))))))
- (magit-run-git "branch" vbranch)))
+With the prefix argument CHOOSE-NAME, prompt for the name of the
+backup branch. Otherwise, name it as 'b/<current-branch>__v<n>',
+where <n> is incremented to form a refname that doesn't already
+exist."
+ (interactive "P")
+ (let ((current (or (magit-get-current-branch)
+ (user-error "No current branch"))))
+ (magit-run-git
+ "branch"
+ (if choose-name
+ (magit-read-string-ns "Backup name" current)
+ (let* ((version-re (format "\\`b/%s__v\\([[:digit:]]+\\)\\'" current))
+ (versions (delq nil
+ (mapcar
+ (lambda (s)
+ (and (string-match version-re s)
+ (string-to-number
+ (match-string-no-properties 1 s))))
+ (magit-list-local-branch-names)))))
+ (format "b/%s__v%d"
+ current
+ (if (null versions) 1 (1+ (apply #'max versions)))))))))
(defun km/magit-mode-bury-all-windows (&optional kill-buffer)
"Run `magit-mode-quit-window' until no longer in Magit buffer."