This repository uses pre-commit to ensure code quality and enforce commit message conventions.
After cloning the repository, run ONE command:
pip install pre-commit && pre-commit install --hook-type commit-msg --hook-type pre-commit --hook-type post-checkoutThat's it! The hooks will now run automatically on every commit and branch checkout.
# Run all checks manually
pre-commit run --all-files
# Test branch name validation
python3 .githooks/check_branch_name.pyAll branch names must follow this format:
<type>-<description> or <type>/<description>
✅ Valid branch names:
feat-buffer-pooling
fix-windows-dll-exports
docs-update-readme
refactor/simplify-tensor-allocation
ci-add-coverage-reporting
test-buffer-manager
❌ Invalid branch names:
buffer_pooling (no type prefix)
Feat-something (capital letter)
feature-test (wrong type, use 'feat')
my-branch (no type prefix)
These branches don't require the naming convention:
main,master,developrelease/*(e.g.,release/v1.0.0)hotfix/*(e.g.,hotfix/critical-bug)
All commit messages must follow the Conventional Commits format:
<type>(<scope>): <subject>
[optional body]
[optional footer]
feat: New featurefix: Bug fixdocs: Documentation only changesstyle: Code style changes (formatting, no logic change)refactor: Code refactoring (neither fixes a bug nor adds a feature)perf: Performance improvementstest: Adding or updating testsbuild: Build system or dependency changesci: CI/CD configuration changeschore: Other changes (tooling, maintenance)revert: Revert a previous commit
✅ Good commit messages:
feat(memory): add buffer pooling for better performance
fix(build): correct Windows DLL export declarations
docs(readme): update build instructions for macOS
refactor(tensor): simplify memory allocation logic
ci(workflows): add coverage reporting to ubuntu workflow
style: apply clang-format to all source files
test(buffer): add unit tests for buffer manager
❌ Bad commit messages:
update code
Fixed bug
Add feature
WIP
asdf
The scope should indicate what part of the codebase is affected:
memory- Memory management (buffers, allocators)tensor- Tensor operationsmodel- Model implementationbuild- Build system (CMake, Conan)ci- CI/CD workflowstest- Testing infrastructuredocs- Documentation
-
File checks:
- Remove trailing whitespace
- Ensure files end with newline
- Check for large files (>1MB)
- Detect merge conflicts
- Check YAML/JSON syntax
- Detect private keys
-
Code formatting:
- C/C++ files:
clang-format - CMake files:
cmake-format - YAML/JSON:
prettier - Shell scripts:
shellcheck - Python scripts:
black
- C/C++ files:
-
Commit message:
- Must follow conventional commit format
- Type must be from allowed list
- Subject should be concise
If you absolutely need to skip the hooks (e.g., for a WIP commit):
# Skip pre-commit hooks (file checks)
git commit --no-verify
# Skip commit-msg hook
git commit --no-verify# Update to latest versions
pre-commit autoupdate
# Reinstall hooks after config changes
pre-commit install --hook-type commit-msg --hook-type pre-commitPre-commit checks also run in CI (GitHub Actions). If your local hooks pass, CI should pass too.
pip install pre-commit# Run to see detailed error
pre-commit run --all-files
# Reinstall hooks
pre-commit uninstall
pre-commit install --hook-type commit-msg --hook-type pre-commit# Let pre-commit auto-fix formatting
pre-commit run --all-files
# Stage the auto-fixed files
git add .
# Commit again
git commit -m "style: apply automated formatting"