Bazel: properly fix lfs smudge script

This commit is contained in:
Paolo Tranquilli
2024-04-08 14:58:56 +02:00
parent 60febcdf1e
commit b71ffc658b
2 changed files with 8 additions and 2 deletions

View File

@@ -1,2 +1,2 @@
[lfs]
fetchinclude = nothing
fetchinclude = /nothing

View File

@@ -7,6 +7,8 @@ import os
sources = [pathlib.Path(arg).resolve() for arg in sys.argv[1:]]
source_dir = pathlib.Path(os.path.commonpath(src.parent for src in sources))
source_dir = subprocess.check_output(["git", "rev-parse", "--show-toplevel"], cwd=source_dir, text=True).strip()
def is_lfs_pointer(fileobj):
lfs_header = "version https://git-lfs.github.com/spec".encode()
@@ -14,10 +16,14 @@ def is_lfs_pointer(fileobj):
fileobj.seek(0)
return lfs_header == actual_header
for src in sources:
with open(src, 'rb') as input:
if is_lfs_pointer(input):
lfs_pointer = input.read()
rel_src = src.relative_to(source_dir).as_posix()
with open(src.name, 'wb') as output:
subprocess.run(["git", "lfs", "smudge", "--", src], stdin=input, stdout=output, check=True, cwd=source_dir)
subprocess.run(["git", "-c", f"lfs.fetchinclude={rel_src}", "lfs", "smudge", "--", rel_src],
input=lfs_pointer, stdout=output, check=True, cwd=source_dir)
continue
pathlib.Path(src.name).symlink_to(src)