-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpre-commit.hook
More file actions
44 lines (37 loc) · 1.24 KB
/
Copy pathpre-commit.hook
File metadata and controls
44 lines (37 loc) · 1.24 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
#!/bin/bash
#
# Pre-commit hook to ensure code is formatted
# - C/C++ files: checked with clang-format (required)
# - JS/CSS/HTML files: checked with prettier (optional)
#
# Install: cp pre-commit.hook .git/hooks/pre-commit && chmod +x .git/hooks/pre-commit
#
# Change to repository root
cd "$(git rev-parse --show-toplevel)" || exit 1
# Color output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Check if format_code.sh exists
if [ ! -f "./format_code.sh" ]; then
echo -e "${RED}ERROR: format_code.sh not found!${NC}"
exit 1
fi
echo -e "${YELLOW}Checking formatting of changed files...${NC}"
# Delegate entirely to format_code.sh --changed --check
# This checks both C/C++ (clang-format) and JS/CSS/HTML (prettier, if available)
./format_code.sh --changed --check
FORMAT_RESULT=$?
echo ""
if [ $FORMAT_RESULT -ne 0 ]; then
echo -e "${RED}Formatting check failed!${NC}"
echo -e "${YELLOW}Run './format_code.sh --changed' to format changed files.${NC}"
echo -e "${YELLOW}Then stage the changes and commit again.${NC}"
echo ""
echo -e "${YELLOW}Or to bypass this check (not recommended):${NC}"
echo -e " git commit --no-verify"
exit 1
fi
echo -e "${GREEN}All formatting checks passed!${NC}"
exit 0