diff options
author | Ed Bartosh <eduard.bartosh@intel.com> | 2012-08-03 16:20:28 +0300 |
---|---|---|
committer | Guido Günther <agx@sigxcpu.org> | 2012-08-22 10:33:32 +0200 |
commit | 7524bbb37c3a1312f382db24d04e0234b7ff07b3 (patch) | |
tree | 5a8aa1585ba94c326393282b292d7fd1704db9cd /gbp/git | |
parent | e8d175aec0ed7fe2d79758de147565518aacaec3 (diff) |
GitRepository: Implement set_upstream_branch and get_upstream_branch methods
set_upstream_branch sets upstream branch for the local branch using
git branch --set-upstream
get_upstream_branch returns info about upstream branches
Signed-off-by: Ed Bartosh <eduard.bartosh@intel.com>
Diffstat (limited to 'gbp/git')
-rw-r--r-- | gbp/git/repository.py | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/gbp/git/repository.py b/gbp/git/repository.py index f3cde12..3f6f5cb 100644 --- a/gbp/git/repository.py +++ b/gbp/git/repository.py @@ -451,6 +451,44 @@ class GitRepository(object): return True return False + def set_upstream_branch(self, local_branch, upstream): + """ + Set upstream branches for local branch + + @param local_branch: name of the local branch + @type local_branch: C{str} + @param upstream: remote/branch, for example origin/master + @type upstream: C{str} + """ + + # check if both branches exist + for branch, remote in [(local_branch, False), (upstream, True)]: + if not self.has_branch(branch, remote=remote): + raise GitRepositoryError("Branch %s doesn't exist!" % branch) + + self._git_getoutput('branch', ["--set-upstream", local_branch, upstream]) + + + def get_upstream_branch(self, local_branch): + """ + Get upstream branch for the local branch + + @param local_branch: name fo the local branch + @type local_branch: C{str} + @return: upstream (remote/branch) or '' if no upstream found + @rtype: C{str} + + """ + args = GitArgs('--format=%(upstream:short)') + if self.has_branch(local_branch, remote=False): + args.add('refs/heads/%s' % local_branch) + else: + raise GitRepositoryError("Branch %s doesn't exist!" % local_branch) + + out = self._git_getoutput('for-each-ref', args.args)[0] + + return out[0].strip() + #{ Tags def create_tag(self, name, msg=None, commit=None, sign=False, keyid=None): |