From bc7593a716a7e219328599b03ec679299ee0c8b0 Mon Sep 17 00:00:00 2001 From: Casey Dahlin Date: Fri, 25 Jun 2010 20:43:30 -0400 Subject: Point branches to the correct upstream for clone --branches Also get rid of fedpkg.git and improve some documentation --- src/pyfedpkg/__init__.py | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'src/pyfedpkg/__init__.py') diff --git a/src/pyfedpkg/__init__.py b/src/pyfedpkg/__init__.py index 6359541..fe34533 100644 --- a/src/pyfedpkg/__init__.py +++ b/src/pyfedpkg/__init__.py @@ -11,6 +11,7 @@ import os import sys +import shutil #import pycurl import subprocess import hashlib @@ -254,6 +255,9 @@ def clone(module, user, path=os.getcwd(), branch=None, bare_dir=None): branch is the name of a branch to checkout instead of origin/master + bare_dir is the name of a directory to make a bare clone too if this is a + bare clone. None otherwise. + Logs the output and returns nothing. """ @@ -287,31 +291,43 @@ def clone_with_dirs(module, user, path=os.getcwd()): """ + # Get the full path of, and git object for, our directory of branches top_path = os.path.join(path, module) + top_git = git.Git(top_path) + # Create our new top directory try: os.mkdir(top_path) except (OSError), e: raise FedpkgError('Could not create directory for module %s: %s' % (module, e)) + # Create a bare clone first. This gives us a good list of branches clone(module, user, top_path, bare_dir="fedpkg.git") + # Get the full path to, and a git object for, our new bare repo repo_path = os.path.join(top_path, "fedpkg.git") - repo_git = git.Git(repo_path) + + # Get a branch listing 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. + # Make a local clone for our branch top_git.clone("--branch", branch, repo_path, branch) + + # Set the origin correctly + branch_path = os.path.join(top_path, branch) + branch_git = git.Git(branch_path) + branch_git.config("--replace-all", "remote.origin.url", + GITBASEURL % {'user': user, 'module': module}) except (git.GitCommandError, OSError), e: raise FedpkgError('Could not locally clone %s from %s: %s' % (branch, repo_path, e)) + # We don't need this now. Ignore errors since keeping it does no harm + shutil.rmtree(repo_path, ignore_errors=True) + # consistent with clone method since the commands should return 0 when # successful. return 0 -- cgit