-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathpre-commit
More file actions
executable file
·48 lines (39 loc) · 1.16 KB
/
pre-commit
File metadata and controls
executable file
·48 lines (39 loc) · 1.16 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
#!/bin/sh
# Automatically detect the current hook name
hook_name=$(basename "$0")
globalHooks="$(git config --global core.hooksPath)"
if [ -f "${globalHooks}/${hook_name}" ]; then
"${globalHooks}/${hook_name}" $@
if [ $? -ne 0 ]; then
echo "❌ Global ${hook_name} hook failed"
exit 1
fi
fi
echo "${hook_name}"
# Get list of staged Python files
STAGED_PY_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep '\.py$')
if [ -z "$STAGED_PY_FILES" ]; then
echo "✅ No Python files staged, skipping format"
exit 0
fi
echo "📝 Running format check on entire codebase..."
# Run make fmt on entire codebase
make fmt
if [ $? -ne 0 ]; then
echo "❌ Format check failed"
exit 1
fi
# Check if formatter made changes to any staged files and re-stage them
echo "📝 Re-staging formatted files..."
for file in $STAGED_PY_FILES; do
if [ -f "$file" ]; then
# Check if the file was modified by formatter
git diff --exit-code "$file" > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo " 📝 Re-staging: $file"
git add "$file"
fi
fi
done
echo "✅ Format check complete"
exit 0