#!/bin/bash echo "Running pre-commit checks..." # 获取项目根目录 PROJECT_DIR=$(git rev-parse --show-toplevel) # 运行编译和代码检查 cd "$PROJECT_DIR" && mvn compile # 检查编译是否成功 if [ $? -ne 0 ]; then echo "Compilation failed! Please fix errors before committing." exit 1 fi # 运行静态代码分析(例如Checkstyle) cd "$PROJECT_DIR" && mvn checkstyle:check if [ $? -ne 0 ]; then echo "Code style check failed! Please fix errors before committing." exit 1 fi echo "All checks passed! Proceeding with commit." exit 0