# pre-commit-hooks **Repository Path**: xu_415/pre-commit-hooks ## Basic Information - **Project Name**: pre-commit-hooks - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 1 - **Created**: 2026-06-04 - **Last Updated**: 2026-06-05 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # litebmc pre-commit-hooks litebmc 所有代码仓的统一 pre-commit hooks 仓库。 ## 快速开始(新用户 3 步完成) ```bash # 1. 克隆本仓库 git clone https://gitee.com/litebmc/pre-commit-hooks.git # 2. 进入你的项目,一键安装 cd /path/to/your/repo bash /path/to/pre-commit-hooks/install.sh # 3. 完成!后续每次 git commit 自动触发检查 ``` ## install.sh 做了什么 | 步骤 | 内容 | |------|------| | 环境检查 | 确认 python3 / pip3 / git 可用 | | pre-commit | 安装或升级 pre-commit 框架 (`pip install pre-commit`) | | Python 工具 | `pyyaml` `black` `isort` `flake8` `flake8-bugbear` `flake8-comprehensions` | | clang-format | 自动检测 apt/yum/dnf/brew/pip 安装 | | gitleaks | 调用 `hooks/install-gitleaks.sh` 自动下载二进制 | | Hook 安装 | 生成 `.pre-commit-config.yaml` 并 `pre-commit install` | ## Hook 列表 ### 通用文件检查 | Hook | 说明 | 依赖 | |------|------|------| | `check-merge-conflict` | 禁止提交含合并冲突标记的文件 | 无(bash) | | `check-trailing-whitespace` | 检查行尾空白符 | 无(bash) | | `check-end-of-file` | 文件以换行符结尾 | 无(bash) | | `check-mixed-line-ending` | 统一 LF 换行 | 无(bash) | | `check-large-files` | 禁止提交 >500KB 文件 | 无(bash) | | `check-no-commit-to-branch` | 禁止直推 master/main | 无(bash) | | `check-debug-statements` | Python 残留调试语句 | 无(bash) | | `check-yaml` | YAML 语法校验 | pyyaml | | `check-json` | JSON 语法校验 | python3 | ### 代码格式化 | Hook | 说明 | 依赖 | |------|------|------| | `clang-format` | C/C++ 代码格式化 | clang-format | | `black` | Python 代码格式化 | black | | `isort` | Python import 排序 | isort | | `flake8` | Python 代码风格 | flake8 + bugbear + comprehensions | ### 提交规范与安全 | Hook | 说明 | 依赖 | |------|------|------| | `check-conventional-commit` | Conventional Commits 校验 | python3 | | `gitleaks` | 敏感信息泄露检查 | gitleaks(未安装时自动跳过) | ## 各仓库配置示例 ### C/C++ 项目(lb_base) ```yaml # .pre-commit-config.yaml repos: - repo: https://gitee.com/litebmc/pre-commit-hooks rev: v1.0.0 hooks: - id: check-merge-conflict - id: check-trailing-whitespace - id: check-end-of-file - id: check-mixed-line-ending - id: check-large-files - id: check-yaml - id: check-json - id: check-no-commit-to-branch - id: clang-format - id: black - id: check-conventional-commit - id: gitleaks ``` ### Python 项目(lbkit) ```yaml # .pre-commit-config.yaml repos: - repo: https://gitee.com/litebmc/pre-commit-hooks rev: v1.0.0 hooks: - id: check-merge-conflict - id: check-debug-statements - id: check-trailing-whitespace - id: check-end-of-file - id: check-mixed-line-ending - id: check-large-files - id: check-yaml - id: check-json - id: check-no-commit-to-branch - id: black - id: isort - id: flake8 - id: check-conventional-commit - id: gitleaks ``` ## 常见操作 ```bash # 手动检查所有文件 pre-commit run --all-files # 只运行指定 hook pre-commit run clang-format --all-files # 跳过某个 hook 提交 SKIP=gitleaks git commit -m "fix: 紧急修复" # 跳过所有 hooks git commit --no-verify -m "wip" # 更新 hooks 及配套工具 bash install.sh # 卸载 hooks pre-commit uninstall pre-commit uninstall -t commit-msg ```