diff --git a/crates/vite_cli_snapshots/tests/cli_snapshots/fixtures/command_config_help/snapshots/command_config_help.md b/crates/vite_cli_snapshots/tests/cli_snapshots/fixtures/command_config_help/snapshots/command_config_help.md index cd0277a5fb..2a3ca1f39c 100644 --- a/crates/vite_cli_snapshots/tests/cli_snapshots/fixtures/command_config_help/snapshots/command_config_help.md +++ b/crates/vite_cli_snapshots/tests/cli_snapshots/fixtures/command_config_help/snapshots/command_config_help.md @@ -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 ``` @@ -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 ``` @@ -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 ``` diff --git a/crates/vite_cli_snapshots/tests/cli_snapshots/fixtures/migration_add_git_hooks/snapshots/migration_add_git_hooks.md b/crates/vite_cli_snapshots/tests/cli_snapshots/fixtures/migration_add_git_hooks/snapshots/migration_add_git_hooks.md index 9d184709e1..bdb8767398 100644 --- a/crates/vite_cli_snapshots/tests/cli_snapshots/fixtures/migration_add_git_hooks/snapshots/migration_add_git_hooks.md +++ b/crates/vite_cli_snapshots/tests/cli_snapshots/fixtures/migration_add_git_hooks/snapshots/migration_add_git_hooks.md @@ -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 @@ -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 diff --git a/crates/vite_cli_snapshots/tests/cli_snapshots/fixtures/migration_composed_husky_custom_dir/snapshots/migration_composed_husky_custom_dir.md b/crates/vite_cli_snapshots/tests/cli_snapshots/fixtures/migration_composed_husky_custom_dir/snapshots/migration_composed_husky_custom_dir.md index 5535dd120a..8eb018d109 100644 --- a/crates/vite_cli_snapshots/tests/cli_snapshots/fixtures/migration_composed_husky_custom_dir/snapshots/migration_composed_husky_custom_dir.md +++ b/crates/vite_cli_snapshots/tests/cli_snapshots/fixtures/migration_composed_husky_custom_dir/snapshots/migration_composed_husky_custom_dir.md @@ -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 @@ -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 diff --git a/docs/guide/commit-hooks.md b/docs/guide/commit-hooks.md index bbd9733dcb..7a8c8d5668 100644 --- a/docs/guide/commit-hooks.md +++ b/docs/guide/commit-hooks.md @@ -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` diff --git a/docs/guide/troubleshooting.md b/docs/guide/troubleshooting.md index 10ac108654..49bc1543ec 100644 --- a/docs/guide/troubleshooting.md +++ b/docs/guide/troubleshooting.md @@ -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: diff --git a/packages/cli/src/config/__tests__/hooks.spec.ts b/packages/cli/src/config/__tests__/hooks.spec.ts index 8d6145d916..3b6492fd04 100644 --- a/packages/cli/src/config/__tests__/hooks.spec.ts +++ b/packages/cli/src/config/__tests__/hooks.spec.ts @@ -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', () => { diff --git a/packages/cli/src/config/bin.ts b/packages/cli/src/config/bin.ts index 626e62506e..45408dfce9 100644 --- a/packages/cli/src/config/bin.ts +++ b/packages/cli/src/config/bin.ts @@ -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', + }, + ], }, ], }); diff --git a/packages/cli/src/config/hooks.ts b/packages/cli/src/config/hooks.ts index f9ef89b360..ca845e4fdf 100644 --- a/packages/cli/src/config/hooks.ts +++ b/packages/cli/src/config/hooks.ts @@ -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 @@ -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 @@ -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('..')) { diff --git a/rfcs/config-and-staged-commands.md b/rfcs/config-and-staged-commands.md index 1b40224ce4..df719c1041 100644 --- a/rfcs/config-and-staged-commands.md +++ b/rfcs/config-and-staged-commands.md @@ -105,7 +105,7 @@ Behavior: 3. Creates hook scripts in `/_/` that source the user-defined hooks in `/` 4. Agent instructions: silently updates existing files that contain Vite+ markers (``) 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`. @@ -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) │