Exemplo n.º 1
0
    def find_common_parent(self, commit_one, commit_two):
        """Find the common parent between the two commits if one exists"""
        one = Commit(self)
        one.checkout(commit_one)
        two = Commit(self)
        two.checkout(commit_two)
        listone = one.getAncestors()
        listtwo = two.getAncestors()

        def compare(a, b):
            common = None
            for index in range(len(a)):
                if a[index] is not b[index]:
                    return common
                common = a[index]
            return common

        if len(listone) < len(listtwo):
            common = compare(listone, listtwo)
        else:
            common = compare(listtwo, listone)

        if not common:
            raise NoCommonParent("The commits %s and %s do not share a common parent" % (commit_one, commit_two))

        return common