Permalink
Browse files

git-get is-ancestor-of A B exits true iff A is an ancestor of B

  • Loading branch information...
1 parent 09cec6a commit a861d5dd296860cbde28a15124399ba866272e9a @mjdominus committed Mar 25, 2012
Showing with 7 additions and 0 deletions.
  1. +7 −0 git-get
View
7 git-get
@@ -58,6 +58,13 @@ sub is_remote {
if (grep $_ eq $in, qx{git remote}) { exit 0 } else { exit 1 }
}
+sub is_ancestor_of {
+ my ($A, $B) = @_;
+ $A = _run("git", "rev-parse", $A);
+ my $merge_base = _run("git", "merge-base", $A, $B);
+ exit($A eq $merge_base ? 0 : 1);
+}
+
sub _run {
my @cmd = @_;
open my($p), "-|", @cmd or die "Couldn't run '@cmd': $!";

0 comments on commit a861d5d

Please sign in to comment.