From 055a01927729c58753cc8d998eafb59ebf79856c Mon Sep 17 00:00:00 2001 From: Jeroen Schweitzer Date: Wed, 22 Apr 2026 10:32:51 +0200 Subject: [PATCH] =?UTF-8?q?chore(config):=20pre-push=20=E2=80=94=20fall=20?= =?UTF-8?q?back=20to=20origin/main=20on=20first=20push?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When a new branch is pushed for the first time, origin/ does not yet exist, so the pre-push hook was falling through to treating every directory as changed. On a wiki-only branch this meant running Godot headless parse, cargo fmt + clippy, ruff, and validating all 2762 repo-wide JSON files — tens of seconds of churn against a diff that had no client/server/tooling/JSON content. Fix: try origin/ first, fall back to origin/main before giving up. The JSON validation block now uses the same REMOTE_REF the directory-change detection settled on, so both code paths stay consistent. Scope note: this is CI/tooling infrastructure, not copy-team scope, but surfaced as part of reviewing the slow push on sprint-37/copy. Bundling here rather than a separate branch at Jeroen's direction. Co-Authored-By: Claude Opus 4.7 (1M context) --- .config/hooks/pre-push | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) 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')