From 69965c45cb7a78832633e04b7ed32f78bc346788 Mon Sep 17 00:00:00 2001 From: Kyle Meyer Date: Tue, 1 Sep 2015 11:43:06 -0400 Subject: Add magit-rev-ancestor-p command --- lisp/init-git.el | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'lisp/init-git.el') 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) -- cgit v1.2.3