Skip to content

fix(cli): keep git hooks running when vp config rewrites the dispatcher - #3570

Merged
fengmk2 merged 5 commits into
mainfrom
triagebot/fix-3567
Nov 25, 2026
Merged

fengmk2 merged 5 commits into
mainfrom
triagebot/fix-3567

Conversation

@voidzero-bot

@voidzero-bot voidzero-bot Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

When a hook runs vp config (for example pnpm install with "prepare": "vp config" in post-checkout), the hook can fail after the user script completes. The shell reports a syntax error such as Unterminated quoted string, and git checkout or git merge exits non-zero, although the install succeeded.

The hook stub sources .vite-hooks/_/h. dash and BusyBox ash read a sourced file in blocks and read the next block only when they need it. vp config rewrote h in place, so the shell parsed bytes of the new file after the hook. The last line exit $c had no final newline, so the shell always read once more at the end of the file.

This PR makes two changes:

  • vp config writes h and the hook stubs to a temp file in <dir>/_/ and renames it over the target. A shell that has the old dispatcher open keeps reading the old file. This also covers the upgrade from a dispatcher that vite-plus 1.8.0 or earlier wrote. If the temp file or the rename fails (for example, when Windows locks the target), the write falls back to an in-place write, as before.
  • The dispatcher body is now one { ... } group, and the generated files end with a newline. The shell parses the whole dispatcher before the hook runs. This protects a running hook when vite-plus 1.8.0 or earlier rewrites the file in place, for example after a checkout of a branch that pins an older version.

A final newline alone protects only shells that read the whole dispatcher (1058 bytes) in one block:

Shell Bytes per read Final newline only Brace group
Debian/Ubuntu dash (glibc) 8192 protected protected
Alpine BusyBox ash 2047 protected protected
macOS /bin/dash, BusyBox with default config about 1024 not protected protected
bash reads the whole file not affected not affected

The dispatcher text changes, so the next vp config or vp hooks enable run refreshes existing dispatchers one time.

Closes #3567

🤖 Generated with Claude Code

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

🚀 Deploying Preview to Cloudflare 🚀

Preview URL: https://triagebot-fix-3567-viteplus-dev.voidzero-docs.workers.dev (commit c73f258)

This URL reflects your latest Preview deployment

Preview Deployments by commit

Status Deployment URL Commit Updated (UTC) See this deployment's details
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://5929e3ca-viteplus-dev.voidzero-docs.workers.dev c73f258 2026-11-25T12:07:54.765Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://c8f61c83-viteplus-dev.voidzero-docs.workers.dev 905dd2a 2026-11-25T10:10:22.181Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://890cbf22-viteplus-dev.voidzero-docs.workers.dev d0e211e 2026-11-25T07:26:54.912Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://9fcdaf38-viteplus-dev.voidzero-docs.workers.dev 3733d35 2026-11-25T07:22:41.333Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://7e723bf1-viteplus-dev.voidzero-docs.workers.dev 4ee55ea 2026-11-24T21:12:20.038Z Visit the dashboard ↗

@fengmk2 fengmk2 changed the title fix(cli): newline-terminate and atomically replace git hook dispatcher files fix(cli): keep git hooks running when vp config rewrites the dispatcher Nov 25, 2026
voidzero-bot Bot and others added 2 commits November 25, 2026 15:25
The final newline alone does not stop the failure in #3567 when the shell
reads the dispatcher in blocks smaller than the file. macOS /bin/dash and
BusyBox builds with the default config read 1 KiB at a time, and the
dispatcher is larger. Put the dispatcher body in a brace group, so the
shell parses the whole file before it runs the hook.

Create the temp file with `wx` and set its mode before the rename. Run the
hook tests with dash where it exists, and add a test that runs `install()`
while a hook runs a dispatcher from vite-plus 1.8.0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@fengmk2 fengmk2 self-assigned this Nov 25, 2026
@fengmk2 fengmk2 added test: e2e Auto run e2e tests test: install-e2e run vite install e2e test test: create-e2e Run `vp create` e2e tests test: sfw labels Nov 25, 2026
fengmk2 and others added 2 commits November 25, 2026 16:29
On Windows, a temp file that another process locks can make the rename and
the cleanup both fail. The cleanup error then left the write helper, and
the in-place fallback did not run. A temp name with the pid can also match
a file from a crashed run, which forces the in-place write.

Use a random temp name, and make the cleanup best-effort so that the
fallback always runs. The tests now check that no temp file stays, and
release the waiting hook when an assertion fails.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`no-promise-executor-return` rejects `new Promise((resolve) => setTimeout(resolve, 20))`
because the arrow returns the timer. Use `setTimeout` from `node:timers/promises`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@fengmk2
fengmk2 requested a review from cpojer November 25, 2026 10:49
@fengmk2
fengmk2 merged commit ce91aa6 into main Nov 25, 2026
152 of 154 checks passed
@fengmk2
fengmk2 deleted the triagebot/fix-3567 branch November 25, 2026 12:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix verified test: create-e2e Run `vp create` e2e tests test: e2e Auto run e2e tests test: install-e2e run vite install e2e test test: sfw

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Git hook dispatcher fails with a shell syntax error when vp config rewrites .vite-hooks/_/h during a hook

2 participants