summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--init.el2
-rw-r--r--lisp/km-magit.el21
2 files changed, 17 insertions, 6 deletions
diff --git a/init.el b/init.el
index 0044a94..c4e716e 100644
--- a/init.el
+++ b/init.el
@@ -1148,7 +1148,7 @@
(magit-define-popup-action 'magit-branch-popup
?r "Rename branch" #'km/magit-branch-rename)
(magit-define-popup-action 'magit-branch-popup
- ?s "Backup current branch" #'km/magit-backup-branch)
+ ?s "Backup current branch" #'km/magit-branch-backup-current)
(magit-define-popup-action 'magit-branch-popup
?t "Local tracking" #'km/magit-checkout-local-tracking))
diff --git a/lisp/km-magit.el b/lisp/km-magit.el
index ccac2ed..bf65c4e 100644
--- a/lisp/km-magit.el
+++ b/lisp/km-magit.el
@@ -207,13 +207,24 @@ START-POINT set to the current branch.
(interactive (list (magit-read-string "Branch name")))
(magit-run-git "checkout" "-b" branch))
-(defun km/magit-backup-branch ()
+(defun km/magit-branch-backup-current ()
"Create a backup branch for the current branch.
-\n(git branch b/<current-branch>)"
+\n(git branch b/<current-branch>__vN)"
(interactive)
- (--if-let (magit-get-current-branch)
- (magit-run-git "branch" (concat "b/" it))
- (user-error "No current branch")))
+ (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)))
(defun km/magit-mode-bury-all-windows (&optional kill-buffer)
"Run `magit-mode-quit-window' until no longer in Magit buffer."