summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyle Meyer <kyle@kyleam.com>2017-02-14 19:49:00 -0500
committerKyle Meyer <kyle@kyleam.com>2017-02-14 19:49:00 -0500
commita3ce3c3a3837011124b977c5eb5e936bb9154387 (patch)
tree198a1a3726f915fc639f7d1f2b84eee102123762
parentd1cca257226a92322a99e3a1b68a4eeaa26b503d (diff)
downloademacs.d-a3ce3c3a3837011124b977c5eb5e936bb9154387.tar.gz
Extend km/magit-backup-branch to support multiple versions
-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."