From c57d4af675910ec151cf982532db0f877aef413f Mon Sep 17 00:00:00 2001 From: Daniel Dehennin Date: Sun, 13 May 2012 20:37:11 +0200 Subject: gbp.git.repository: Add a "git merge-base" wrapper MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes: #672642 Signed-off-by: Guido Günther --- gbp/git/repository.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'gbp') diff --git a/gbp/git/repository.py b/gbp/git/repository.py index 2cc5eda..16bad60 100644 --- a/gbp/git/repository.py +++ b/gbp/git/repository.py @@ -299,6 +299,26 @@ class GitRepository(object): remote += merge.replace("refs/heads","", 1) return remote + def get_merge_base(self, commit1, commit2): + """ + Get the common ancestor between two commits + + @param commit1: commit SHA1 or name of a branch or tag + @type commit1: C{str} + @param commit2: commit SHA1 or name of a branch or tag + @type commit2: C{str} + @return: SHA1 of the common ancestor + @rtype: C{str} + """ + args = GitArgs() + args.add(commit1) + args.add(commit2) + sha1, stderr, ret = self._git_inout('merge-base', args.args, capture_stderr=True) + if not ret: + return sha1.strip() + else: + raise GitRepositoryError("Failed to get common ancestor: %s" % stderr.strip()) + def merge(self, commit, verbose=False, edit=False): """ Merge changes from the named commit into the current branch -- cgit v1.2.3