feat(git-hooks): add pre-commit branch validation#695
Conversation
Adds branch validation to prevent wrong-branch commits: - Block: commits directly to main/master (EXIT_STATUS=1) - Warn: unusual branch names not matching conventional patterns - Allow: feat/*, fix/*, docs/*, chore/*, refactor/*, test/*, ci/*, build/*, perf/* - Allow: detached HEAD state (for rebasing) This addresses the root cause identified in PR #669 retrospective: trust-based compliance led to cross-PR contamination affecting 4 PRs. Bypass: git commit --no-verify (use sparingly) Closes #681 Closes #678 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
PR Validation ReportTip ✅ Status: PASS Description Validation
QA Validation
Powered by PR Validation workflow |
Added Phase 2 autonomous development completing 6 additional PRs: - PR #694: Investigation-only validation (issues #655-658) - PR #695: Branch validation hook (issues #678, #681) - PR #696: Branch verification protocol (issue #684) Session created 7 PRs total, closing 10+ P0 issues. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Code Review
This pull request adds a helpful pre-commit hook to validate branch names, preventing direct commits to main/master and encouraging conventional naming. The implementation is robust, correctly handling detached HEAD states and providing clear user feedback. I've identified one high-severity style guide violation regarding variable naming conventions in the bash script and provided a suggestion to correct it.
Address code review feedback: rename CURRENT_BRANCH and BRANCH_VALID to current_branch and branch_valid per repository style guide. Local script variables use snake_case; UPPER_CASE reserved for environment/exported variables. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
✨ Finishing touches🧪 Generate unit tests (beta)
Comment |
|
Caution Review failedFailed to post review comments Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. 📝 WalkthroughWalkthroughAdds branch validation to the pre-commit hook that blocks commits to main/master, validates branch names against conventional patterns (feat/, fix/, docs/*, etc.), warns on non-matching branches, and allows --no-verify bypass. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Suggested labels
Pre-merge checks and finishing touches✅ Passed checks (5 passed)
✨ Finishing touches🧪 Generate unit tests (beta)
Comment |
Summary
Adds branch validation to the pre-commit hook to prevent wrong-branch commits. This addresses the root cause identified in the PR #669 retrospective where trust-based compliance led to cross-PR contamination.
Specification References
Changes
.githooks/pre-commit:main/master(hard failure)feat/*,fix/*,docs/*,chore/*,refactor/*,test/*,ci/*,build/*,perf/*,tech-debt*Type of Change
Testing
Manual Testing:
mainbranch--no-verifybypass worksAgent Review
Security Review
Security considerations:
set -efor fail-fast behavior--no-verifyis documentedOther Agent Reviews
Checklist
Related Issues