-
Notifications
You must be signed in to change notification settings - Fork 1.2k
erepo: --rev BRANCH: shallow clone #4246
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
Changes from all commits
a69d0ea
20c293c
7e28208
ffdd556
84e5f96
e2844f1
bc3948f
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 |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
import logging | ||
import os | ||
import shlex | ||
from functools import partial | ||
|
||
import yaml | ||
from funcy import cached_property | ||
|
@@ -92,7 +93,7 @@ def root_dir(self): | |
return self.repo.working_tree_dir | ||
|
||
@staticmethod | ||
def clone(url, to_path, rev=None): | ||
def clone(url, to_path, rev=None, shallow_branch=None): | ||
import git | ||
|
||
ld_key = "LD_LIBRARY_PATH" | ||
|
@@ -109,14 +110,23 @@ def clone(url, to_path, rev=None): | |
env[ld_key] = "" | ||
|
||
try: | ||
if shallow_branch is not None and os.path.exists(url): | ||
# git disables --depth for local clones unless file:// url | ||
# scheme is used | ||
url = f"file://{url}" | ||
with TqdmGit(desc="Cloning", unit="obj") as pbar: | ||
tmp_repo = git.Repo.clone_from( | ||
clone_from = partial( | ||
git.Repo.clone_from, | ||
url, | ||
to_path, | ||
env=env, # needed before we can fix it in __init__ | ||
no_single_branch=True, | ||
progress=pbar.update_git, | ||
) | ||
if shallow_branch is None: | ||
tmp_repo = clone_from() | ||
else: | ||
tmp_repo = clone_from(branch=shallow_branch, depth=1) | ||
Comment on lines
117
to
+129
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. seems essentially the same method as #3585 - just checking if @Suor has the same concern here as with https://github.com/iterative/dvc/pull/3585/files#r402728411 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. In this case the caller has to explicitly specify that they want a shallow clone now, rather than us making a choice in |
||
tmp_repo.close() | ||
except git.exc.GitCommandError as exc: # pylint: disable=no-member | ||
raise CloneError(url, to_path) from exc | ||
|
@@ -250,8 +260,8 @@ def checkout(self, branch, create_new=False): | |
else: | ||
self.repo.git.checkout(branch) | ||
|
||
def pull(self): | ||
infos = self.repo.remote().pull() | ||
def pull(self, **kwargs): | ||
infos = self.repo.remote().pull(**kwargs) | ||
for info in infos: | ||
if info.flags & info.ERROR: | ||
raise SCMError(f"pull failed: {info.note}") | ||
|
Uh oh!
There was an error while loading. Please reload this page.
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.
Since
rev=None
is supposed to mean tip on the default branch (master), we want to use origin/HEAD, not HEAD from our local clone working copy. Local HEAD points to the tip of whatever branch we first cloned from (which may not be the default branch), but here we want the tip of the default branch.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.
I would be happy to see such things commented about in dvc code.