summaryrefslogtreecommitdiff
path: root/lisp
diff options
context:
space:
mode:
authorKyle Meyer <kyle@kyleam.com>2015-05-10 22:29:08 -0400
committerKyle Meyer <kyle@kyleam.com>2015-05-10 22:29:08 -0400
commit64ba09baed50dfc95adf46ccd1f32425a635fb9f (patch)
tree2b5fe346261e34866a355dcd310b26089200bd86 /lisp
parent698b58947ad364134929272d544646d8f9b0967a (diff)
downloademacs.d-64ba09baed50dfc95adf46ccd1f32425a635fb9f.tar.gz
Magit: Add commands for checking out recent refs
Diffstat (limited to 'lisp')
-rw-r--r--lisp/init-git.el33
1 files changed, 33 insertions, 0 deletions
diff --git a/lisp/init-git.el b/lisp/init-git.el
index 108d26c..f342199 100644
--- a/lisp/init-git.el
+++ b/lisp/init-git.el
@@ -123,6 +123,35 @@ without requiring confirmation.
(interactive)
(magit-run-git "checkout" "-"))
+(defun km/magit-list-recent-refs (n &optional remote)
+ "List N recent refs.
+If REMOTE is non-nil, limit to remote refs."
+ (magit-git-lines
+ "for-each-ref" "--sort=-committerdate" "--format=%(refname:short)"
+ (format "--count=%s" n)
+ (if remote "refs/remotes" "refs")))
+
+(defun km/magit-checkout-recent-ref (n)
+ "Checkout branch from N recent refs.
+Refs are sorted by committer date."
+ (interactive (list (or (and current-prefix-arg
+ (prefix-numeric-value current-prefix-arg))
+ 5)))
+ (magit-run-git "checkout"
+ (magit-completing-read
+ "Ref" (km/magit-list-recent-refs n))))
+
+(defun km/magit-checkout-track-recent-ref (n)
+ "Create and checkout a local tracking branch.
+Listed refs are limited to N most recent, sorted by committer
+date."
+ (interactive (list (or (and current-prefix-arg
+ (prefix-numeric-value current-prefix-arg))
+ 5)))
+ (magit-run-git "checkout" "-t"
+ (magit-completing-read
+ "Ref" (km/magit-list-recent-refs n 'remote))))
+
(defun km/magit-checkout-master ()
"Checkout master branch.
\n(git checkout master)"
@@ -311,6 +340,10 @@ the file name if NO-DIRECTORY is non-nil."
(magit-define-popup-action 'magit-branch-popup
?m "Checkout master" 'km/magit-checkout-master)
(magit-define-popup-action 'magit-branch-popup
+ ?n "Checkou recent ref" 'km/magit-checkout-recent-ref)
+ (magit-define-popup-action 'magit-branch-popup
+ ?N "Track recent ref" 'km/magit-checkout-track-recent-ref)
+ (magit-define-popup-action 'magit-branch-popup
?p "Checkout previous" 'km/magit-checkout-previous-branch)
(magit-define-popup-action 'magit-branch-popup
?s "Backup current branch" 'km/magit-backup-branch)