pq-rpm: implement --new-packaging-dir cmdline option
authorMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Tue, 11 Feb 2014 08:18:47 +0000 (10:18 +0200)
committerMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Fri, 14 Nov 2014 12:47:20 +0000 (14:47 +0200)
Used for setting the packaging directory to be used in the new orphan
packaging branch. Defaults to --packaging-dir so that the gbp.conf files
are more likely to work without modification.

Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
gbp/scripts/pq_rpm.py
tests/component/rpm/test_pq_rpm.py

index 6c07c7258ad6d43d11f7b86f224f2754af9acc0e..7ee407dce9aa54b8c15a32a4513bc90d8fcac2d3 100755 (executable)
@@ -522,7 +522,8 @@ def convert_package(repo, options):
                  (old_packaging, new_branch))
     packaging_tree = '%s:%s' % (old_packaging, options.packaging_dir)
     packaging_tmp = tempfile.mkdtemp(prefix='pack_', dir=options.tmp_dir)
-    dump_tree(repo, packaging_tmp, packaging_tree, with_submodules=False,
+    dump_packaging_dir = os.path.join(packaging_tmp, options.new_packaging_dir)
+    dump_tree(repo, dump_packaging_dir, packaging_tree, with_submodules=False,
               recursive=False)
 
     msg = "Auto-import packaging files from branch '%s'" % old_packaging
@@ -530,9 +531,10 @@ def convert_package(repo, options):
     repo.set_branch(new_branch)
 
     # Generate patches
-    spec = SpecFile(spec.specfile)
+    spec = SpecFile(os.path.join(options.new_packaging_dir, spec.specfile))
     patches = update_patch_series(repo, spec, upstream_commit, old_packaging,
                                   options)
+    patches = [os.path.join(options.new_packaging_dir, pat) for pat in patches]
 
     # Commit paches and spec
     if patches:
@@ -588,6 +590,10 @@ def main(argv):
     parser.add_config_file_option(option_name="spec-file", dest="spec_file")
     parser.add_config_file_option(option_name="packaging-dir",
             dest="packaging_dir")
+    parser.add_option("--new-packaging-dir",
+            help="Packaging directory in the new packaging branch. Only "
+                 "relevant for the 'convert' action. If not defined, defaults "
+                 "to '--packaging-dir'")
     parser.add_config_file_option(option_name="packaging-branch",
             dest="packaging_branch",
             help="Branch the packaging is being maintained on. Only relevant "
@@ -612,6 +618,8 @@ def main(argv):
     (options, args) = parser.parse_args(argv)
     gbp.log.setup(options.color, options.verbose, options.color_scheme)
     options.patch_export_compress = string_to_int(options.patch_export_compress)
+    if options.new_packaging_dir is None:
+        options.new_packaging_dir = options.packaging_dir
 
     if len(args) < 2:
         gbp.log.err("No action given.")
index 69b760f4d1e0ac7a26eb998615eb0647dc7b389d..1bc15d52ad4e788e605abf2a6bf76f82972ab8be 100644 (file)
@@ -256,15 +256,16 @@ class TestPqRpm(RpmRepoTestBase):
         """Basic test for convert action"""
         repo = self.init_test_repo('gbp-test2')
         branches = repo.get_local_branches() + ['master-orphan']
-        files = ['bar.tar.gz', 'foo.txt', 'gbp-test2.spec',
-                 'gbp-test2-alt.spec', 'my.patch', '0001-My-addition.patch']
-
+        files = ['packaging/', 'packaging/bar.tar.gz', 'packaging/foo.txt',
+                 'packaging/gbp-test2.spec', 'packaging/gbp-test2-alt.spec',
+                 'packaging/my.patch', 'packaging/0001-My-addition.patch',
+                 '.gbp.conf']
         # First should fail because 'master-orphan' branch already exists
         eq_(mock_pq(['convert']), 1)
         self._check_log(-1, "gbp:error: Branch 'master-orphan' already exists")
 
         # Re-try with force
-        eq_(mock_pq(['convert', '--import-files=', '--force']), 0)
+        eq_(mock_pq(['convert', '--force']), 0)
         self._check_repo_state(repo, 'master-orphan', branches, files)
 
     def test_convert_fail(self):
@@ -520,6 +521,20 @@ class TestPqRpm(RpmRepoTestBase):
         ok_('debian/gbp.conf' not in repo.list_files())
         ok_('.gbp.conf' not in repo.list_files())
 
+    def test_option_new_packaging_dir(self):
+        """Test the --new-packaging-dir cmdline option"""
+        repo = self.init_test_repo('gbp-test2')
+        branches = repo.get_local_branches() + ['master-orphan']
+        files = ['rpm/', 'rpm/bar.tar.gz', 'rpm/foo.txt',
+                 'rpm/gbp-test2.spec', 'rpm/gbp-test2-alt.spec',
+                 'rpm/my.patch', 'rpm/0001-My-addition.patch']
+        # Drop already-existing master-orphan branch
+        repo.delete_branch('master-orphan')
+        # Try convert
+        eq_(mock_pq(['convert', '--import-files=',
+                     '--new-packaging-dir=rpm']), 0)
+        self._check_repo_state(repo, 'master-orphan', branches, files)
+
     def test_import_unapplicable_patch(self):
         """Test import when a patch does not apply"""
         repo = self.init_test_repo('gbp-test')