From d2ebfaee99f0a0d72a987a38a39015143d02330f Mon Sep 17 00:00:00 2001 From: Todd Zullinger Date: Jun 11 2018 05:29:48 +0000 Subject: Provide base_module to clone_config templates When cloning from a namespaced repository, the clone_config template may wish to use the module with and without the namespace prefix. Use the get_base_module() function to extract base_module and expand it when found in a clone_config template. Resolves: #326 Signed-off-by: Todd Zullinger --- diff --git a/pyrpkg/__init__.py b/pyrpkg/__init__.py index 2640ce2..3c8f5b3 100644 --- a/pyrpkg/__init__.py +++ b/pyrpkg/__init__.py @@ -1352,7 +1352,9 @@ class Commands(object): conf_git.config('credential.useHttpPath', 'true') # Set any other clone_config if self.clone_config: - clone_config = self.clone_config.strip() % {'module': module} + base_module = self.get_base_module(module) + clone_config = self.clone_config.strip() % { + 'base_module': base_module, 'module': module} for confline in clone_config.splitlines(): if confline: conf_git.config(*confline.split()) diff --git a/tests/commands/test_clone.py b/tests/commands/test_clone.py index f4daff0..ad5272a 100644 --- a/tests/commands/test_clone.py +++ b/tests/commands/test_clone.py @@ -106,6 +106,26 @@ class CommandCloneTestCase(CommandTestCase): self.assertTrue(os.path.isdir(clonedir)) self.assertFalse(os.path.exists(os.path.join(clonedir, 'index'))) + def test_clone_config_template_accepts_base_module(self): + self.module = 'rpms/module1' + self.base_module = 'module1' + self.make_new_git(self.module) + + import pyrpkg + cmd = pyrpkg.Commands(self.path, self.lookaside, self.lookasidehash, + self.lookaside_cgi, self.gitbaseurl, + self.anongiturl, self.branchre, self.kojiprofile, + self.build_client, self.user, self.dist, + self.target, self.quiet, distgit_namespaced=True) + cmd.clone_config = 'bz.default-component %(base_module)s' + cmd.clone(self.module, anon=True) + + moduledir = os.path.join(self.path, 'module1') + self.assertTrue(os.path.isdir(os.path.join(moduledir, '.git'))) + confgit = git.Git(moduledir) + self.assertEqual(confgit.config( + 'bz.default-component'), self.base_module) + def test_clone_fails_with_both_branch_and_bare_dir(self): self.make_new_git(self.module, branches=['rpkg-tests-1', 'rpkg-tests-2'])