diff --git a/doc/debug-hook-guide.md b/doc/debug-hook-guide.md index 2b029d33..956a21e7 100644 --- a/doc/debug-hook-guide.md +++ b/doc/debug-hook-guide.md @@ -18,15 +18,17 @@ A pre-commit hook that automatically detects and prevents debug code from reachi ./scripts/install-debug-hook.sh ``` -This automatically installs, updates, and verifies the hook in your current repository. +This automatically installs, updates, and verifies the hook in your current +repository. **Note**: Hooks are not automatically installed - you must run this +script deliberately to enable debug code checking. ## ๐ง Manual Installation **Copy files manually:** ```bash -cp .git/hooks/pre-commit /path/to/your/repo/.git/hooks/ -cp .git/hooks/debug-checker.config /path/to/your/repo/.git/hooks/ +cp scripts/git-hooks/pre-commit /path/to/your/repo/.git/hooks/ +cp scripts/git-hooks/debug-checker.config /path/to/your/repo/.git/hooks/ chmod +x /path/to/your/repo/.git/hooks/pre-commit ``` @@ -36,12 +38,27 @@ chmod +x /path/to/your/repo/.git/hooks/pre-commit - **`debug-checker.config`** - Configuration file - **`README.md`** - Documentation and troubleshooting +**Note**: Hooks are stored in `scripts/git-hooks/` and must be deliberately +installed by each developer. They are not automatically active. + ## ๐ฏ How It Works -1. **Branch Detection**: Only runs on protected branches -2. **File Filtering**: Automatically skips tests, scripts, and documentation -3. **Pattern Matching**: Detects debug code using regex patterns -4. **Commit Prevention**: Blocks commits containing debug code +1. **Deliberate Installation**: Hooks must be explicitly installed by each + developer +2. **Branch Detection**: Only runs on protected branches +3. **File Filtering**: Automatically skips tests, scripts, and documentation +4. **Pattern Matching**: Detects debug code using regex patterns +5. **Commit Prevention**: Blocks commits containing debug code + +## ๐ Installation Philosophy + +**Why deliberate installation?** + +- **Developer choice**: Each developer decides whether to use the hook +- **No forced behavior**: Hooks don't interfere with existing workflows +- **Local control**: Hooks are installed locally, not globally +- **Easy removal**: Can be uninstalled at any time +- **Team flexibility**: Some developers may prefer different tools ## ๐ฟ Branch Behavior @@ -145,8 +162,8 @@ A test script is available at `scripts/test-debug-hook.sh` to verify the hook wo ## ๐ Additional Resources -- **Hook documentation**: `.git/hooks/README.md` -- **Configuration**: `.git/hooks/debug-checker.config` +- **Hook documentation**: `scripts/git-hooks/README.md` +- **Configuration**: `scripts/git-hooks/debug-checker.config` - **Test script**: `scripts/test-debug-hook.sh` - **Installation script**: `scripts/install-debug-hook.sh` diff --git a/scripts/git-hooks/README.md b/scripts/git-hooks/README.md new file mode 100644 index 00000000..d335b3b2 --- /dev/null +++ b/scripts/git-hooks/README.md @@ -0,0 +1,103 @@ +# 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 +1. **Branch Detection**: Only runs on protected branches (configurable) +2. **File Filtering**: Automatically skips test files, scripts, and documentation +3. **Pattern Matching**: Detects common debug patterns using regex +4. **Commit Prevention**: Blocks commits containing debug code + +### Protected Branches (Default) +- `master` +- `main` +- `production` +- `release` +- `stable` + +### 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**: `" 1 + +echo -e "\n${BLUE}Test Case 7: Debug attribute (should fail)${NC}" +run_test "Debug attribute" "