feat: sparse checkout + shallow fetch для минимального трафика

- git_pull() использует fetch --depth 1 + reset (не качает историю)
- sparse checkout: скачивается только latest версия cli.js, не все
- Все старые версии остаются в репо, но клиент их не скачивает
- README обновлён с git clone --depth 1

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
delta-cloud-208e
2026-02-21 11:42:49 +00:00
parent 71c6fdf7b0
commit 3bc69d4eff
3 changed files with 54 additions and 3 deletions

View File

@@ -150,7 +150,7 @@ def ver_tuple(v):
def git_pull():
"""Pull latest changes from remote (shallow fetch for minimal download)."""
try:
# Shallow fetch + reset — downloads only latest snapshot, not full history
# Shallow fetch + reset — downloads only latest commit, not full history
result = subprocess.run(
["git", "fetch", "--depth", "1", "origin", "master"],
cwd=SCRIPT_DIR, capture_output=True, text=True, timeout=60,
@@ -170,6 +170,10 @@ def git_pull():
["git", "reset", "--hard", "origin/master"],
cwd=SCRIPT_DIR, capture_output=True, text=True, timeout=10,
)
# Setup sparse checkout to download only latest version's cli.js
_setup_sparse_checkout()
return True
except subprocess.TimeoutExpired:
eprint(f" {Y}git fetch timed out{D}")
@@ -179,6 +183,50 @@ def git_pull():
return True
def _setup_sparse_checkout():
"""Configure sparse checkout to only include root files + latest release.
This avoids downloading cli.js for ALL versions (each ~12MB).
Only the latest version's cli.js is checked out.
"""
index_path = os.path.join(SCRIPT_DIR, "claude", "releases", "index.json")
if not os.path.isfile(index_path):
return
try:
with open(index_path, "r") as f:
latest = json.load(f).get("latest")
except Exception:
return
if not latest:
return
# Enable sparse checkout
subprocess.run(
["git", "config", "core.sparseCheckout", "true"],
cwd=SCRIPT_DIR, capture_output=True,
)
sparse_file = os.path.join(SCRIPT_DIR, ".git", "info", "sparse-checkout")
os.makedirs(os.path.dirname(sparse_file), exist_ok=True)
patterns = [
"/*", # root files (updater, config, README)
"/claude/releases/index.json", # version index
f"/claude/releases/v{latest}/", # latest release (cli.js + changelog + install)
]
with open(sparse_file, "w") as f:
f.write("\n".join(patterns) + "\n")
# Apply sparse checkout
subprocess.run(
["git", "checkout", "HEAD", "--", "."],
cwd=SCRIPT_DIR, capture_output=True, timeout=30,
)
# ============================================================
# CLI.js installation
# ============================================================