From 15f33236b438d9b1a5c371ecc9cdbdac87e5bad9 Mon Sep 17 00:00:00 2001 From: Tobias Fischer Date: Tue, 26 Mar 2024 03:13:16 +1000 Subject: [PATCH] Only fetch `lfs` files for specific `git_ref` (#5202) --- conda_build/source.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/conda_build/source.py b/conda_build/source.py index 3583f0b8ce..f1cfdb2613 100644 --- a/conda_build/source.py +++ b/conda_build/source.py @@ -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 ) @@ -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, @@ -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.