-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpre-commit.sh
More file actions
executable file
·39 lines (29 loc) · 853 Bytes
/
Copy pathpre-commit.sh
File metadata and controls
executable file
·39 lines (29 loc) · 853 Bytes
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
#!/bin/bash
# Pre-commit hook: format staged Elixir files.
# Runs mix format and re-stages any files it reformats.
set -e
# Colors
CYAN='\033[0;36m'
GREEN='\033[0;32m'
NC='\033[0m'
echo ""
echo -e "${CYAN}Pre-commit: mix format${NC}"
echo ""
# Get project root using git
PROJECT_ROOT="$(git rev-parse --show-toplevel)"
# Change to project root (needed for mix format)
cd "$PROJECT_ROOT"
mix format
# Re-stage any already-staged Elixir files that were reformatted by mix format
FORMATTED_FILES=$(git diff --name-only | grep -E '\.(ex|exs)$' || true)
if [ -n "$FORMATTED_FILES" ]; then
while IFS= read -r file; do
if git diff --cached --name-only | grep -qx "$file"; then
git add "$file"
echo " Reformatted and re-staged: $file"
fi
done <<< "$FORMATTED_FILES"
fi
echo -e "${GREEN}✓ Code formatted${NC}"
echo ""
exit 0