Skip to content
Merged
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 @@ -23,6 +23,7 @@ Environment:
Examples:
vp hooks enable
vp hooks enable --hooks-dir .custom-hooks
vp hooks enable --replace-husky
vp hooks disable
vp hooks status

Expand Down Expand Up @@ -52,6 +53,7 @@ Environment:
Examples:
vp hooks enable
vp hooks enable --hooks-dir .custom-hooks
vp hooks enable --replace-husky
vp hooks disable
vp hooks status

Expand All @@ -70,6 +72,7 @@ Install or refresh the hook dispatcher (sets core.hooksPath)
Options:
--hooks-dir <path> Custom hooks directory (default: .vite-hooks, or last used)
-h, --help Show this help message
--replace-husky Replace a local Husky hooks path after migrating custom checks (old files are preserved but no longer run)

Documentation: https://viteplus.dev/guide/commit-hooks
```
Expand Down Expand Up @@ -97,6 +100,7 @@ Environment:
Examples:
vp hooks enable
vp hooks enable --hooks-dir .custom-hooks
vp hooks enable --replace-husky
vp hooks disable
vp hooks status

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Environment:
Examples:
vp hooks enable
vp hooks enable --hooks-dir .custom-hooks
vp hooks enable --replace-husky
vp hooks disable
vp hooks status

Expand Down Expand Up @@ -52,6 +53,7 @@ Environment:
Examples:
vp hooks enable
vp hooks enable --hooks-dir .custom-hooks
vp hooks enable --replace-husky
vp hooks disable
vp hooks status

Expand All @@ -70,6 +72,7 @@ Install or refresh the hook dispatcher (sets core.hooksPath)
Options:
--hooks-dir <path> Custom hooks directory (default: .vite-hooks, or last used)
-h, --help Show this help message
--replace-husky Replace a local Husky hooks path after migrating custom checks (old files are preserved but no longer run)

Documentation: https://viteplus.dev/guide/commit-hooks
```
Expand Down Expand Up @@ -97,6 +100,7 @@ Environment:
Examples:
vp hooks enable
vp hooks enable --hooks-dir .custom-hooks
vp hooks enable --replace-husky
vp hooks disable
vp hooks status

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "hooks-replace-husky",
"private": true,
"scripts": {
"prepare": "vp config"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[[case]]
name = "command_hooks_replace_husky"
vp = ["local", "global"]
steps = [
{ argv = ["git", "init"], snapshot = false },
{ argv = ["git", "config", "core.hooksPath", ".husky/_"], snapshot = false },
{ argv = ["vpt", "write-file", ".husky/_/pre-commit", "#!/bin/sh\necho original-check-rejected >&2\nexit 1\n"], snapshot = false },
{ argv = ["vpt", "write-file", ".vite-hooks/commit-msg", "echo migrated-check-rejected >&2\nexit 1\n"], snapshot = false },
{ argv = ["vp", "config", "--no-agent"], tty = false, comment = "preserve non-empty Husky directory and explain recovery" },
{ argv = ["vp", "hooks", "enable"], comment = "ordinary enable also preserves old hooks" },
{ argv = ["git", "config", "--local", "core.hooksPath"], comment = "Husky remains active until explicit replacement" },
{ argv = ["vp", "hooks", "enable", "--replace-husky"], envs = [["VP_GIT_HOOKS", "0"]], comment = "explicit replacement honors environment opt-out" },
{ argv = ["git", "config", "--local", "core.hooksPath"], comment = "opt-out left the path unchanged" },
{ argv = ["vp", "hooks", "enable", "--replace-husky"], comment = "explicitly activate the migrated hooks, explaining the old hooks no longer run" },
{ argv = ["git", "config", "--local", "core.hooksPath"], comment = "Vite+ dispatcher is now active" },
{ argv = ["vpt", "print-file", ".husky/_/pre-commit"], comment = "old Husky script was preserved" },
{ argv = ["vpt", "print-file", "package.json"], comment = "prepare does not acquire the explicit replacement flag" },
{ argv = ["git", "-c", "user.name=Test", "-c", "user.email=test@example.invalid", "-c", "commit.gpgsign=false", "commit", "--allow-empty", "-m", "test"], comment = "the migrated check rejects the commit", continue-on-failure = true },
{ argv = ["vp", "hooks", "disable", "--replace-husky"], comment = "the replacement option is enable-only", continue-on-failure = true },
]

[[case]]
name = "command_hooks_recover_empty_husky"
vp = ["local", "global"]
steps = [
{ argv = ["git", "init"], snapshot = false },
{ argv = ["git", "config", "core.hooksPath", ".husky/_"], snapshot = false },
{ argv = ["vpt", "mkdir", "-p", ".husky/_"], snapshot = false },
{ argv = ["vpt", "write-file", ".vite-hooks/pre-commit", "exit 0\n"], snapshot = false },
{ argv = ["vp", "config", "--no-agent"], tty = false, comment = "recover an empty old directory automatically" },
{ argv = ["git", "config", "--local", "core.hooksPath"], comment = "Vite+ hooks are active without an explicit override" },
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# command_hooks_recover_empty_husky

## `git init`


## `git config core.hooksPath .husky/_`


## `vpt mkdir -p .husky/_`


## `vpt write-file .vite-hooks/pre-commit 'exit 0
'`


## `vp config --no-agent`

recover an empty old directory automatically

```
```

## `git config --local core.hooksPath`

Vite+ hooks are active without an explicit override

```
.vite-hooks/_
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# command_hooks_recover_empty_husky

## `git init`


## `git config core.hooksPath .husky/_`


## `vpt mkdir -p .husky/_`


## `vpt write-file .vite-hooks/pre-commit 'exit 0
'`


## `vp config --no-agent`

recover an empty old directory automatically

```
```

## `git config --local core.hooksPath`

Vite+ hooks are active without an explicit override

```
.vite-hooks/_
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
# command_hooks_replace_husky

## `git init`


## `git config core.hooksPath .husky/_`


## `vpt write-file .husky/_/pre-commit '#'\!'/bin/sh
echo original-check-rejected >&2
exit 1
'`


## `vpt write-file .vite-hooks/commit-msg 'echo migrated-check-rejected >&2
exit 1
'`


## `vp config --no-agent`

preserve non-empty Husky directory and explain recovery

```
core.hooksPath is already set to ".husky/_", skipping. Vite+ hooks at .vite-hooks are not active. Migrate any custom Husky checks, then run `vp hooks enable --replace-husky` (with the same --hooks-dir if customized). Switching stops running hooks from ".husky/_"; the old files are preserved.
```

## `vp hooks enable`

ordinary enable also preserves old hooks

```
core.hooksPath is already set to ".husky/_", skipping. Vite+ hooks at .vite-hooks are not active. Migrate any custom Husky checks, then run `vp hooks enable --replace-husky` (with the same --hooks-dir if customized). Switching stops running hooks from ".husky/_"; the old files are preserved.
```

## `git config --local core.hooksPath`

Husky remains active until explicit replacement

```
.husky/_
```

## `VP_GIT_HOOKS=0 vp hooks enable --replace-husky`

explicit replacement honors environment opt-out

```
skip install (git hooks disabled)
```

## `git config --local core.hooksPath`

opt-out left the path unchanged

```
.husky/_
```

## `vp hooks enable --replace-husky`

explicitly activate the migrated hooks, explaining the old hooks no longer run

```
Git hook dispatcher installed at .vite-hooks/_. Replaced core.hooksPath ".husky/_". Old Husky files were preserved, but hooks from ".husky/_" no longer run. Custom checks must be migrated to .vite-hooks.
```

## `git config --local core.hooksPath`

Vite+ dispatcher is now active

```
.vite-hooks/_
```

## `vpt print-file .husky/_/pre-commit`

old Husky script was preserved

```
#!/bin/sh
echo original-check-rejected >&2
exit 1
```

## `vpt print-file package.json`

prepare does not acquire the explicit replacement flag

```
{
"name": "hooks-replace-husky",
"private": true,
"scripts": {
"prepare": "vp config"
}
}
```

## `git -c user.name=Test -c user.email=test@example.invalid -c commit.gpgsign=false commit --allow-empty -m test`

the migrated check rejects the commit

**Exit code:** 1

```
migrated-check-rejected
VITE+ - commit-msg script failed (code 1)
```

## `vp hooks disable --replace-husky`

the replacement option is enable-only

**Exit code:** 1

```
VITE+ - The Unified Toolchain for the Web

error: unexpected argument '--replace-husky' found

Usage: vp hooks disable [OPTIONS]

For more information, try '--help'.
```
Loading
Loading