Hook dispatcher breaks on Git for Windows when core.hooksPath is an absolute path
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 72/100
调研方向
Start by reading the generated .vite-hooks/_/h script described in the issue, then locate the code that generates it and any related hook tests. Reproduce on Windows with Git for Windows using an absolute core.hooksPath. Done means the generated dispatcher handles that path correctly and git commit runs the repository's hook without the reported module error or silently falling back to a global vp.
由索引模型根据 Issue 内容生成。
描述
Version: vite-plus 1.3.0 (global vp 1.2.0), Git for Windows 2.54.0, Node 22.23.1, Windows 11.
What happens
When core.hooksPath is an absolute Windows path such as C:\repo\.vite-hooks\_, every hook fails:
Error: Cannot find module 'C:\Program Files\Git\Users\me\repo\node_modules\vite-plus\bin\vp'
VITE+ - pre-commit script failed (code 1)
Some tools set an absolute path on purpose. For example, worktree managers point linked worktrees at the main checkout's dispatcher, because the generated .vite-hooks/_ is gitignored and missing in a new worktree.
Cause
The generated .vite-hooks/_/h derives the repo root from $0 and prepends it to PATH:
d="$(dirname "$(dirname "$(dirname "$0")")")"
export PATH="$d/node_modules/.bin:$PATH"
Git for Windows passes $0 as a drive-letter path, so d is C:\repo or C:/repo. sh splits the PATH entry at the drive colon into C and \repo\node_modules\.bin:
- With backslashes, sh finds the pnpm shim through the drive-relative path. The shim then passes
/repo/...to Node, which MSYS maps under the Git install root, giving the MODULE_NOT_FOUND above. - With forward slashes, the entry doesn't resolve, and
vpsilently falls back to whatever else is on PATH (here, the global~/.vite-plus/bin/vp).
Repro
- On Windows with Git for Windows, run
vp config --hooksin a repo whose pre-commit isvp staged. - Run
git config core.hooksPath "$(pwd -W)\.vite-hooks\_", or anyC:\...absolute value. - Run
git commit.
Suggested fix
Normalise d (or $0) to a POSIX path before building PATH, for example:
case "$d" in [A-Za-z]:*) command -v cygpath >/dev/null 2>&1 && d=$(cygpath -u "$d") ;; esac
Alternatively, avoid putting a path derived from $0 into PATH. Husky uses the cwd-relative node_modules/.bin.
Workaround we use (documented init script ~/.config/vite-plus/hooks-init.sh):
case "$0" in
[A-Za-z]:*)
if [ -z "${VP_HOOKS_POSIX_REEXEC-}" ] && command -v cygpath >/dev/null 2>&1; then
export VP_HOOKS_POSIX_REEXEC=1
exec sh "$(cygpath -u "$0")" "$@"
fi
;;
esac
- 主要语言
- Rust
- 星标
- 6.3k
- 派生
- 283
- 平均合并
- 1 天 14 小时
- 30 天内合并 PR
- 208
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
voidzero-dev/vite-plus 的其他 Issue
-
contribution welcome
难度 2/5 1-3 小时 新手友好度 74/100
voidzero-dev/vite-plus#3096 · 1 条评论 · 3 个 reaction ·
维护者通常 1 天内回复
-
pending triage
难度 2/5 1-3 小时 新手友好度 72/100
voidzero-dev/vite-plus#2882 · 2 条评论 ·
维护者通常 1 天内回复
-
enhancement
难度 2/5 1-3 小时 新手友好度 62/100
voidzero-dev/vite-plus#2097 · 10 条评论 · 2 个 reaction ·
维护者通常 1 天内回复
-
pending triage
难度 3/5 半天 新手友好度 78/100
voidzero-dev/vite-plus#3110 ·
维护者通常 1 天内回复
-
pending triage
难度 5/5 一周以上 新手友好度 28/100
voidzero-dev/vite-plus#3107 · 1 个 reaction ·
维护者通常 1 天内回复
查看 voidzero-dev/vite-plus 的全部 Issue
相似的 Issue
-
documentation P2
难度 2/5 1-3 小时 新手友好度 88/100
维护者通常 1 天内回复
-
bug good first issue priority:high
难度 2/5 1-3 小时 新手友好度 88/100
Konfirm-xyz/konfirm-contracts#163 ·
维护者通常 1 天内回复
-
area:gc-repack-output bug factory:dogfood factory:triaged priority:p3 type:bug type:ux
难度 2/5 1-3 小时 新手友好度 72/100
gitbutlerapp/grit#1161 · 1 条评论 ·
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 1 天内回复
-
feature performance
难度 2/5 1-3 小时 新手友好度 65/100
lance-format/lance#10137 ·
维护者通常 2 天内回复