Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b71ffc6

Browse files
committed
Bazel: properly fix lfs smudge script
1 parent 60febcd commit b71ffc6

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

.lfsconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
[lfs]
2-
fetchinclude = nothing
2+
fetchinclude = /nothing

misc/bazel/internal/git_lfs_smudge.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,23 @@
77

88
sources = [pathlib.Path(arg).resolve() for arg in sys.argv[1:]]
99
source_dir = pathlib.Path(os.path.commonpath(src.parent for src in sources))
10+
source_dir = subprocess.check_output(["git", "rev-parse", "--show-toplevel"], cwd=source_dir, text=True).strip()
11+
1012

1113
def is_lfs_pointer(fileobj):
1214
lfs_header = "version https://git-lfs.github.com/spec".encode()
1315
actual_header = fileobj.read(len(lfs_header))
1416
fileobj.seek(0)
1517
return lfs_header == actual_header
1618

19+
1720
for src in sources:
1821
with open(src, 'rb') as input:
1922
if is_lfs_pointer(input):
23+
lfs_pointer = input.read()
24+
rel_src = src.relative_to(source_dir).as_posix()
2025
with open(src.name, 'wb') as output:
21-
subprocess.run(["git", "lfs", "smudge", "--", src], stdin=input, stdout=output, check=True, cwd=source_dir)
26+
subprocess.run(["git", "-c", f"lfs.fetchinclude={rel_src}", "lfs", "smudge", "--", rel_src],
27+
input=lfs_pointer, stdout=output, check=True, cwd=source_dir)
2228
continue
2329
pathlib.Path(src.name).symlink_to(src)

0 commit comments

Comments
 (0)