clone_repo(repo_url, dest_path, branch)
elif not is_fresh(sentinel):
set_remote(dest_path, repo_url)
- fetch(dest_path)
+ fetch_branch(dest_path, branch)
touch_file(sentinel)
else:
log.info("%s was just updated; assuming it is current", dest_path)
raise
-def clone_repo(repo_url, dest_path, branch):
+def clone_repo(repo_url, dest_path, branch, shallow=True):
"""
Clone a repo into a path
:param repo_url: The full URL to the repo (not including the branch)
:param dest_path: The full path to the destination directory
:param branch: The branch.
+ :param shallow: Whether to perform a shallow clone (--depth 1)
:raises: BranchNotFoundError if the branch is not found;
GitError for other errors
"""
validate_branch(branch)
log.info("Cloning %s %s from upstream", repo_url, branch)
+ args = ['git', 'clone']
+ if shallow:
+ args.extend(['--depth', '1'])
+ args.extend(['--branch', branch, repo_url, dest_path])
proc = subprocess.Popen(
- ('git', 'clone', '--branch', branch, repo_url, dest_path),
+ args,
cwd=os.path.dirname(dest_path),
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
:param repo_path: The full path to the repository
:raises: GitError if the operation fails
"""
- log.debug("Setting repo remote to %s", repo_url)
+ log.debug("Setting repo remote to %s", repo_url)
proc = subprocess.Popen(
('git', 'remote', 'set-url', 'origin', repo_url),
cwd=repo_path,
raise GitError("git fetch failed!")
-def fetch_branch(repo_path, branch):
+def fetch_branch(repo_path, branch, shallow=True):
"""
Call "git fetch -p origin <branch>"
:param repo_path: The full path to the repository on-disk
:param branch: The branch.
+ :param shallow: Whether to perform a shallow fetch (--depth 1)
:raises: BranchNotFoundError if the branch is not found;
GitError for other errors
"""
validate_branch(branch)
log.info("Fetching %s from upstream", branch)
+ args = ['git', 'fetch']
+ if shallow:
+ args.extend(['--depth', '1'])
+ args.extend(['-p', 'origin', branch])
proc = subprocess.Popen(
- ('git', 'fetch', '-p', 'origin', branch),
+ args,
cwd=repo_path,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)