From 65c07d64a7b1dc85c41083c60a8082b3705154c3 Mon Sep 17 00:00:00 2001 From: Sandy Carter Date: Tue, 21 Jul 2015 11:02:24 -0400 Subject: Implement is_ancestor Wrap `git merge-base --is-ancestor` into its own function because it acts as a boolean check unlike base `git merge-base call` --- git/repo/base.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'git/repo/base.py') diff --git a/git/repo/base.py b/git/repo/base.py index b0411235..16fb58e5 100644 --- a/git/repo/base.py +++ b/git/repo/base.py @@ -504,6 +504,21 @@ class Repo(object): return res + def is_ancestor(self, ancestor_rev, rev): + """Check if a commit is an ancestor of another + + :param ancestor_rev: Rev which should be an ancestor + :param rev: Rev to test against ancestor_rev + :return: ``True``, ancestor_rev is an accestor to rev. + """ + try: + self.git.merge_base(ancestor_rev, rev, is_ancestor=True) + except GitCommandError as err: + if err.status == 1: + return False + raise + return True + def _get_daemon_export(self): filename = join(self.git_dir, self.DAEMON_EXPORT_FILE) return os.path.exists(filename) -- cgit v1.2.1