Skip to content

Commit

Permalink
Only fetch lfs files for specific git_ref (#5202)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobias-Fischer authored Mar 25, 2024
1 parent 51f81ce commit 15f3323
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions conda_build/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,19 +202,19 @@ def unpack(
shutil.move(os.path.join(tmpdir, f), os.path.join(src_dir, f))


def check_git_lfs(git, cwd):
def check_git_lfs(git, cwd, git_ref):
try:
lfs_list_output = check_output_env([git, "lfs", "ls-files", "--all"], cwd=cwd)
lfs_list_output = check_output_env([git, "lfs", "ls-files", git_ref], cwd=cwd)
return lfs_list_output and lfs_list_output.strip()
except CalledProcessError:
return False


def git_lfs_fetch(git, cwd, stdout, stderr):
def git_lfs_fetch(git, cwd, git_ref, stdout, stderr):
lfs_version = check_output_env([git, "lfs", "version"], cwd=cwd)
log.info(lfs_version)
check_call_env(
[git, "lfs", "fetch", "origin", "--all"], cwd=cwd, stdout=stdout, stderr=stderr
[git, "lfs", "fetch", "origin", git_ref], cwd=cwd, stdout=stdout, stderr=stderr
)


Expand Down Expand Up @@ -273,8 +273,8 @@ def git_mirror_checkout_recursive(
check_call_env(
[git, "fetch"], cwd=mirror_dir, stdout=stdout, stderr=stderr
)
if check_git_lfs(git, mirror_dir):
git_lfs_fetch(git, mirror_dir, stdout, stderr)
if check_git_lfs(git, mirror_dir, git_ref):
git_lfs_fetch(git, mirror_dir, git_ref, stdout, stderr)
else:
# Unlike 'git clone', fetch doesn't automatically update the cache's HEAD,
# So here we explicitly store the remote HEAD in the cache's local refs/heads,
Expand Down Expand Up @@ -318,8 +318,8 @@ def git_mirror_checkout_recursive(
check_call_env(
args + [git_url, git_mirror_dir], stdout=stdout, stderr=stderr
)
if check_git_lfs(git, mirror_dir):
git_lfs_fetch(git, mirror_dir, stdout, stderr)
if check_git_lfs(git, mirror_dir, git_ref):
git_lfs_fetch(git, mirror_dir, git_ref, stdout, stderr)
except CalledProcessError:
# on windows, remote URL comes back to us as cygwin or msys format. Python doesn't
# know how to normalize it. Need to convert it to a windows path.
Expand Down

0 comments on commit 15f3323

Please sign in to comment.