From 5d1327459b37f9fa1ab46a4bdf61cdc889f97603 Mon Sep 17 00:00:00 2001 From: Kyle Meyer Date: Thu, 26 Jan 2017 23:05:47 -0500 Subject: magit: Add a cherry dwim command --- init.el | 2 ++ lisp/km-magit.el | 29 +++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/init.el b/init.el index 6a0eabd..bc9bc39 100644 --- a/init.el +++ b/init.el @@ -1112,6 +1112,8 @@ (magit-define-popup-action 'magit-log-popup ?d "Log dwim" #'km/magit-log-dwim) + (magit-define-popup-action 'magit-log-popup + ?y "Cherry dwim" #'km/magit-cherry-dwim) (magit-define-popup-action 'magit-merge-popup ?u "Merge upstream" #'km/magit-ff-merge-upstream) diff --git a/lisp/km-magit.el b/lisp/km-magit.el index 1ec6bba..ccac2ed 100644 --- a/lisp/km-magit.el +++ b/lisp/km-magit.el @@ -646,6 +646,35 @@ argument. Interactively, this can be accessed using the command (magit-log (list range) args files) (call-interactively #'magit-log)))) +(defun km/magit-cherry-dwim () + (interactive) + (-let [(head . upstream) + (if (eq major-mode 'magit-log-mode) + (let ((range (caar magit-refresh-args))) + (and range + (string-match magit-range-re range) + (cons (match-string 3 range) + (match-string 1 range)))) + (let ((section (magit-current-section)) + (current-branch (magit-get-current-branch))) + (pcase (list (magit-section-type section) + (magit-section-value section)) + (`(unpushed "@{upstream}..") + (cons current-branch (magit-get-upstream-branch))) + (`(unpulled "..@{upstream}") + (cons (magit-get-upstream-branch) current-branch)) + ;; Don't try to match "@{push}" because + ;; `magit-insert-unpulled-from-pushremote' and + ;; `magit-insert-unpulled-from-pushremote' avoid it to + ;; be compatible with all push.default settings. + (`(unpushed ,_) + (cons current-branch (magit-get-push-branch))) + (`(unpulled ,_) + (cons (magit-get-push-branch) current-branch)))))] + (if (and head upstream) + (magit-cherry head upstream) + (call-interactively #'magit-cherry)))) + (defun km/magit--insert-count-lines (rev counts) (-let [(n-behind n-ahead) counts] (when (> n-ahead 0) -- cgit v1.2.3