diff options
author | Kyle Meyer <kyle@kyleam.com> | 2017-03-19 00:08:00 -0400 |
---|---|---|
committer | Kyle Meyer <kyle@kyleam.com> | 2017-03-19 00:08:00 -0400 |
commit | aef515233d7083a59f51c89df0b539bf047e0830 (patch) | |
tree | b814fc59a2b717e5c3abfcbc1eda100e6faf825f | |
parent | b23710bb423897f24929cb465d6476d49281c1fb (diff) | |
download | emacs.d-aef515233d7083a59f51c89df0b539bf047e0830.tar.gz |
magit-branch-backup-current: Allow arbitrary name
-rw-r--r-- | lisp/km-magit.el | 40 |
1 files changed, 23 insertions, 17 deletions
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/<current-branch>__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/<current-branch>__v<n>', +where <n> 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." |