summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCasey Dahlin <cdahlin@redhat.com>2010-06-17 03:47:03 -0400
committerCasey Dahlin <cdahlin@redhat.com>2010-06-17 04:01:57 -0400
commit12efa2f8060b42cf38c4e96b8477db4ff79f8240 (patch)
treee5ef87e129de647de27fc8d400a27c0a7a1d456c
parenta0906dcea34827c094df8624072b2b8756738a6d (diff)
downloadfedpkg-12efa2f8060b42cf38c4e96b8477db4ff79f8240.tar.gz
fedpkg-12efa2f8060b42cf38c4e96b8477db4ff79f8240.tar.xz
fedpkg-12efa2f8060b42cf38c4e96b8477db4ff79f8240.zip
Implement fedpkg.py clone --branches
-rw-r--r--src/pyfedpkg/__init__.py46
1 files changed, 39 insertions, 7 deletions
diff --git a/src/pyfedpkg/__init__.py b/src/pyfedpkg/__init__.py
index 9350207..e4380b8 100644
--- a/src/pyfedpkg/__init__.py
+++ b/src/pyfedpkg/__init__.py
@@ -138,7 +138,7 @@ def clean(dry=False, useignore=True):
log.error(error)
return proc.returncode
-def clone(module, user, path=os.getcwd(), branch=None):
+def clone(module, user, path=os.getcwd(), branch=None, bare_dir=None):
"""Clone a repo, optionally check out a specific branch.
module is the name of the module to clone
@@ -157,11 +157,19 @@ def clone(module, user, path=os.getcwd(), branch=None):
mygit = git.Git(path)
# do the clone and capture the output
try:
- if branch:
+ if branch and bare_dir:
+ log.debug('Cloning %s with branch %s' % (giturl, branch))
+ retcode, output, error = mygit.clone('--branch', branch, '--bare',
+ giturl, bare_dir,
+ with_extended_output=True)
+ elif branch:
log.debug('Cloning %s with branch %s' % (giturl, branch))
retcode, output, error = mygit.clone('--branch', branch,
giturl,
with_extended_output=True)
+ elif bare_dir:
+ retcode, output, error = mygit.clone('--bare', giturl, bare_dir,
+ with_extended_output=True)
else:
log.debug('Cloning %s' % giturl)
retcode, output, error = mygit.clone(giturl,
@@ -173,7 +181,7 @@ def clone(module, user, path=os.getcwd(), branch=None):
log.error(error)
return retcode
-def clone_with_dirs(module, user):
+def clone_with_dirs(module, user, path=os.getcwd()):
"""Clone a repo old style with subdirs for each branch.
module is the name of the module to clone
@@ -182,10 +190,34 @@ def clone_with_dirs(module, user):
"""
- # not implemented yet
- print('would have cloned %s with dirs as user %s' %
- (module, user))
- return
+ top_path = os.path.join(path, module)
+
+ try:
+ os.mkdir(top_path)
+ except (OSError), e:
+ raise FedpkgError('Could not create directory for module %s: %s' %
+ (module, e))
+
+ clone(module, user, top_path, bare_dir="fedpkg.git")
+ repo_path = os.path.join(top_path, "fedpkg.git")
+
+ repo_git = git.Git(repo_path)
+ branches = [x for x in repo_git.branch().split() if x != "*"]
+ top_git = git.Git(top_path)
+
+ for branch in branches:
+ try:
+ branch_path = os.path.join(top_path, branch)
+ # Git will automatically use hardlinks for local clones if such is
+ # possible. No need for fancy switches.
+ top_git.clone("--branch", branch, repo_path, branch)
+ except (git.GitCommandError, OSError), e:
+ raise FedpkgError('Could not locally clone %s from %s: %s' %
+ (branch, repo_path, e))
+
+ # consistent with clone method since the commands should return 0 when
+ # successful.
+ return 0
def get_latest_commit(module):
"""Discover the latest commit has for a given module and return it"""