diff options
author | Kyle Meyer <kyle@kyleam.com> | 2017-05-13 12:08:19 -0400 |
---|---|---|
committer | Kyle Meyer <kyle@kyleam.com> | 2017-05-14 10:10:35 -0400 |
commit | 113efb231b32732d0cde9997a8268abd9738b7c7 (patch) | |
tree | 09e2cd42b8f8848d6457e1b80721c93e307b2c42 /lisp | |
parent | 3f185e7548cb565f323c484bbbfb9b5b14cb1043 (diff) | |
download | emacs.d-113efb231b32732d0cde9997a8268abd9738b7c7.tar.gz |
magit: Add command to "archive" branches
Diffstat (limited to 'lisp')
-rw-r--r-- | lisp/km-magit.el | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/lisp/km-magit.el b/lisp/km-magit.el index 56c1e67..81fa48a 100644 --- a/lisp/km-magit.el +++ b/lisp/km-magit.el @@ -234,6 +234,37 @@ exist." current (if (null versions) 1 (1+ (apply #'max versions))))))))) +(defun km/magit-branch-archive (branches) + "Move BRANCHES from refs/heads/ to refs/archive/." + (interactive + (list (or (magit-region-values 'branch) + (list + (magit-completing-read + "Branch to archive" (magit-list-refnames "refs/heads") + nil 'require nil nil + (or (magit-branch-at-point) (magit-get-previous-branch))))))) + (setq branches + (mapcar (lambda (branch) + (cons + (replace-regexp-in-string "refs/heads/" "" branch) + (concat (and (not (string-prefix-p "refs/heads/" branch)) + "refs/heads/") + branch))) + branches)) + (pcase-dolist (`(,branch-short . ,branch-full) branches) + (if (magit-git-success "update-ref" + (replace-regexp-in-string "refs/heads/" + "refs/archive/" + branch-full) + branch-full) + (magit-run-git "branch" "-D" branch-short) + (error "update-ref call failed"))) + (message (concat "Archived " + (let ((num-branches (length branches))) + (if (= num-branches 1) + (caar branches) + (format "%d branches" num-branches)))))) + (defun km/magit-mode-bury-all-windows (&optional kill-buffer) "Run `magit-mode-quit-window' until no longer in Magit buffer." (interactive "P") |