You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
2 months ago | |
|---|---|---|
| .. | ||
| README.md | 2 months ago | |
| debug-checker.config | 2 months ago | |
| pre-commit | 2 months ago | |
README.md
TimeSafari Git Hooks
This directory contains custom Git hooks for the TimeSafari project.
Debug Code Checker Hook
Overview
The pre-commit hook automatically checks for debug code when committing to protected branches (master, main, production, release). This prevents debug statements from accidentally reaching production code.
How It Works
- Branch Detection: Only runs on protected branches (configurable)
- File Filtering: Automatically skips test files, scripts, and documentation
- Pattern Matching: Detects common debug patterns using regex
- Commit Prevention: Blocks commits containing debug code
Protected Branches (Default)
mastermainproductionreleasestable
Debug Patterns Detected
- Console statements:
console.log,console.debug,console.error - Template debug:
Debug:,debug:in Vue templates - Debug constants:
DEBUG_,debug_variables - HTML debug:
<!-- debugcomments - Debug attributes:
debug="true"attributes - Vue debug:
v-if="debug",v-show="debug" - Debug TODOs:
TODO debug,FIXME debug
Files Automatically Skipped
- Test files:
*.test.js,*.spec.ts,*.test.vue - Scripts:
scripts/directory - Test directories:
test-*directories - Documentation:
docs/,*.md,*.txt - Config files:
*.json,*.yml,*.yaml - IDE files:
.cursor/directory
Configuration
Edit .git/hooks/debug-checker.config to customize:
- Protected branches
- Debug patterns
- Skip patterns
- Logging level
Testing the Hook
Run the test script to verify the hook works:
./scripts/test-debug-hook.sh
Manual Testing
- Make changes to a file with debug code
- Stage the file:
git add <filename> - Try to commit:
git commit -m 'test' - Hook should prevent commit if debug code is found
Bypassing the Hook (Emergency)
If you absolutely need to commit debug code to a protected branch:
git commit --no-verify -m "emergency: debug code needed"
⚠️ Warning: This bypasses all pre-commit hooks. Use sparingly and only in emergencies.
Troubleshooting
Hook not running
- Ensure the hook is executable:
chmod +x .git/hooks/pre-commit - Check if you're on a protected branch
- Verify the hook file exists and has correct permissions
False positives
- Add legitimate debug patterns to skip patterns in config
- Use proper logging levels (
logger.info,logger.debug) instead of console - Move debug code to feature branches first
Hook too strict
- Modify debug patterns in config file
- Add more file types to skip patterns
- Adjust protected branch list
Best Practices
- Use feature branches for development with debug code
- Use proper logging instead of console statements
- Test thoroughly before merging to protected branches
- Review commits to ensure no debug code slips through
- Keep config updated as project needs change
Integration with CI/CD
This hook works locally. For CI/CD pipelines, consider:
- Running the same checks in your build process
- Adding ESLint rules for console statements
- Using TypeScript strict mode
- Adding debug code detection to PR checks
Support
If you encounter issues:
- Check the hook output for specific error messages
- Verify your branch is in the protected list
- Review the configuration file
- Test with the provided test script
- Check file permissions and git setup