From a4f4ac3ad023be838f50b463b7ce785cf8e0de23 Mon Sep 17 00:00:00 2001 From: Jesse Keating Date: Wed, 6 Jan 2010 16:55:00 -0800 Subject: Finish up the clone function More use of the git module and it's lambda for running arbitrary git commands. There is no clone command within the git module. --- src/fedpkg/__init__.py | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) (limited to 'src/fedpkg') diff --git a/src/fedpkg/__init__.py b/src/fedpkg/__init__.py index e296af6..85805ea 100644 --- a/src/fedpkg/__init__.py +++ b/src/fedpkg/__init__.py @@ -136,26 +136,40 @@ def clean(dry=False, useignore=True): log.error(error) return proc.returncode -def clone(module, user, branch=None): +def clone(module, user, path=os.getcwd(), branch=None): """Clone a repo, optionally check out a specific branch. module is the name of the module to clone + path is the basedir to perform the clone in + branch is the name of a branch to checkout instead of origin/master - gitargs is an optional list of arguments to git clone + Logs the output and returns the return code """ - # not implemented yet # construct the git url giturl = GITBASEURL % {'user': user, 'module': module} - cmd = ['git', 'clone'] - if branch: - cmd.extend(['--branch', branch]) - cmd.append(giturl) - print('Would have ran %s' % subprocess.list2cmdline(cmd)) - return + # Create the git object + mygit = git.Git(path) + # do the clone and capture the output + try: + if branch: + log.debug('Cloning %s with branch %s' % (giturl, branch)) + retcode, output, error = mygit.clone('--branch', branch, + giturl, + with_extended_output=True) + else: + log.debug('Cloning %s' % giturl) + retcode, output, error = mygit.clone(giturl, + with_extended_output=True) + except (git.GitCommandError, OSError), e: + raise FedpkgError('Could not clone %s: %s' % (giturl, e)) + log.info(output) + if error: + log.error(error) + return retcode def clone_with_dirs(module, user): """Clone a repo old style with subdirs for each branch. -- cgit