Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Hook dispatcher breaks on Git for Windows when core.hooksPath is an absolute path

未关闭
#3,102 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
72/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
git, node.js, shell
领域
cli, devtools

调研方向

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 内容生成。

描述

pending triage

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 vp silently falls back to whatever else is on PATH (here, the global ~/.vite-plus/bin/vp).

Repro

  1. On Windows with Git for Windows, run vp config --hooks in a repo whose pre-commit is vp staged.
  2. Run git config core.hooksPath "$(pwd -W)\.vite-hooks\_", or any C:\... absolute value.
  3. 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

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

voidzero-dev/vite-plus 的其他 Issue

查看 voidzero-dev/vite-plus 的全部 Issue

相似的 Issue

更多 Rust Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。