summaryrefslogtreecommitdiff
path: root/lisp/init-git.el
diff options
context:
space:
mode:
authorKyle Meyer <kyle@kyleam.com>2015-09-01 11:43:06 -0400
committerKyle Meyer <kyle@kyleam.com>2015-09-01 11:43:30 -0400
commit69965c45cb7a78832633e04b7ed32f78bc346788 (patch)
tree9d1b9679251814b922efd7eb125879bdb216414d /lisp/init-git.el
parent5304951d4cd2c4bc98ed204ba928533f9d80c56a (diff)
downloademacs.d-69965c45cb7a78832633e04b7ed32f78bc346788.tar.gz
Add magit-rev-ancestor-p command
Diffstat (limited to 'lisp/init-git.el')
-rw-r--r--lisp/init-git.el20
1 files changed, 20 insertions, 0 deletions
diff --git a/lisp/init-git.el b/lisp/init-git.el
index 29525a5..d6ac3c9 100644
--- a/lisp/init-git.el
+++ b/lisp/init-git.el
@@ -444,6 +444,26 @@ function."
(when (derived-mode-p 'magit-log-mode)
(magit-diff-show-or-scroll-up)))
+(defun km/magit-rev-ancestor-p (rev-a rev-b)
+ "Report whether REV-A is the ancestor of REV-B.
+Use the revision at point as REV-B. With prefix argument or if
+there is no revision at point, prompt for the revision. Always
+prompt for REV-A."
+ (interactive
+ (let* ((atpoint (or (and magit-blame-mode (magit-blame-chunk-get :hash))
+ (magit-branch-or-commit-at-point)
+ (magit-tag-at-point)))
+ (commit (or (and (not current-prefix-arg) atpoint)
+ (magit-read-branch-or-commit "Descendant" atpoint))))
+ (list (magit-read-other-branch-or-commit
+ (format "Test if ancestor of %s" commit) commit)
+ commit)))
+ (message "%s is %san ancestor of %s" rev-a
+ (if (magit-git-success "merge-base" "--is-ancestor"
+ rev-a rev-b)
+ "" "NOT ")
+ rev-b))
+
(define-key ctl-x-4-map "g" 'magit-find-file-other-window)
(define-key km/file-map "g" 'magit-find-file)