diff options
-rw-r--r-- | lisp/km-magit.el | 41 |
1 files changed, 22 insertions, 19 deletions
diff --git a/lisp/km-magit.el b/lisp/km-magit.el index 45b2860..58c8332 100644 --- a/lisp/km-magit.el +++ b/lisp/km-magit.el @@ -173,31 +173,34 @@ START-POINT set to the current branch. (concat it "-tmp"))))) (magit-run-git "checkout" "-b" branch)) -(defun km/magit-branch-backup-current (&optional choose-name) +(defun km/magit-branch-backup-current (&optional choose-suffix) "Create a backup branch for the current branch. -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." +Name it as 'b/<current-branch>__v<n>', where <n> is incremented +to form a refname that doesn't already exist. With the prefix +argument CHOOSE-SUFFIX, prompt for a suffix to use instead of +'v'." (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 "\\`%s__v\\([[:digit:]]+\\)\\'" - (regexp-quote 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 "%s__v%d" - current - (if (null versions) 1 (1+ (apply #'max versions))))))))) + (let* ((suffix (if choose-suffix + (magit-read-string-ns "Backup suffix") + "v")) + (version-re (format "\\`%s__%s\\([[:digit:]]+\\)\\'" + (regexp-quote current) + (regexp-quote suffix))) + (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 "%s__%s%d" + current + suffix + (if (null versions) 1 (1+ (apply #'max versions)))))))) (defun km/magit-branch-archive (branches) "Move BRANCHES from refs/heads/ to refs/archive/." |