From b708f92f3e7e498aff8f57fc97d0d38606e9c822 Mon Sep 17 00:00:00 2001 From: Kyle Meyer Date: Thu, 16 Apr 2020 23:28:42 -0400 Subject: km/magit-branch-backup-current: Allow non-interactive suffix arg This will make it easier to create commands for common ones. --- lisp/km-magit.el | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/lisp/km-magit.el b/lisp/km-magit.el index 0cfbf2c..7f339cd 100644 --- a/lisp/km-magit.el +++ b/lisp/km-magit.el @@ -220,25 +220,24 @@ START-POINT set to the current branch. (error "bug: version re should always match")))) (km/magit-branch-get-set branch suffix))))) -(defun km/magit-branch-backup-current (&optional choose-suffix) +(defun km/magit-branch-backup-current (&optional suffix) "Create a backup branch for the current branch. Name it as '__v', where 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 +argument SUFFIX, prompt for a suffix to use instead of 'v'." - (interactive "P") - (let ((current (or (magit-get-current-branch) - (user-error "No current branch")))) + (interactive (list (and current-prefix-arg + (magit-read-string-ns "Backup suffix")))) + (setq suffix (or suffix "v")) + (let* ((current (or (magit-get-current-branch) + (user-error "No current branch"))) + (versions (km/magit-branch--get-versions current suffix))) (magit-run-git "branch" "--copy" - (let* ((suffix (if choose-suffix - (magit-read-string-ns "Backup suffix") - "v")) - (versions (km/magit-branch--get-versions current suffix))) - (format "%s__%s%d" - current - suffix - (if (null versions) 1 (1+ (apply #'max versions)))))))) + (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/." -- cgit v1.2.3