From ccfa3f18a7629908b526f63b8d70ef05385636f9 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Nov 25 2015 10:00:18 +0000 Subject: [PATCH 1/5] 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 1a73275..a665c6f 100644 --- a/src/pyrpkg/__init__.py +++ b/src/pyrpkg/__init__.py @@ -1127,7 +1127,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 @@ -1141,6 +1142,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. """ @@ -1177,6 +1180,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 93543a1228b10a9ac55c31b362c6123b2864172a Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Nov 25 2015 10:00:20 +0000 Subject: [PATCH 2/5] 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 d8612198fea07e4e1832e41b0e177790873cfd6f Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Nov 25 2015 10:00:22 +0000 Subject: [PATCH 3/5] 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 6da911e..3e58002 100755 --- a/src/pyrpkg/cli.py +++ b/src/pyrpkg/cli.py @@ -378,6 +378,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 @@ -1008,10 +1012,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 2ebd8945b1847f79a6297e4393feb0b06857acaa Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Nov 25 2015 10:00:25 +0000 Subject: [PATCH 4/5] 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 a665c6f..12b2ec8 100644 --- a/src/pyrpkg/__init__.py +++ b/src/pyrpkg/__init__.py @@ -1171,7 +1171,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 e37e32d67598be23065c56c1e8601f258c7ab293 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Nov 25 2015 10:00:27 +0000 Subject: [PATCH 5/5] 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 12b2ec8..d1800c9 100644 --- a/src/pyrpkg/__init__.py +++ b/src/pyrpkg/__init__.py @@ -1189,8 +1189,8 @@ class Commands(object): self._run_command(cmd, cwd=path) if self.clone_config: - conf_git = git.Git( - os.path.join(path, bare_dir if bare_dir else module)) + git_dir = target if target else bare_dir if bare_dir else module + conf_git = git.Git(os.path.join(path, git_dir)) self._clone_config(conf_git, module) return