-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
get/import: --rev BRANCH: shallow clone #3585
Changes from all commits
28d16f7
fd66d76
cec5b58
a3cb0cd
e287dc9
d2666e8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
"""Manages Git.""" | ||
|
||
from functools import partial | ||
import logging | ||
import os | ||
import yaml | ||
|
@@ -71,16 +72,31 @@ def clone(url, to_path, rev=None): | |
# [1] https://github.com/gitpython-developers/GitPython/issues/924 | ||
env[ld_key] = "" | ||
|
||
clone_from = partial( | ||
git.Repo.clone_from, | ||
url, | ||
to_path, | ||
env=env, # needed before we can fix it in __init__ | ||
no_single_branch=True, | ||
) | ||
|
||
try: | ||
tmp_repo = git.Repo.clone_from( | ||
url, | ||
to_path, | ||
env=env, # needed before we can fix it in __init__ | ||
no_single_branch=True, | ||
) | ||
tmp_repo.close() | ||
if rev: | ||
logger.debug("attempting shallow clone of branch %s", rev) | ||
tmp_repo = clone_from(branch=rev, depth=1) | ||
else: | ||
logger.debug("full clone") | ||
tmp_repo = clone_from() | ||
Comment on lines
+84
to
+89
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is very dangerous code, which will cause us grief. We shouldn't hide that we are sometimes make shallow code and sometimes not from outside. Outside may rely on clone being full as it currently does in I mean if we do want to make shallow or single branch clone we should request it in a call signature. BTW, the retry below doesn't look good either, can we do it some other way? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we're going to have to fix "outside" (i.e. |
||
except git.exc.GitCommandError as exc: | ||
raise CloneError(url, to_path) from exc | ||
if not rev or ("Remote branch %s not found" % rev) not in str(exc): | ||
raise CloneError(url, to_path) from exc | ||
try: | ||
logger.debug("not a branch - performing full clone") | ||
tmp_repo = clone_from() | ||
except git.exc.GitCommandError as exc: | ||
raise CloneError(url, to_path) from exc | ||
|
||
tmp_repo.close() | ||
|
||
# NOTE: using our wrapper to make sure that env is fixed in __init__ | ||
repo = Git(to_path) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This breaks clones cache below. As it presumes it has default branch.