summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--init.el2
-rw-r--r--lisp/km-magit.el29
2 files changed, 31 insertions, 0 deletions
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)