Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ Options:
-h, --help Show this help message

Environment:
VITE_GIT_HOOKS=0 Skip hook installation
VP_GIT_HOOKS=0 Skip hook installation
VITE_GIT_HOOKS=0 Deprecated alias of VP_GIT_HOOKS=0

Documentation: https://viteplus.dev/guide/commit-hooks
```
Expand All @@ -37,7 +38,8 @@ Options:
-h, --help Show this help message

Environment:
VITE_GIT_HOOKS=0 Skip hook installation
VP_GIT_HOOKS=0 Skip hook installation
VITE_GIT_HOOKS=0 Deprecated alias of VP_GIT_HOOKS=0

Documentation: https://viteplus.dev/guide/commit-hooks
```
Expand All @@ -58,7 +60,8 @@ Options:
-h, --help Show this help message

Environment:
VITE_GIT_HOOKS=0 Skip hook installation
VP_GIT_HOOKS=0 Skip hook installation
VITE_GIT_HOOKS=0 Deprecated alias of VP_GIT_HOOKS=0

Documentation: https://viteplus.dev/guide/commit-hooks
```
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ hook dispatcher script content

```
#!/usr/bin/env sh
{ [ "$HUSKY" = "2" ] || [ "$VITE_GIT_HOOKS" = "2" ]; } && set -x
{ [ "$HUSKY" = "2" ] || [ "$VP_GIT_HOOKS" = "2" ] || [ "$VITE_GIT_HOOKS" = "2" ]; } && set -x
n=$(basename "$0")
s=$(dirname "$(dirname "$0")")/$n

Expand All @@ -105,7 +105,7 @@ i="${XDG_CONFIG_HOME:-$HOME/.config}/vite-plus/hooks-init.sh"
[ ! -f "$i" ] && i="${XDG_CONFIG_HOME:-$HOME/.config}/husky/init.sh"
[ -f "$i" ] && . "$i"

{ [ "${HUSKY-}" = "0" ] || [ "${VITE_GIT_HOOKS-}" = "0" ]; } && exit 0
{ [ "${HUSKY-}" = "0" ] || [ "${VP_GIT_HOOKS-}" = "0" ] || [ "${VITE_GIT_HOOKS-}" = "0" ]; } && exit 0

d="$(dirname "$(dirname "$(dirname "$0")")")"
__vp_shell=/bin/sh
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ hook dispatcher should resolve repo root correctly for nested dirs

```
#!/usr/bin/env sh
{ [ "$HUSKY" = "2" ] || [ "$VITE_GIT_HOOKS" = "2" ]; } && set -x
{ [ "$HUSKY" = "2" ] || [ "$VP_GIT_HOOKS" = "2" ] || [ "$VITE_GIT_HOOKS" = "2" ]; } && set -x
n=$(basename "$0")
s=$(dirname "$(dirname "$0")")/$n

Expand All @@ -81,7 +81,7 @@ i="${XDG_CONFIG_HOME:-$HOME/.config}/vite-plus/hooks-init.sh"
[ ! -f "$i" ] && i="${XDG_CONFIG_HOME:-$HOME/.config}/husky/init.sh"
[ -f "$i" ] && . "$i"

{ [ "${HUSKY-}" = "0" ] || [ "${VITE_GIT_HOOKS-}" = "0" ]; } && exit 0
{ [ "${HUSKY-}" = "0" ] || [ "${VP_GIT_HOOKS-}" = "0" ] || [ "${VITE_GIT_HOOKS-}" = "0" ]; } && exit 0

d="$(dirname "$(dirname "$(dirname "$(dirname "$0")")")")"
__vp_shell=/bin/sh
Expand Down
4 changes: 2 additions & 2 deletions docs/guide/commit-hooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ Use `--no-hooks` when you want `vp config` to leave existing Git hook setup unch
`--no-agent` when you want it to skip updates to existing coding agent instruction files. You
can pass both flags when you want `vp config` to skip both setup steps.

You can also set `VITE_GIT_HOOKS=0` to disable hook installation from lifecycle scripts such as
`prepare` or `postinstall`.
You can also set `VP_GIT_HOOKS=0` to disable hook installation from lifecycle scripts such as
`prepare` or `postinstall`. `VITE_GIT_HOOKS=0` is still accepted as a deprecated alias.

### `vp staged`

Expand Down
2 changes: 1 addition & 1 deletion docs/guide/troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ If `vp staged` fails or your pre-commit hook does not run:

- make sure `vite.config.ts` contains a `staged` block
- run `vp config` to install hooks
- check whether hook installation was skipped intentionally through `VITE_GIT_HOOKS=0`
- check whether hook installation was skipped intentionally through `VP_GIT_HOOKS=0` (or the deprecated `VITE_GIT_HOOKS=0` alias)

A minimal staged config looks like this:

Expand Down
40 changes: 40 additions & 0 deletions packages/cli/src/config/__tests__/hooks.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,46 @@ describe('install', () => {
}
},
);

it('skips install when VP_GIT_HOOKS=0', () => {
const prev = process.env.VP_GIT_HOOKS;
process.env.VP_GIT_HOOKS = '0';
try {
const result = install('.vite-hooks');
expect(result).toEqual({ message: 'skip install (git hooks disabled)', isError: false });
} finally {
if (prev === undefined) {
delete process.env.VP_GIT_HOOKS;
} else {
process.env.VP_GIT_HOOKS = prev;
}
}
});

it('skips install when deprecated VITE_GIT_HOOKS=0', () => {
const prev = process.env.VITE_GIT_HOOKS;
process.env.VITE_GIT_HOOKS = '0';
try {
const result = install('.vite-hooks');
expect(result).toEqual({ message: 'skip install (git hooks disabled)', isError: false });
} finally {
if (prev === undefined) {
delete process.env.VITE_GIT_HOOKS;
} else {
process.env.VITE_GIT_HOOKS = prev;
}
}
});
});

describe('hookScript env gates', () => {
it('honors VP_GIT_HOOKS and keeps VITE_GIT_HOOKS as a deprecated alias', () => {
const script = hookScript('.vite-hooks');
expect(script).toContain('"$VP_GIT_HOOKS" = "2"');
expect(script).toContain('"$VITE_GIT_HOOKS" = "2"');
expect(script).toContain('"${VP_GIT_HOOKS-}" = "0"');
expect(script).toContain('"${VITE_GIT_HOOKS-}" = "0"');
});
});

describe('hookScript', () => {
Expand Down
8 changes: 7 additions & 1 deletion packages/cli/src/config/bin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,13 @@ async function main() {
},
{
title: 'Environment',
rows: [{ label: 'VITE_GIT_HOOKS=0', description: 'Skip hook installation' }],
rows: [
{ label: 'VP_GIT_HOOKS=0', description: 'Skip hook installation' },
{
label: 'VITE_GIT_HOOKS=0',
description: 'Deprecated alias of VP_GIT_HOOKS=0',
},
],
},
],
});
Expand Down
11 changes: 8 additions & 3 deletions packages/cli/src/config/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export function hookScript(dir: string): string {
const depth = segments + 2; // +2 for _ subdir and hook filename
const rootExpr = nestedDirname(depth);
return `#!/usr/bin/env sh
{ [ "$HUSKY" = "2" ] || [ "$VITE_GIT_HOOKS" = "2" ]; } && set -x
{ [ "$HUSKY" = "2" ] || [ "$VP_GIT_HOOKS" = "2" ] || [ "$VITE_GIT_HOOKS" = "2" ]; } && set -x
n=$(basename "$0")
s=$(dirname "$(dirname "$0")")/$n

Expand All @@ -47,7 +47,7 @@ i="\${XDG_CONFIG_HOME:-$HOME/.config}/vite-plus/hooks-init.sh"
[ ! -f "$i" ] && i="\${XDG_CONFIG_HOME:-$HOME/.config}/husky/init.sh"
[ -f "$i" ] && . "$i"

{ [ "\${HUSKY-}" = "0" ] || [ "\${VITE_GIT_HOOKS-}" = "0" ]; } && exit 0
{ [ "\${HUSKY-}" = "0" ] || [ "\${VP_GIT_HOOKS-}" = "0" ] || [ "\${VITE_GIT_HOOKS-}" = "0" ]; } && exit 0

d=${rootExpr}
__vp_shell=/bin/sh
Expand Down Expand Up @@ -77,7 +77,12 @@ export interface InstallResult {
}

export function install(dir = '.vite-hooks'): InstallResult {
if (process.env.HUSKY === '0' || process.env.VITE_GIT_HOOKS === '0') {
// VP_GIT_HOOKS is the canonical name; VITE_GIT_HOOKS is kept for backwards compatibility.
if (
process.env.HUSKY === '0' ||
process.env.VP_GIT_HOOKS === '0' ||
process.env.VITE_GIT_HOOKS === '0'
) {
return { message: 'skip install (git hooks disabled)', isError: false };
}
if (dir.includes('..')) {
Expand Down
4 changes: 2 additions & 2 deletions rfcs/config-and-staged-commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ Behavior:
3. Creates hook scripts in `<hooks-dir>/_/` that source the user-defined hooks in `<hooks-dir>/`
4. Agent instructions: silently updates existing files that contain Vite+ markers (`<!--VITE PLUS START-->`) when content is outdated. Never creates new agent files. Skipped with `--hooks-only`.
5. Safe to run multiple times (idempotent)
6. Exits 0 and skips hooks if `VITE_GIT_HOOKS=0` or `HUSKY=0` environment variable is set (backwards compatible)
6. Exits 0 and skips hooks if `VP_GIT_HOOKS=0`, `VITE_GIT_HOOKS=0` (deprecated alias), or `HUSKY=0` environment variable is set (backwards compatible)
7. Exits 0 and skips hooks if `.git` directory doesn't exist (safe during `npm install` in consumer projects)
8. Exits 1 on real errors (git command not found, `git config` failed)
9. Agent update runs uniformly in all modes (lifecycle script, interactive, non-interactive). New agent file creation is handled by `vp create`/`vp migrate`.
Expand Down Expand Up @@ -291,7 +291,7 @@ Husky <9.0.0 is not supported by auto migration — `vp migrate` detects unsuppo
```
vp config
├─ VITE_GIT_HOOKS=0 or HUSKY=0? ──→ Skip hooks (exit 0)
├─ VP_GIT_HOOKS=0 / VITE_GIT_HOOKS=0 / HUSKY=0? ──→ Skip hooks (exit 0)
├─ Not inside a git repo? ──→ Skip hooks (exit 0)
Expand Down