Skip to content

Commit cfb59b2

Browse files
fix(cli): preserve project-owned git hooks (#2280)
resolves #2252 --------- Co-authored-by: MK (fengmk2) <fengmk2@gmail.com>
1 parent 28b85a2 commit cfb59b2

81 files changed

Lines changed: 1321 additions & 755 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
vp run lint
2+
vp exec tsc --noEmit
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
[[case]]
22
name = "command_config_auto_hooks"
33
vp = "global"
4+
env = { npm_lifecycle_event = "prepare" }
45
steps = [
56
{ argv = ["git", "init"], snapshot = false, continue-on-failure = true },
6-
{ argv = ["vp", "config"], comment = "should install hooks automatically without prompting (staged config exists)", continue-on-failure = true },
7+
{ argv = ["vp", "config"], comment = "prepare should install the dispatcher without changing project hook policy", continue-on-failure = true },
78
{ argv = ["git", "config", "--local", "core.hooksPath"], comment = "should be .vite-hooks/_", continue-on-failure = true },
8-
{ argv = ["vpt", "print-file", ".vite-hooks/pre-commit"], comment = "should have vp staged", continue-on-failure = true },
9+
{ argv = ["vpt", "print-file", ".vite-hooks/pre-commit"], comment = "project-owned hook should remain unchanged", continue-on-failure = true },
910
{ argv = ["vpt", "print-file", "vite.config.ts"], comment = "should remain unchanged", continue-on-failure = true },
1011
]

crates/vite_cli_snapshots/tests/cli_snapshots/fixtures/command_config_auto_hooks/snapshots/command_config_auto_hooks.md

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
## `vp config`
77

8-
should install hooks automatically without prompting (staged config exists)
8+
prepare should install the dispatcher without changing project hook policy
99

1010
```
1111
```
@@ -20,10 +20,11 @@ should be .vite-hooks/_
2020

2121
## `vpt print-file .vite-hooks/pre-commit`
2222

23-
should have vp staged
23+
project-owned hook should remain unchanged
2424

2525
```
26-
vp staged
26+
vp run lint
27+
vp exec tsc --noEmit
2728
```
2829

2930
## `vpt print-file vite.config.ts`
@@ -33,9 +34,5 @@ should remain unchanged
3334
```
3435
import { defineConfig } from 'vite-plus';
3536
36-
export default defineConfig({
37-
staged: {
38-
'*': 'vp check --fix',
39-
},
40-
});
37+
export default defineConfig({});
4138
```
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
11
import { defineConfig } from 'vite-plus';
22

3-
export default defineConfig({
4-
staged: {
5-
'*': 'vp check --fix',
6-
},
7-
});
3+
export default defineConfig({});

crates/vite_cli_snapshots/tests/cli_snapshots/fixtures/command_config_help/snapshots/command_config_help.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@ VITE+ - The Unified Toolchain for the Web
77
88
Usage: vp config [OPTIONS]
99
10-
Configure Vite+ for the current project (hooks + agent integration).
10+
Configure Vite+ for the current project (hook dispatcher + agent integration).
1111
1212
Options:
1313
--hooks-dir <path> Custom hooks directory (default: .vite-hooks)
14-
--no-hooks Skip hook installation
14+
--no-hooks Skip hook dispatcher installation
1515
--no-agent Skip updating coding agent instructions
1616
-h, --help Show this help message
1717
1818
Environment:
19-
VP_GIT_HOOKS=0 Skip hook installation
19+
VP_GIT_HOOKS=0 Skip hook dispatcher installation
2020
2121
Documentation: https://viteplus.dev/guide/commit-hooks
2222
```
@@ -28,16 +28,16 @@ VITE+ - The Unified Toolchain for the Web
2828
2929
Usage: vp config [OPTIONS]
3030
31-
Configure Vite+ for the current project (hooks + agent integration).
31+
Configure Vite+ for the current project (hook dispatcher + agent integration).
3232
3333
Options:
3434
--hooks-dir <path> Custom hooks directory (default: .vite-hooks)
35-
--no-hooks Skip hook installation
35+
--no-hooks Skip hook dispatcher installation
3636
--no-agent Skip updating coding agent instructions
3737
-h, --help Show this help message
3838
3939
Environment:
40-
VP_GIT_HOOKS=0 Skip hook installation
40+
VP_GIT_HOOKS=0 Skip hook dispatcher installation
4141
4242
Documentation: https://viteplus.dev/guide/commit-hooks
4343
```
@@ -49,16 +49,16 @@ VITE+ - The Unified Toolchain for the Web
4949
5050
Usage: vp config [OPTIONS]
5151
52-
Configure Vite+ for the current project (hooks + agent integration).
52+
Configure Vite+ for the current project (hook dispatcher + agent integration).
5353
5454
Options:
5555
--hooks-dir <path> Custom hooks directory (default: .vite-hooks)
56-
--no-hooks Skip hook installation
56+
--no-hooks Skip hook dispatcher installation
5757
--no-agent Skip updating coding agent instructions
5858
-h, --help Show this help message
5959
6060
Environment:
61-
VP_GIT_HOOKS=0 Skip hook installation
61+
VP_GIT_HOOKS=0 Skip hook dispatcher installation
6262
6363
Documentation: https://viteplus.dev/guide/commit-hooks
6464
```

crates/vite_cli_snapshots/tests/cli_snapshots/fixtures/command_config_no_agent/snapshots.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name = "command_config_no_agent"
33
vp = "global"
44
steps = [
55
{ argv = ["git", "init"], snapshot = false, continue-on-failure = true },
6-
{ argv = ["vp", "config", "--no-agent"], comment = "should install hooks but skip agent instruction updates", continue-on-failure = true },
6+
{ argv = ["vp", "config", "--no-agent"], tty = false, comment = "should install the hook dispatcher but skip agent instruction updates", continue-on-failure = true },
77
{ argv = ["git", "config", "--local", "core.hooksPath"], comment = "should be .vite-hooks/_", continue-on-failure = true },
88
{ argv = ["vpt", "grep-file", "AGENTS.md", "OUTDATED CONTENT"], comment = "agent must stay unchanged (outdated marker still present)" },
99
]

crates/vite_cli_snapshots/tests/cli_snapshots/fixtures/command_config_no_agent/snapshots/command_config_no_agent.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
## `vp config --no-agent`
77

8-
should install hooks but skip agent instruction updates
8+
should install the hook dispatcher but skip agent instruction updates
99

1010
```
1111
```

crates/vite_cli_snapshots/tests/cli_snapshots/fixtures/command_config_postinstall_auto_hooks/snapshots.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ vp = "global"
44
env = { npm_lifecycle_event = "postinstall" }
55
steps = [
66
{ argv = ["git", "init"], snapshot = false, continue-on-failure = true },
7-
{ argv = ["vp", "config"], comment = "should install hooks automatically without prompting", continue-on-failure = true },
7+
{ argv = ["vp", "config"], comment = "should install the dispatcher automatically without prompting", continue-on-failure = true },
88
{ argv = ["git", "config", "--local", "core.hooksPath"], comment = "should be .vite-hooks/_", continue-on-failure = true },
9-
{ argv = ["vpt", "print-file", ".vite-hooks/pre-commit"], comment = "should have vp staged", continue-on-failure = true },
10-
{ argv = ["vpt", "print-file", "vite.config.ts"], comment = "should have staged config", continue-on-failure = true },
9+
{ argv = ["vpt", "stat-file", ".vite-hooks/_/pre-commit", "--assert", "file"], comment = "generated dispatcher shim should exist", continue-on-failure = true },
10+
{ argv = ["vpt", "stat-file", ".vite-hooks/pre-commit", "--assert", "missing"], comment = "project hook should not be created", continue-on-failure = true },
11+
{ argv = ["vpt", "stat-file", "vite.config.ts", "--assert", "missing"], comment = "vite config should not be created", continue-on-failure = true },
1112
]

crates/vite_cli_snapshots/tests/cli_snapshots/fixtures/command_config_postinstall_auto_hooks/snapshots/command_config_postinstall_auto_hooks.md

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
## `vp config`
77

8-
should install hooks automatically without prompting
8+
should install the dispatcher automatically without prompting
99

1010
```
1111
```
@@ -18,25 +18,26 @@ should be .vite-hooks/_
1818
.vite-hooks/_
1919
```
2020

21-
## `vpt print-file .vite-hooks/pre-commit`
21+
## `vpt stat-file .vite-hooks/_/pre-commit --assert file`
2222

23-
should have vp staged
23+
generated dispatcher shim should exist
2424

2525
```
26-
vp staged
26+
.vite-hooks/_/pre-commit: file
2727
```
2828

29-
## `vpt print-file vite.config.ts`
29+
## `vpt stat-file .vite-hooks/pre-commit --assert missing`
3030

31-
should have staged config
31+
project hook should not be created
3232

3333
```
34-
import { defineConfig } from 'vite-plus';
34+
.vite-hooks/pre-commit: missing
35+
```
36+
37+
## `vpt stat-file vite.config.ts --assert missing`
3538

36-
export default defineConfig({
37-
staged: {
38-
"*": "vp check --fix"
39-
},
39+
vite config should not be created
4040

41-
});
41+
```
42+
vite.config.ts: missing
4243
```

crates/vite_cli_snapshots/tests/cli_snapshots/fixtures/command_config_prepare_auto_hooks/snapshots.toml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ vp = "global"
44
env = { npm_lifecycle_event = "prepare" }
55
steps = [
66
{ argv = ["git", "init"], snapshot = false, continue-on-failure = true },
7-
{ argv = ["vp", "config"], comment = "should install hooks automatically without prompting", continue-on-failure = true },
7+
{ argv = ["vp", "config"], comment = "should install the dispatcher automatically without prompting", continue-on-failure = true },
88
{ argv = ["git", "config", "--local", "core.hooksPath"], comment = "should be .vite-hooks/_", continue-on-failure = true },
9-
{ argv = ["vpt", "print-file", ".vite-hooks/pre-commit"], comment = "should have vp staged", continue-on-failure = true },
10-
{ argv = ["vpt", "print-file", "vite.config.ts"], comment = "should have staged config", continue-on-failure = true },
9+
{ argv = ["vpt", "stat-file", ".vite-hooks/_/pre-commit", "--assert", "file"], comment = "generated dispatcher shim should exist", continue-on-failure = true },
10+
{ argv = ["vpt", "stat-file", ".vite-hooks/pre-commit", "--assert", "missing"], comment = "project hook should not be created", continue-on-failure = true },
11+
{ argv = ["vpt", "stat-file", "vite.config.ts", "--assert", "missing"], comment = "vite config should not be created", continue-on-failure = true },
1112
{ argv = ["vp", "config"], comment = "run again to ensure idempotent", continue-on-failure = true },
12-
{ argv = ["vpt", "print-file", ".vite-hooks/pre-commit"], comment = "should remain unchanged", continue-on-failure = true },
13-
{ argv = ["vpt", "print-file", "vite.config.ts"], comment = "should remain unchanged", continue-on-failure = true },
13+
{ argv = ["vpt", "stat-file", ".vite-hooks/pre-commit", "--assert", "missing"], comment = "project hook should still be absent", continue-on-failure = true },
14+
{ argv = ["vpt", "stat-file", "vite.config.ts", "--assert", "missing"], comment = "vite config should still be absent", continue-on-failure = true },
1415
]

0 commit comments

Comments
 (0)