summaryrefslogtreecommitdiff
path: root/lisp/init-git.el
diff options
context:
space:
mode:
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)