Skip to content

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

Open

Description

@WeitzY

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions