fix(config): make pre-push hook tolerant of cold worktrees
Skip checks gracefully when .godot/, client/scripts/, or server/target/ don't exist instead of failing. Worktree branches can now push without needing a full Godot import or Rust build first. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
+17
-11
@@ -10,7 +10,7 @@ echo "pre-push: running lint checks..."
|
||||
|
||||
# --- GDScript parse check (headless Godot) ---
|
||||
GODOT="${GODOT:-godot}"
|
||||
if command -v "$GODOT" >/dev/null 2>&1; then
|
||||
if command -v "$GODOT" >/dev/null 2>&1 && [ -d "$REPO_ROOT/client/.godot" ]; then
|
||||
echo "pre-push: checking GDScript (parse)..."
|
||||
SCRIPT_ERRORS=$("$GODOT" --headless --path "$REPO_ROOT/client" --quit 2>&1 | grep -ci "SCRIPT ERROR" || true)
|
||||
if [ "$SCRIPT_ERRORS" -gt 0 ]; then
|
||||
@@ -21,11 +21,11 @@ if command -v "$GODOT" >/dev/null 2>&1; then
|
||||
echo "pre-push: GDScript parse — OK"
|
||||
fi
|
||||
else
|
||||
echo "pre-push: WARNING — Godot not found, skipping GDScript parse check"
|
||||
echo "pre-push: skipping GDScript parse (no .godot/ import — run Godot once to enable)"
|
||||
fi
|
||||
|
||||
# --- GDScript lint (gdlint static analysis) — advisory only until codebase is clean ---
|
||||
if command -v gdlint >/dev/null 2>&1; then
|
||||
if command -v gdlint >/dev/null 2>&1 && [ -d "$REPO_ROOT/client/scripts" ]; then
|
||||
echo "pre-push: checking GDScript (gdlint — advisory)..."
|
||||
LINT_COUNT=$(gdlint "$REPO_ROOT/client/scripts/" "$REPO_ROOT/client/ui/" 2>&1 | grep -c "Error:" || true)
|
||||
if [ "$LINT_COUNT" -gt 0 ]; then
|
||||
@@ -36,7 +36,7 @@ if command -v gdlint >/dev/null 2>&1; then
|
||||
fi
|
||||
|
||||
# --- GDScript format check (gdformat) — advisory only until codebase is clean ---
|
||||
if command -v gdformat >/dev/null 2>&1; then
|
||||
if command -v gdformat >/dev/null 2>&1 && [ -d "$REPO_ROOT/client/scripts" ]; then
|
||||
echo "pre-push: checking GDScript (gdformat — advisory)..."
|
||||
FORMAT_COUNT=$(gdformat --check "$REPO_ROOT/client/scripts/" "$REPO_ROOT/client/ui/" 2>&1 | grep -c "would reformat" || true)
|
||||
if [ "$FORMAT_COUNT" -gt 0 ]; then
|
||||
@@ -48,13 +48,7 @@ fi
|
||||
|
||||
# --- Rust lint (clippy + fmt) ---
|
||||
if command -v cargo >/dev/null 2>&1 && [ -d "$REPO_ROOT/server" ]; then
|
||||
echo "pre-push: checking Rust (clippy)..."
|
||||
if ! (cd "$REPO_ROOT/server" && cargo clippy -- -D warnings 2>&1); then
|
||||
ERRORS=$((ERRORS + 1))
|
||||
else
|
||||
echo "pre-push: clippy — OK"
|
||||
fi
|
||||
|
||||
# fmt only needs source files — always safe to run
|
||||
echo "pre-push: checking Rust (fmt)..."
|
||||
if ! (cd "$REPO_ROOT/server" && cargo fmt --check 2>&1); then
|
||||
ERRORS=$((ERRORS + 1))
|
||||
@@ -62,6 +56,18 @@ if command -v cargo >/dev/null 2>&1 && [ -d "$REPO_ROOT/server" ]; then
|
||||
echo "pre-push: fmt — OK"
|
||||
fi
|
||||
|
||||
# clippy needs a build — skip if target/ doesn't exist (cold worktree)
|
||||
if [ -d "$REPO_ROOT/server/target" ]; then
|
||||
echo "pre-push: checking Rust (clippy)..."
|
||||
if ! (cd "$REPO_ROOT/server" && cargo clippy -- -D warnings 2>&1); then
|
||||
ERRORS=$((ERRORS + 1))
|
||||
else
|
||||
echo "pre-push: clippy — OK"
|
||||
fi
|
||||
else
|
||||
echo "pre-push: skipping clippy (no target/ — run 'cargo build' once to enable)"
|
||||
fi
|
||||
|
||||
# --- Rust dependency audit (cargo deny) — requires deny.toml config ---
|
||||
if command -v cargo-deny >/dev/null 2>&1 && [ -f "$REPO_ROOT/server/deny.toml" ]; then
|
||||
echo "pre-push: checking Rust (cargo deny)..."
|
||||
|
||||
Reference in New Issue
Block a user