From 90bcac1fc6a0bfd409b6c1f69b4096bee6983ffd Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Jun 07 2016 15:03:51 +0000 Subject: [PATCH 1/7] Let rpkg support cloning into a specified directory Signed-off-by: Pierre-Yves Chibon --- diff --git a/src/pyrpkg/__init__.py b/src/pyrpkg/__init__.py index 4a92d86..d77a767 100644 --- a/src/pyrpkg/__init__.py +++ b/src/pyrpkg/__init__.py @@ -1232,7 +1232,8 @@ class Commands(object): self._run_command(cmd, cwd=self.path) return - def clone(self, module, path=None, branch=None, bare_dir=None, anon=False): + def clone(self, module, path=None, branch=None, bare_dir=None, + anon=False, target=None): """Clone a repo, optionally check out a specific branch. module is the name of the module to clone @@ -1246,6 +1247,8 @@ class Commands(object): anon is whether or not to clone anonymously + target is the name of the folder in which to clone the repo + Logs the output and returns nothing. """ @@ -1282,6 +1285,10 @@ class Commands(object): # --bare and --origin are incompatible cmd.extend(['--origin', self.default_branch_remote]) + if target: + self.log.debug('Cloning into: %s' % target) + cmd.append(target) + self._run_command(cmd, cwd=path) if self.clone_config: From b1cff8afcd514b1934e2fcd21f075c9696f3b7c1 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Jun 07 2016 15:03:51 +0000 Subject: [PATCH 2/7] Add unit-tests for cloning into a specified directory Signed-off-by: Pierre-Yves Chibon --- diff --git a/test/commands/test_clone.py b/test/commands/test_clone.py index cc02907..981c40a 100644 --- a/test/commands/test_clone.py +++ b/test/commands/test_clone.py @@ -99,3 +99,20 @@ class CommandCloneTestCase(CommandTestCase): cmd.clone(self.module, anon=True, branch='rpkg-tests-1', bare_dir='test.git') self.assertRaises(pyrpkg.rpkgError, raises) + + def test_clone_into_dir(self): + self.make_new_git(self.module, + branches=['rpkg-tests-1', 'rpkg-tests-2']) + + import pyrpkg + cmd = pyrpkg.Commands(self.path, self.lookaside, self.lookasidehash, + self.lookaside_cgi, self.gitbaseurl, + self.anongiturl, self.branchre, self.kojiconfig, + self.build_client, self.user, self.dist, + self.target, self.quiet) + cmd.clone( + self.module, anon=True, branch='rpkg-tests-1', target='new_clone') + + with open(os.path.join( + self.path, 'new_clone', '.git', 'HEAD')) as HEAD: + self.assertEqual(HEAD.read(), 'ref: refs/heads/rpkg-tests-1\n') From 47f94bee7bea0c900731c5ecddb96e21e9d70aac Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Jun 07 2016 15:03:51 +0000 Subject: [PATCH 3/7] Add to the CLI the possibility to specify a target folder for the clone Signed-off-by: Pierre-Yves Chibon --- diff --git a/src/pyrpkg/cli.py b/src/pyrpkg/cli.py index e28bda7..e254d31 100755 --- a/src/pyrpkg/cli.py +++ b/src/pyrpkg/cli.py @@ -381,6 +381,10 @@ defined, packages will be built sequentially.""" % {'name': self.name}) # store the module to be cloned clone_parser.add_argument( 'module', nargs=1, help='Name of the module to clone') + # Eventually specify where to clone the module + clone_parser.add_argument( + "clone_target", default=None, nargs="?", + help='Directory in which to clone the module') clone_parser.set_defaults(command=self.clone) # Add an alias for historical reasons @@ -1014,10 +1018,13 @@ see API KEY section of copr-cli(1) man page. def clone(self): if self.args.branches: self.cmd.clone_with_dirs(self.args.module[0], - anon=self.args.anonymous) + anon=self.args.anonymous, + target=self.args.clone_target) else: - self.cmd.clone(self.args.module[0], branch=self.args.branch, - anon=self.args.anonymous) + self.cmd.clone(self.args.module[0], + branch=self.args.branch, + anon=self.args.anonymous, + target=self.args.clone_target) def commit(self): if self.args.clog: From 86d6211a1c9819fe62399c69e56c0bf49b171df0 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Jun 07 2016 15:03:51 +0000 Subject: [PATCH 4/7] Only clone into the bare_dir if no target was specified Signed-off-by: Pierre-Yves Chibon --- diff --git a/src/pyrpkg/__init__.py b/src/pyrpkg/__init__.py index d77a767..4ca0115 100644 --- a/src/pyrpkg/__init__.py +++ b/src/pyrpkg/__init__.py @@ -1276,7 +1276,9 @@ class Commands(object): cmd.extend(['-b', branch, giturl]) elif bare_dir: self.log.debug('Cloning %s bare' % giturl) - cmd.extend(['--bare', giturl, bare_dir]) + cmd.extend(['--bare', giturl]) + if not target: + cmd.append(bare_dir) else: self.log.debug('Cloning %s' % giturl) cmd.extend([giturl]) From 544965dc6265ab8e372afb1e445ee1170d8ee6c2 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Jun 07 2016 15:03:51 +0000 Subject: [PATCH 5/7] Adjust figuring out the path of the git repo cloned If the repo was cloned into a target, then target is the new location if there was not target but the repo was cloned to a bare repo, then bare_dir is the new location, otherwise it's module Signed-off-by: Pierre-Yves Chibon --- diff --git a/src/pyrpkg/__init__.py b/src/pyrpkg/__init__.py index 4ca0115..382745b 100644 --- a/src/pyrpkg/__init__.py +++ b/src/pyrpkg/__init__.py @@ -1303,9 +1303,8 @@ class Commands(object): else: base_module = module - conf_git = git.Git( - os.path.join(path, bare_dir if bare_dir else base_module) - ) + git_dir = target if target else bare_dir if bare_dir else base_module + conf_git = git.Git(os.path.join(path, git_dir)) self._clone_config(conf_git, module) return From 93547cb67de0ad7c5bb3440f4db8f84cf1d45ade Mon Sep 17 00:00:00 2001 From: Lubomír Sedlář Date: Jun 07 2016 15:03:51 +0000 Subject: [PATCH 6/7] Fix cloning with -B and namespaced module Signed-off-by: Lubomír Sedlář --- diff --git a/src/pyrpkg/__init__.py b/src/pyrpkg/__init__.py index 382745b..e9aec4f 100644 --- a/src/pyrpkg/__init__.py +++ b/src/pyrpkg/__init__.py @@ -1294,22 +1294,23 @@ class Commands(object): self._run_command(cmd, cwd=path) if self.clone_config: - # Handle namespaced modules - # Example: - # module: docker/cockpit - # The path will just be os.path.join(path, "cockpit") - if "/" in module: - base_module = module.split("/")[-1] - else: - base_module = module - + base_module = self.get_base_module(module) git_dir = target if target else bare_dir if bare_dir else base_module conf_git = git.Git(os.path.join(path, git_dir)) self._clone_config(conf_git, module) return - def clone_with_dirs(self, module, anon=False): + def get_base_module(self, module): + # Handle namespaced modules + # Example: + # module: docker/cockpit + # The path will just be os.path.join(path, "cockpit") + if "/" in module: + return module.split("/")[-1] + return module + + def clone_with_dirs(self, module, anon=False, target=None): """Clone a repo old style with subdirs for each branch. module is the name of the module to clone @@ -1321,7 +1322,7 @@ class Commands(object): self._push_url = None self._branch_remote = None # Get the full path of, and git object for, our directory of branches - top_path = os.path.join(self.path, module) + top_path = os.path.join(self.path, target or self.get_base_module(module)) top_git = git.Git(top_path) repo_path = os.path.join(top_path, 'rpkg.git') From 094303a93c10890a6db1d2969e49a9c74924ef35 Mon Sep 17 00:00:00 2001 From: Lubomír Sedlář Date: Jun 07 2016 15:03:51 +0000 Subject: [PATCH 7/7] Add tests for cloning with a namespace Signed-off-by: Lubomír Sedlář --- diff --git a/test/commands/__init__.py b/test/commands/__init__.py index a4cf160..56b53a3 100644 --- a/test/commands/__init__.py +++ b/test/commands/__init__.py @@ -55,7 +55,7 @@ class CommandTestCase(unittest.TestCase): subprocess.check_call(['git', 'clone', 'file://%s' % moduledir], cwd=cloneroot, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - clonedir = os.path.join(cloneroot, module) + clonedir = os.path.join(cloneroot, module.split('/')[-1]) open(os.path.join(clonedir, '.gitignore'), 'w').close() open(os.path.join(clonedir, 'sources'), 'w').close() subprocess.check_call(['git', 'add', '.gitignore', 'sources'], diff --git a/test/commands/test_clone.py b/test/commands/test_clone.py index 981c40a..b6cf492 100644 --- a/test/commands/test_clone.py +++ b/test/commands/test_clone.py @@ -32,6 +32,26 @@ class CommandCloneTestCase(CommandTestCase): self.assertEqual(confgit.config('sendemail.to'), "%s-owner@fedoraproject.org" % self.module) + def test_clone_anonymous_with_namespace(self): + self.module = 'rpms/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.kojiconfig, + self.build_client, self.user, self.dist, + self.target, self.quiet, distgit_namespaced=True) + cmd.clone_config = CLONE_CONFIG + 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.module) + self.assertEqual(confgit.config('sendemail.to'), + "%s-owner@fedoraproject.org" % self.module) + def test_clone_anonymous_with_path(self): self.make_new_git(self.module) @@ -116,3 +136,21 @@ class CommandCloneTestCase(CommandTestCase): with open(os.path.join( self.path, 'new_clone', '.git', 'HEAD')) as HEAD: self.assertEqual(HEAD.read(), 'ref: refs/heads/rpkg-tests-1\n') + + def test_clone_into_dir_with_namespace(self): + self.module = 'rpms/module1' + self.make_new_git(self.module, + branches=['rpkg-tests-1', 'rpkg-tests-2']) + + import pyrpkg + cmd = pyrpkg.Commands(self.path, self.lookaside, self.lookasidehash, + self.lookaside_cgi, self.gitbaseurl, + self.anongiturl, self.branchre, self.kojiconfig, + self.build_client, self.user, self.dist, + self.target, self.quiet, distgit_namespaced=True) + cmd.clone( + self.module, anon=True, branch='rpkg-tests-1', target='new_clone') + + with open(os.path.join( + self.path, 'new_clone', '.git', 'HEAD')) as HEAD: + self.assertEqual(HEAD.read(), 'ref: refs/heads/rpkg-tests-1\n')