summaryrefslogtreecommitdiff
path: root/lisp/km-magit.el
diff options
context:
space:
mode:
authorKyle Meyer <kyle@kyleam.com>2018-12-09 15:13:31 -0500
committerKyle Meyer <kyle@kyleam.com>2018-12-09 15:13:46 -0500
commitf2da8092e9f49cb669af4c4f6979a8ecac7b7448 (patch)
tree55ad0beaa1919d96d0edc335138517e37f5891d0 /lisp/km-magit.el
parent7fa947af86bdc65dd521c2e3e1444bc7e37cce32 (diff)
downloademacs.d-f2da8092e9f49cb669af4c4f6979a8ecac7b7448.tar.gz
km/magit-branch-backup-current: Tweak prefix meaning
Diffstat (limited to 'lisp/km-magit.el')
-rw-r--r--lisp/km-magit.el41
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/."