diff options
author | Kyle Meyer <kyle@kyleam.com> | 2017-01-26 23:05:47 -0500 |
---|---|---|
committer | Kyle Meyer <kyle@kyleam.com> | 2017-01-26 23:05:47 -0500 |
commit | 5d1327459b37f9fa1ab46a4bdf61cdc889f97603 (patch) | |
tree | 681a0c93a699e58a31123348629a474a16ce9581 /lisp | |
parent | 4791ff89fafaa785394cad771bc84749d5dfb064 (diff) | |
download | emacs.d-5d1327459b37f9fa1ab46a4bdf61cdc889f97603.tar.gz |
magit: Add a cherry dwim command
Diffstat (limited to 'lisp')
-rw-r--r-- | lisp/km-magit.el | 29 |
1 files changed, 29 insertions, 0 deletions
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) |