Skip to content

Commit ac67e16

Browse files
docs: document disabling git hooks per environment (#2230)
Documents how to disable the installed Vite+ commit hooks per environment --------- Signed-off-by: Alexander Lichter <github@lichter.io>
1 parent a6f41ec commit ac67e16

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

docs/guide/commit-hooks.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,35 @@ export default defineConfig({
5959

6060
This is the default Vite+ approach and should replace separate `lint-staged` configuration in most projects. Because `vp staged` reads from `vite.config.ts`, your staged-file checks stay in the same place as your lint, format, test, build, and task-runner config.
6161

62+
## Disabling Hooks in Specific Environments
63+
64+
The installed hooks check the environment on every run, so you can disable them per machine or per process without uninstalling anything. This is useful when commits happen outside development, for example through a flat file CMS or other processes.
65+
66+
### Environment variable
67+
68+
Set `VITE_GIT_HOOKS=0` in the environment of the process that runs `git commit`, and every Vite+ hook exits immediately without running:
69+
70+
```bash
71+
VITE_GIT_HOOKS=0 git commit -m "content update"
72+
```
73+
74+
`HUSKY=0` is honored the same way for ecosystem tooling compatibility. Setting `VITE_GIT_HOOKS=0` in an environment also keeps `vp config` from reinstalling hooks there when a lifecycle script such as `prepare` runs.
75+
76+
### Init script
77+
78+
Before checking the environment variable, each hook sources an init script if one exists:
79+
80+
1. `$XDG_CONFIG_HOME/vite-plus/hooks-init.sh` (defaults to `~/.config/vite-plus/hooks-init.sh`)
81+
2. `$XDG_CONFIG_HOME/husky/init.sh` as a fallback
82+
83+
To disable hooks for a whole machine, create the init script and export the variable there:
84+
85+
```sh [~/.config/vite-plus/hooks-init.sh]
86+
export VITE_GIT_HOOKS=0
87+
```
88+
89+
Because the hook itself reads this file, it works even when the committing process does not inherit your shell environment, for example if a daemon or web server is making commits.
90+
6291
## Removing commit hooks
6392

6493
To fully remove Vite+ commit hooks, undo each thing `vp config` set up:

0 commit comments

Comments
 (0)