gbp-pull: implement --all cmdline option
authorMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Tue, 15 Jan 2013 14:28:24 +0000 (16:28 +0200)
committerMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Tue, 3 Mar 2015 08:07:46 +0000 (10:07 +0200)
This updates all remote-tracking branches (for the remote that is
fetched from) whose local branch name is identical to the remote branch
name.

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

index fd658c8dfa23085b46f4ef6dcfef0b81b5df807c..de076b7fc4105260b201d376fad72f03e45e5d79 100644 (file)
@@ -23,6 +23,7 @@
 
       &man.common.options.synopsis;
       <arg><option>--force</option></arg>
+      <arg><option>--all</option></arg>
       <arg><option>--redo-pq</option></arg>
       <arg><option>--[no-]pristine-tar</option></arg>
       <arg><option>--ignore-branch</option></arg>
          makes you lose your modifications.</para></warning></para>
         </listitem>
       </varlistentry>
+      <varlistentry>
+        <term><option>--all</option></term>
+        <listitem>
+         <para>Update all remote-tracking branches that have identical name in the
+            remote repository.</para>
+        </listitem>
+      </varlistentry>
       <varlistentry>
         <term><option>--redo-pq</option></term>
         <listitem>
index e3aa099df1558829f0d5463946e4f2258479f5cf..41ff56cd2f13420b98bbcf0d088918aebd217db8 100755 (executable)
@@ -56,7 +56,8 @@ def fast_forward_branch(branch, repo, options):
             gbp.log.info("Non-fast forwarding '%s' due to --force" % branch)
             update = True
         else:
-            gbp.log.warn("Skipping non-fast forward of '%s' - use --force" % branch)
+            gbp.log.warn("Skipping non-fast forward of '%s' - use --force or "
+                         "update manually" % branch)
 
     if update:
         gbp.log.info("Updating '%s'" % branch)
@@ -82,6 +83,9 @@ def build_parser(name):
     branch_group.add_boolean_config_file_option(option_name = "ignore-branch", dest="ignore_branch")
     branch_group.add_option("--force", action="store_true", dest="force", default=False,
                       help="force a branch update even if it can't be fast forwarded")
+    branch_group.add_option("--all", action="store_true", default=False,
+                            help="update all remote-tracking branches that "
+                                 "have identical name in the remote")
     branch_group.add_option("--redo-pq", action="store_true", dest="redo_pq", default=False,
                       help="redo the patch queue branch after a pull. Warning: this drops the old patch-queue branch")
     branch_group.add_config_file_option(option_name="upstream-branch", dest="upstream_branch")
@@ -123,7 +127,7 @@ def main(argv):
         return 1
 
     try:
-        branches = []
+        branches = set()
         try:
             current = repo.get_branch()
         except GitRepositoryError:
@@ -136,10 +140,23 @@ def main(argv):
 
         for branch in [ options.debian_branch, options.upstream_branch ]:
             if repo.has_branch(branch):
-                branches += [ branch ]
+                branches.add(branch)
 
         if repo.has_pristine_tar_branch() and options.pristine_tar:
-            branches += [ repo.pristine_tar_branch ]
+            branches.add(repo.pristine_tar_branch)
+
+        if options.all:
+            current_remote = repo.get_merge_branch(current)
+            if current_remote:
+                fetch_remote = current_remote.split('/')[0]
+            else:
+                fetch_remote = 'origin'
+            for branch in repo.get_local_branches():
+                merge_branch = repo.get_merge_branch(branch)
+                if merge_branch:
+                    rem, rem_br = merge_branch.split('/', 1)
+                    if rem == fetch_remote and branch == rem_br:
+                        branches.add(branch)
 
         (ret, out) = repo.is_clean()
         if not ret: