diff --git a/.config/hooks/pre-push b/.config/hooks/pre-push index bd5a0390c..0e1d7dfd6 100755 --- a/.config/hooks/pre-push +++ b/.config/hooks/pre-push @@ -9,14 +9,27 @@ ERRORS=0 echo "pre-push: running lint checks..." # --- Detect which directories have changes vs remote --- +# Prefer origin/ as the baseline (what the remote already has), +# but fall back to origin/main for first-push of a new branch — otherwise +# every check runs against nothing and the hook treats the whole repo as +# changed, spending tens of seconds on linters and JSON validation that +# have no diff to cover (e.g. pushing a wiki-only branch rebuilds GDScript +# and runs clippy + ruff + validates all 2762 JSON files). BRANCH=$(git branch --show-current) -REMOTE_REF="origin/$BRANCH" -if git rev-parse --verify "$REMOTE_REF" >/dev/null 2>&1; then +if git rev-parse --verify "origin/$BRANCH" >/dev/null 2>&1; then + REMOTE_REF="origin/$BRANCH" +elif git rev-parse --verify "origin/main" >/dev/null 2>&1; then + REMOTE_REF="origin/main" +else + REMOTE_REF="" +fi + +if [ -n "$REMOTE_REF" ]; then CLIENT_CHANGED=$(git diff --name-only "$REMOTE_REF"..HEAD -- client/ 2>/dev/null | wc -l) SERVER_CHANGED=$(git diff --name-only "$REMOTE_REF"..HEAD -- server/ 2>/dev/null | wc -l) TOOLING_CHANGED=$(git diff --name-only "$REMOTE_REF"..HEAD -- tooling/ pyproject.toml 2>/dev/null | wc -l) else - # New branch or no remote ref — fall through to directory checks + # No remote at all (e.g. fresh clone before first fetch) — be safe, run everything CLIENT_CHANGED=1 SERVER_CHANGED=1 TOOLING_CHANGED=1 @@ -114,7 +127,12 @@ else fi # --- JSON syntax validation --- -if git rev-parse --verify "$REMOTE_REF" >/dev/null 2>&1; then +# Use the same REMOTE_REF the directory-change detection above settled on +# (origin/ preferred, origin/main fallback). Without this, a first +# push of a new branch falls through to "validate every JSON in the repo," +# which on this repo means 2762 Python parses — tens of seconds of churn +# for a push that might not have touched any JSON at all. +if [ -n "$REMOTE_REF" ]; then JSON_FILES=$(git diff --name-only "$REMOTE_REF"..HEAD -- '*.json' 2>/dev/null || true) else JSON_FILES=$(git ls-files '*.json')