diff options
author | Guido Günther <agx@sigxcpu.org> | 2010-08-04 15:26:13 -0400 |
---|---|---|
committer | Guido Günther <agx@sigxcpu.org> | 2010-08-04 15:26:13 -0400 |
commit | af2a435443ff050c6a47fa2c58d79fa7f954cc38 (patch) | |
tree | 8d91e0ae52d4e85f5f12ae9bc25e2462545fdb13 | |
parent | 34d6d84518d6f0593400af7e041d931b347ecf8a (diff) |
Don't update already up to date branches
-rwxr-xr-x | gbp-pull | 28 | ||||
-rw-r--r-- | gbp/git.py | 12 |
2 files changed, 31 insertions, 9 deletions
@@ -29,22 +29,38 @@ from gbp.errors import GbpError from gbp.git import (GitRepositoryError, GitRepository) def fast_forward_branch(branch, repo, options): + """ + update branch to its remote branch, fail on non fast forward updates + unless --force is given + @return: branch updated or already up to date + @rtype: boolean + """ + update = False + remote = repo.get_merge_branch(branch) if not remote: print >>sys.stderr, "Warning: no branch tracking '%s' found - skipping." % branch - return - fast_forward = repo.is_fast_forward(branch, remote) - if not fast_forward: + return False + + can_fast_forward, up_to_date = repo.is_fast_forward(branch, remote) + + if up_to_date: # Great, we're done + print "Branch '%s' is already up to date." % branch + return True + + if can_fast_forward: + update = True + else: if options.force: print "Non-fast forwarding '%s' due to --force" % branch - fast_forward = True + update = True else: print >>sys.stderr, "Warning: Skipping non-fast forward of '%s' - use --force" % branch - if fast_forward: + if update: repo.set_branch(branch) GitMerge(remote)() - return fast_forward + return update def main(argv): changelog = 'debian/changelog' @@ -118,13 +118,19 @@ class GitRepository(object): return remote def is_fast_forward(self, from_branch, to_branch): - """check if an update from from_branch to to_branch would be a fast forward""" + """check if an update from from_branch to to_branch would be a fast + forward or if the branch is uptodate already""" out = self.__git_getoutput('rev-list', ["--left-right", "%s...%s" % (from_branch, to_branch)])[0] + + if not out: # already up to date + return True, True + for line in out: if line.startswith("<"): - return False - return True + return False, False + + return True, False def set_branch(self, branch): """switch to branch 'branch'""" |