Skip to content
This repository was archived by the owner on Apr 1, 2026. It is now read-only.

Commit 6e70930

Browse files
author
FreeSynergy
committed
chore: restore strict pre-commit hook (staged packages only, hard fail)
1 parent 2feb173 commit 6e70930

1 file changed

Lines changed: 8 additions & 27 deletions

File tree

.githooks/pre-commit

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,14 @@ require_tool clippy clippy
2626
STAGED=$(git diff --cached --name-only --diff-filter=ACMR | grep '\.rs$' || true)
2727

2828
if [ -z "$STAGED" ]; then
29+
# No Rust files staged — only check toml/config changes with fmt
2930
echo " No staged .rs files — skipping clippy and tests."
3031
echo -e "${GREEN}[FS] All checks passed.${NC}"
3132
exit 0
3233
fi
3334

34-
# ── Collect workspace members ─────────────────────────────────────────────────
35-
# Use cargo metadata to get only workspace members (excludes vendor/external packages)
36-
mapfile -t WORKSPACE_MEMBERS < <(cargo metadata --no-deps --format-version 1 2>/dev/null \
37-
| python3 -c "import json,sys; data=json.load(sys.stdin); [print(p['name']) for p in data.get('packages',[])]" \
38-
2>/dev/null || true)
39-
4035
# ── Detect affected packages ──────────────────────────────────────────────────
36+
# For each staged .rs file, walk up to find its Cargo.toml and extract the package name.
4137
PKGS=()
4238
for f in $STAGED; do
4339
dir=$(dirname "$f")
@@ -46,17 +42,7 @@ for f in $STAGED; do
4642
if [ -f "$toml" ]; then
4743
name=$(grep -m1 '^name' "$toml" | sed 's/name *= *"\(.*\)"/\1/')
4844
if [ -n "$name" ]; then
49-
# Only include workspace members (skip vendor/external packages)
50-
if [ ${#WORKSPACE_MEMBERS[@]} -eq 0 ]; then
51-
PKGS+=("$name")
52-
else
53-
for wm in "${WORKSPACE_MEMBERS[@]}"; do
54-
if [ "$wm" = "$name" ]; then
55-
PKGS+=("$name")
56-
break
57-
fi
58-
done
59-
fi
45+
PKGS+=("$name")
6046
fi
6147
break
6248
fi
@@ -68,7 +54,7 @@ done
6854
mapfile -t PKGS < <(printf '%s\n' "${PKGS[@]}" | sort -u)
6955

7056
if [ ${#PKGS[@]} -eq 0 ]; then
71-
echo " No staged files map to workspace packages — skipping."
57+
echo " Could not map staged files to packages — skipping."
7258
echo -e "${GREEN}[FS] All checks passed.${NC}"
7359
exit 0
7460
fi
@@ -85,23 +71,18 @@ echo " [1/3] Format check..."
8571
cargo fmt "${PKG_FLAGS[@]}" -- --check || fail "Format issues found. Run: cargo fmt ${PKG_FLAGS[*]}"
8672

8773
# ── Clippy ────────────────────────────────────────────────────────────────────
88-
# Note: cross-repo path dependencies may have pre-existing compilation errors.
89-
# Clippy failures due to dependency compilation errors are reported as warnings.
9074
echo " [2/3] Clippy..."
91-
if ! RUSTFLAGS="-D warnings" cargo clippy "${PKG_FLAGS[@]}" --all-targets -- \
75+
RUSTFLAGS="-D warnings" cargo clippy "${PKG_FLAGS[@]}" --all-targets -- \
9276
-D clippy::large_enum_variant \
9377
-D clippy::cognitive_complexity \
9478
-D clippy::too_many_arguments \
9579
-D clippy::too_many_lines \
9680
-D clippy::wildcard_imports \
97-
-D clippy::unused_self 2>&1; then
98-
echo -e "${YELLOW} WARNING: Clippy check failed (may be due to cross-repo dependency state). Proceeding.${NC}"
99-
fi
81+
-D clippy::unused_self \
82+
|| fail "Clippy found issues. Fix them before committing."
10083

10184
# ── Tests ─────────────────────────────────────────────────────────────────────
10285
echo " [3/3] Tests..."
103-
if ! cargo test "${PKG_FLAGS[@]}" 2>&1; then
104-
echo -e "${YELLOW} WARNING: Tests failed (may be due to cross-repo dependency state). Proceeding.${NC}"
105-
fi
86+
cargo test "${PKG_FLAGS[@]}" || fail "Tests failed."
10687

10788
echo -e "${GREEN}[FS] All checks passed.${NC}"

0 commit comments

Comments
 (0)