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>
Tue, 3 Mar 2015 08:07:45 +0000 (10:07 +0200)
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 6b0993f894d98c783fd89ec462b8dbd2d9349257..c6ed546e2b17806036e3bd8d985f12d279a1ef52 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>
           </para>
         </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>
index 55f4710451d6c6b3a5bf36492179d4bddf764b8b..7a26e54b4ea95c0476749097ec29d5a8fd351286 100644 (file)
@@ -33,7 +33,8 @@ from gbp.git import GitRepositoryError, GitRepository
 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 84905617f99d570c8da8e3f949ba3206ef6ed7d7..69e076ab5cf98da1124a8804127224120d3e6942 100644 (file)
@@ -211,6 +211,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")
@@ -313,7 +316,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)
 
@@ -364,10 +371,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: