From aef515233d7083a59f51c89df0b539bf047e0830 Mon Sep 17 00:00:00 2001 From: Kyle Meyer Date: Sun, 19 Mar 2017 00:08:00 -0400 Subject: magit-branch-backup-current: Allow arbitrary name --- lisp/km-magit.el | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) (limited to 'lisp') 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/__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/__v', +where 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." -- cgit v1.2.3