summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyle Meyer <kyle@kyleam.com>2017-12-31 11:41:04 -0500
committerKyle Meyer <kyle@kyleam.com>2017-12-31 11:45:45 -0500
commit363e8d35f47069deba4bb00ce46f8bd6cdaf5a2c (patch)
treee2099a9895c605a8ba7b75fed8837ed4a0a2a03c
parenta6ea7d04f89b86531d96a016fcb1d58ba64b678e (diff)
downloademacs.d-363e8d35f47069deba4bb00ce46f8bd6cdaf5a2c.tar.gz
magit: Modify message for refs/pull/ merges
-rw-r--r--init.el11
-rw-r--r--lisp/km-magit.el22
2 files changed, 32 insertions, 1 deletions
diff --git a/init.el b/init.el
index 4de43ce..d972efc 100644
--- a/init.el
+++ b/init.el
@@ -1032,7 +1032,16 @@
(lambda (fn &rest args)
(let ((magit-process-popup-time 0))
(apply fn args)))
- '((name . "magit-fetch-process"))))
+ '((name . "magit-fetch-process")))
+
+ (advice-add 'magit-merge
+ :around
+ (lambda (fn rev &optional args &rest other)
+ (let ((msg (km/magit-merge-pull-message rev)))
+ (when msg
+ (push (format "-m%s" msg) args)))
+ (apply fn rev args other))
+ '((name . "magit-merge-check-pull"))))
(use-package git-rebase
:defer t
diff --git a/lisp/km-magit.el b/lisp/km-magit.el
index 1c84250..2a02e9d 100644
--- a/lisp/km-magit.el
+++ b/lisp/km-magit.el
@@ -121,6 +121,28 @@ branch."
(magit-merge it '("--ff-only"))
(user-error "No upstream branch")))
+;;;###autoload
+(defun km/magit-merge-pull-message (rev)
+ "Generate a PR merge message for REV.
+
+The PR message can take two forms:
+
+ 1) Merge branch '<local>' [#<pr>]
+ 2) Merge pull request #<pr> from <remote>/<branch>
+
+The first is used if REV is the name of a local branch, and the
+second if REV is the name of a remote branch.
+
+This assumes that you are pulling PRs into your 'refs/pull/'
+namespace."
+ (-when-let (pr (--when-let (magit-rev-name rev "refs/pull/*")
+ (and (string-match "\\`pull/.+/\\([0-9]+\\)\\'" it)
+ (match-string 1 it))))
+ (cond ((magit-local-branch-p rev)
+ (format "Merge branch '%s' [#%s]" rev pr))
+ ((magit-remote-branch-p rev)
+ (format "Merge pull request #%s from %s" pr rev)))))
+
(defun km/magit-push-all ()
"Push all branches."
(interactive)