Repository navigation
Expand file tree
/
Copy pathpost-sync.py
More file actions
58 lines (47 loc) · 1.91 KB
/
Copy pathpost-sync.py
File metadata and controls
58 lines (47 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
"""repo post-sync hook: materialise Git LFS payloads.
repo knows nothing about Git LFS. On a fresh checkout the tracked files
are left as their pointer text -- a few dozen bytes naming an object --
and whatever reads them fails on a file that is not what it claims to be.
The WebView APK is the visible case: signapk reports "zip END header not
found" while looking at 134 bytes of ASCII.
Fetching them here keeps a plain `repo sync` sufficient, with no extra
step to remember and nothing to configure per machine.
"""
import os
import shutil
import subprocess
# Projects whose .gitattributes routes files through LFS, as manifest paths.
LFS_PROJECTS = ("device/rise",)
def _pull(worktree):
"""Fetch the LFS objects of one worktree, returning an error or None."""
# --local keeps the filter config inside this worktree: the hook stays
# self-contained instead of writing to the user's ~/.gitconfig.
for args in (("lfs", "install", "--local"), ("lfs", "pull")):
result = subprocess.run(
("git", "-C", worktree) + args,
capture_output=True,
text=True,
)
if result.returncode:
return (result.stderr or result.stdout).strip()
return None
def main(repo_topdir=None, **kwargs):
topdir = repo_topdir or os.getcwd()
worktrees = [
os.path.join(topdir, path)
for path in LFS_PROJECTS
if os.path.exists(os.path.join(topdir, path, ".git"))
]
if not worktrees:
return
if not shutil.which("git-lfs"):
print(
"post-sync: git-lfs is not installed, leaving %d project(s) on "
"their LFS pointers. Install it and re-run `repo sync`, or the "
"WebView APK will not sign." % len(worktrees)
)
return
for worktree in worktrees:
error = _pull(worktree)
if error:
print("post-sync: git lfs pull failed in %s: %s" % (worktree, error))