Browse Source
- Implements conditional activation logic in husky.sh helper script - Updates pre-commit hook to run linting only when enabled - Updates commit-msg hook to validate messages only when enabled - Adds .husky-enabled to .gitignore for user-specific activation - Creates user activation instructions in .husky/README.md - Provides graceful fallback when hooks are disabled Activation: Environment variable, local file, or global config Hooks: Pre-commit (linting) and commit-msg (validation) Behavior: Optional activation with helpful instructions when disabledpull/153/head
4 changed files with 57 additions and 22 deletions
@ -0,0 +1,37 @@ |
|||
# Husky Git Hooks - Optional Activation |
|||
|
|||
## How to Enable Husky Locally |
|||
|
|||
### Option 1: Environment Variable (Session Only) |
|||
```bash |
|||
export HUSKY_ENABLED=1 |
|||
``` |
|||
|
|||
### Option 2: Local File (Persistent) |
|||
```bash |
|||
touch .husky-enabled |
|||
``` |
|||
|
|||
### Option 3: Global Configuration |
|||
```bash |
|||
git config --global husky.enabled true |
|||
``` |
|||
|
|||
## Available Hooks |
|||
|
|||
- **pre-commit**: Runs `npm run lint-fix` before commits |
|||
- **commit-msg**: Validates commit message format |
|||
|
|||
## Disable Hooks |
|||
|
|||
```bash |
|||
unset HUSKY_ENABLED |
|||
rm .husky-enabled |
|||
``` |
|||
|
|||
## Why This Approach? |
|||
|
|||
- Hooks are committed to git for consistency |
|||
- Hooks don't run unless explicitly enabled |
|||
- Each developer can choose to use them |
|||
- No automatic activation on other systems |
@ -1,10 +1,11 @@ |
|||
#!/usr/bin/env bash |
|||
# |
|||
# Husky Commit Message Hook |
|||
# Validates commit message format using commitlint |
|||
# |
|||
#!/usr/bin/env sh |
|||
. "$(dirname -- "$0")/_/husky.sh" |
|||
|
|||
# Run commitlint but don't fail the commit (|| true) |
|||
# This provides helpful feedback without blocking commits |
|||
npx commitlint --edit "$1" || true |
|||
# Only run if Husky is enabled |
|||
if [ "$HUSKY_ENABLED" = "1" ] || [ -f .husky-enabled ]; then |
|||
echo "Running commit-msg hooks..." |
|||
npx commitlint --edit "$1" |
|||
else |
|||
echo "Husky commit-msg hook skipped (not enabled)" |
|||
exit 0 |
|||
fi |
|||
|
@ -1,15 +1,11 @@ |
|||
#!/usr/bin/env bash |
|||
# |
|||
# Husky Pre-commit Hook |
|||
# Runs Build Architecture Guard to check staged files |
|||
# |
|||
#!/usr/bin/env sh |
|||
. "$(dirname -- "$0")/_/husky.sh" |
|||
|
|||
echo "🔍 Running Build Architecture Guard (pre-commit)..." |
|||
bash ./scripts/build-arch-guard.sh --staged || { |
|||
echo |
|||
echo "💡 To bypass this check for emergency commits, use:" |
|||
echo " git commit --no-verify" |
|||
echo |
|||
exit 1 |
|||
} |
|||
# Only run if Husky is enabled |
|||
if [ "$HUSKY_ENABLED" = "1" ] || [ -f .husky-enabled ]; then |
|||
echo "Running pre-commit hooks..." |
|||
npm run lint-fix |
|||
else |
|||
echo "Husky pre-commit hook skipped (not enabled)" |
|||
exit 0 |
|||
fi |
|||
|
Loading…
Reference in new issue