import-orig: implement --create-missing-branches option
authorMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Wed, 12 Feb 2014 13:11:30 +0000 (15:11 +0200)
committerMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Thu, 5 Jun 2014 11:20:03 +0000 (14:20 +0300)
Create the upstream branch if it does not exist. Use the same option
name that import-dsc has.

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

index b744752..714a534 100644 (file)
@@ -26,6 +26,7 @@
       <arg><option>--[no-]merge</option></arg>
       <arg><option>--upstream-branch=</option><replaceable>branch_name</replaceable></arg>
       <arg><option>--debian-branch=</option><replaceable>branch_name</replaceable></arg>
+      <arg><option>--[no-]create-missing-branches</option></arg>
       <arg><option>--upstream-vcs-tag=</option><replaceable>tag_name</replaceable></arg>
       <arg><option>--[no-]sign-tags</option></arg>
       <arg><option>--keyid=</option><replaceable>gpg-keyid</replaceable></arg>
         </listitem>
       </varlistentry>
       <varlistentry>
+        <term><option>--[no-]create-missing-branches</option>
+        </term>
+        <listitem>
+          <para>
+          Create missing upstream branch if it does not exist.
+          </para>
+        </listitem>
+      </varlistentry>
+      <varlistentry>
         <term><option>--upstream-vcs-tag</option>=<replaceable>tag_name</replaceable>
         </term>
         <listitem>
index 2eb6330..67c9921 100644 (file)
@@ -29,7 +29,8 @@ import gbp.tristate
 no_upstream_branch_msg = """
 Repository does not have branch '%s' for upstream sources. If there is none see
 file:///usr/share/doc/git-buildpackage/manual-html/gbp.import.html#GBP.IMPORT.CONVERT
-on howto create it otherwise use --upstream-branch to specify it.
+on howto create it or check the --create-missing-branches option. Otherwise,
+use --upstream-branch to specify it.
 """
 
 def expand_path(option, opt, value):
index 3061994..baa0ab3 100644 (file)
@@ -209,6 +209,9 @@ def build_parser(name):
     branch_group.add_option("--upstream-vcs-tag", dest="vcs_tag",
                             help="Upstream VCS tag add to the merge commit")
     branch_group.add_boolean_config_file_option(option_name="merge", dest="merge")
+    branch_group.add_boolean_config_file_option(
+                      option_name="create-missing-branches",
+                      dest="create_missing_branches")
 
     tag_group.add_boolean_config_file_option(option_name="sign-tags",
                       dest="sign_tags")
@@ -283,7 +286,11 @@ def main(argv):
         is_empty = False if initial_branch else True
 
         if not repo.has_branch(options.upstream_branch) and not is_empty:
-            raise GbpError(no_upstream_branch_msg % options.upstream_branch)
+            if options.create_missing_branches:
+                gbp.log.info("Will create missing branch '%s'" %
+                             options.upstream_branch)
+            else:
+                raise GbpError(no_upstream_branch_msg % options.upstream_branch)
 
         (sourcepackage, version) = detect_name_and_version(repo, source, options)
 
@@ -334,10 +341,10 @@ def main(argv):
                 parents = None
 
             commit = repo.commit_dir(source.unpacked,
-                                     msg=msg,
-                                     branch=import_branch,
-                                     other_parents=parents,
-                                     )
+                        msg=msg,
+                        branch=import_branch,
+                        other_parents=parents,
+                        create_missing_branch=options.create_missing_branches)
 
             if options.pristine_tar:
                 if pristine_orig: