afegit pre-hooks
This commit is contained in:
@@ -2,7 +2,12 @@
|
||||
"permissions": {
|
||||
"allow": [
|
||||
"Bash(cat:*)",
|
||||
"Bash(cmake --build:*)"
|
||||
"Bash(cmake --build:*)",
|
||||
"Bash(chmod:*)",
|
||||
"Bash(.git/hooks/pre-commit)",
|
||||
"Bash(brew --prefix:*)",
|
||||
"Bash(make setup_hooks:*)",
|
||||
"Bash(tools/hooks/pre-commit)"
|
||||
],
|
||||
"deny": [],
|
||||
"ask": []
|
||||
|
||||
10
CLAUDE.md
10
CLAUDE.md
@@ -107,3 +107,13 @@ tools/linter/run_cppcheck.sh -u # unused functions
|
||||
- OpenGL
|
||||
- C++20 compiler (clang++ on macOS, g++ on Linux/Windows)
|
||||
- CMake 3.10+
|
||||
|
||||
## Git Hooks
|
||||
|
||||
Pre-commit hooks are stored in `tools/hooks/` and must be configured after cloning:
|
||||
|
||||
```bash
|
||||
make setup_hooks
|
||||
```
|
||||
|
||||
This configures git to use `tools/hooks/` as the hooks directory. The pre-commit hook runs `clang-format` to verify code formatting before each commit.
|
||||
|
||||
11
Makefile
11
Makefile
@@ -385,6 +385,14 @@ linux_release:
|
||||
# Elimina la carpeta temporal
|
||||
$(RMDIR) "$(RELEASE_FOLDER)"
|
||||
|
||||
# ==============================================================================
|
||||
# SETUP
|
||||
# ==============================================================================
|
||||
setup_hooks:
|
||||
@echo "Configurando git hooks..."
|
||||
git config core.hooksPath tools/hooks
|
||||
@echo "✓ Git hooks configurados desde tools/hooks/"
|
||||
|
||||
# ==============================================================================
|
||||
# REGLAS ESPECIALES
|
||||
# ==============================================================================
|
||||
@@ -407,9 +415,10 @@ help:
|
||||
@echo " macos_release - Crear release completo para macOS"
|
||||
@echo " pack_tool - Compilar herramienta de empaquetado"
|
||||
@echo " resources.pack - Generar pack de recursos desde data/"
|
||||
@echo " setup_hooks - Configurar git hooks (pre-commit)"
|
||||
@echo " show_version - Mostrar version actual ($(VERSION))"
|
||||
@echo " help - Mostrar esta ayuda"
|
||||
|
||||
FORCE:
|
||||
|
||||
.PHONY: windows windows_debug windows_release macos macos_debug macos_release linux linux_debug linux_release pack_tool resources.pack show_version help
|
||||
.PHONY: windows windows_debug windows_release macos macos_debug macos_release linux linux_debug linux_release pack_tool resources.pack setup_hooks show_version help
|
||||
|
||||
80
tools/hooks/pre-commit
Executable file
80
tools/hooks/pre-commit
Executable file
@@ -0,0 +1,80 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Pre-commit hook: Verifica el formato de archivos C++ con clang-format
|
||||
# Los archivos en source/external/ son ignorados automáticamente
|
||||
#
|
||||
|
||||
# Colores para output
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[0;33m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# Buscar clang-format en ubicaciones comunes
|
||||
CLANG_FORMAT=$(command -v clang-format)
|
||||
if [ -z "$CLANG_FORMAT" ]; then
|
||||
# Buscar en ubicaciones comunes de macOS/Linux
|
||||
for path in \
|
||||
"/opt/homebrew/opt/llvm/bin/clang-format" \
|
||||
"/opt/homebrew/bin/clang-format" \
|
||||
"/usr/local/opt/llvm/bin/clang-format" \
|
||||
"/usr/local/bin/clang-format" \
|
||||
"/usr/bin/clang-format"; do
|
||||
if [ -x "$path" ]; then
|
||||
CLANG_FORMAT="$path"
|
||||
break
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
if [ -z "$CLANG_FORMAT" ]; then
|
||||
echo -e "${YELLOW}Warning: clang-format not found, skipping format check${NC}"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Obtener archivos staged (solo .cpp, .hpp, .h)
|
||||
STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep -E '\.(cpp|hpp|h)$')
|
||||
|
||||
# Si no hay archivos C++ staged, salir
|
||||
if [ -z "$STAGED_FILES" ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Filtrar archivos en external/
|
||||
FILES_TO_CHECK=""
|
||||
for file in $STAGED_FILES; do
|
||||
# Excluir source/external/ y archivos generados
|
||||
if [[ ! "$file" =~ ^source/external/ ]] && [[ ! "$file" =~ project\.h$ ]]; then
|
||||
if [ -f "$file" ]; then
|
||||
FILES_TO_CHECK="$FILES_TO_CHECK $file"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
# Si no quedan archivos después del filtrado, salir
|
||||
if [ -z "$FILES_TO_CHECK" ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Verificar formato
|
||||
FAILED_FILES=""
|
||||
for file in $FILES_TO_CHECK; do
|
||||
if ! $CLANG_FORMAT --dry-run --Werror "$file" 2>/dev/null; then
|
||||
FAILED_FILES="$FAILED_FILES\n - $file"
|
||||
fi
|
||||
done
|
||||
|
||||
# Reportar resultados
|
||||
if [ -n "$FAILED_FILES" ]; then
|
||||
echo -e "${RED}Formatting errors found in:${NC}"
|
||||
echo -e "$FAILED_FILES"
|
||||
echo ""
|
||||
echo -e "Run ${YELLOW}clang-format -i <file>${NC} to fix, or use:"
|
||||
echo -e " ${YELLOW}cmake --build build --target format${NC}"
|
||||
echo ""
|
||||
echo -e "To bypass this check, use: ${YELLOW}git commit --no-verify${NC}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo -e "${GREEN}Format check passed${NC}"
|
||||
exit 0
|
||||
Reference in New Issue
Block a user