Repository navigation
Expand file tree
/
Copy pathpre-push
More file actions
executable file
·79 lines (66 loc) · 2.45 KB
/
Copy pathpre-push
File metadata and controls
executable file
·79 lines (66 loc) · 2.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/bin/sh
# Pre-push hook for Cortex CLI (OPTIMIZED)
# Only checks crates with changes since origin
set -e
echo "=== Pre-push Hook (Optimized) ==="
# Get the remote branch we're pushing to
REMOTE=${1:-origin}
REMOTE_REF=$(git rev-parse --abbrev-ref @{upstream} 2>/dev/null || echo "$REMOTE/master")
# Get changed Rust files since remote
CHANGED_RS_FILES=$(git diff --name-only "$REMOTE_REF"...HEAD | grep '\.rs$' || true)
if [ -z "$CHANGED_RS_FILES" ]; then
echo "No Rust files changed since $REMOTE_REF, skipping checks."
exit 0
fi
echo "Checking changes since $REMOTE_REF..."
# Find changed crates
CHANGED_CRATES=$(echo "$CHANGED_RS_FILES" | sed 's|/src/.*||' | sort -u | grep -v '^\.' || true)
# Format check on changed files only
echo "Running rustfmt --check on changed files..."
echo "$CHANGED_RS_FILES" | xargs rustfmt --edition 2024 --check 2>/dev/null || {
echo "ERROR: Format check failed. Run 'cargo fmt' to fix."
exit 1
}
# Clippy only on changed crates
if [ -n "$CHANGED_CRATES" ]; then
echo "Running clippy on changed crates..."
CLIPPY_ARGS=""
for crate in $CHANGED_CRATES; do
if [ -f "$crate/Cargo.toml" ]; then
crate_name=$(basename "$crate")
# Skip cortex-gui (needs frontend built)
if [ "$crate_name" != "cortex-gui" ] && [ "$crate_name" != "src-tauri" ]; then
CLIPPY_ARGS="$CLIPPY_ARGS -p $crate_name"
fi
fi
done
if [ -n "$CLIPPY_ARGS" ]; then
cargo clippy $CLIPPY_ARGS --lib 2>&1 | head -50 || true
fi
fi
# Check only changed crates
echo "Running cargo check on changed crates..."
for crate in $CHANGED_CRATES; do
if [ -f "$crate/Cargo.toml" ]; then
crate_name=$(basename "$crate")
if [ "$crate_name" != "cortex-gui" ] && [ "$crate_name" != "src-tauri" ]; then
cargo check -p "$crate_name" 2>/dev/null || {
echo "ERROR: cargo check failed for $crate_name"
exit 1
}
fi
fi
done
# Run tests only on changed crates
echo "Running tests on changed crates..."
for crate in $CHANGED_CRATES; do
if [ -f "$crate/Cargo.toml" ]; then
crate_name=$(basename "$crate")
if [ "$crate_name" != "cortex-gui" ] && [ "$crate_name" != "src-tauri" ]; then
cargo test -p "$crate_name" --lib 2>/dev/null || {
echo "WARNING: Tests failed for $crate_name (continuing)"
}
fi
fi
done
echo "=== Pre-push passed! ==="