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 --- lisp/km-magit.el | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'lisp') 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