gbp-pull: similar update strategy for all branches
authorMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Thu, 12 Jan 2012 13:25:57 +0000 (15:25 +0200)
committerMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Fri, 14 Nov 2014 12:22:11 +0000 (14:22 +0200)
Treat non-checked-out branches similarly to the current branch when
forcing update. That is, do git merge, instead of just setting the ref.

Also, renames fast_forward_branch() to update_branch() to better match
the functionality.

Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
gbp/scripts/pull.py

index 98d966e..a2dafd0 100755 (executable)
@@ -29,7 +29,7 @@ from gbp.git import GitRepositoryError
 from gbp.deb.git import DebianGitRepository
 import gbp.log
 
-def fast_forward_branch(branch, repo, options):
+def update_branch(branch, repo, options):
     """
     update branch to its remote branch, fail on non fast forward updates
     unless --force is given
@@ -63,10 +63,17 @@ def fast_forward_branch(branch, repo, options):
         gbp.log.info("Updating '%s'" % branch)
         if repo.branch == branch:
             repo.merge(remote)
-        else:
+        elif can_fast_forward:
             sha1 = repo.rev_parse(remote)
             repo.update_ref("refs/heads/%s" % branch, sha1,
                             msg="gbp: forward %s to %s" % (branch, remote))
+        else:
+            # Merge other branch, if it cannot be fast-forwarded
+            current_branch=repo.branch
+            repo.set_branch(branch)
+            repo.merge(remote)
+            repo.set_branch(current_branch)
+
     return update
 
 
@@ -165,7 +172,7 @@ def main(argv):
         repo.fetch(depth=options.depth)
         repo.fetch(depth=options.depth, tags=True)
         for branch in branches:
-            if not fast_forward_branch(branch, repo, options):
+            if not update_branch(branch, repo, options):
                 retval = 2
 
         if options.redo_pq: