Skip to content

Hooks: PATHEXT is .CPL in the hook environment when the hook shell is PowerShell, so Git LFS pre-push can't find git #23245

Backlog

Description

@Taiizor

The problem

On Windows, with Load Git hook environment variables from shell enabled and the shell set to Windows PowerShell or PowerShell Core, the Git LFS pre-push hook fails on every push:

Running pre-push hook...
Error getting Git version: executable file not found in %PATH%
pre-push hook failed with code 2 after 0.47s

Root cause. getShellEnv in app/src/lib/hooks/get-shell-env.ts spawns the shell with an empty environment:

const child = spawn(shell, [...args, quoteCommand(printenvzPath)], {
  env: {},
  ...

When it is given an empty environment on Windows, Node/libuv adds only a fixed set of required variables (PATH, SYSTEMROOT, TEMP, USERPROFILE, ...), and PATHEXT is not one of them. PowerShell (both 5.1 and 7) starts without PATHEXT and sets it to just .CPL. printenvz captures that value and the hook runs with it. git-lfs (Go) resolves git through PATHEXT, so it looks only for git.CPL and never finds git.exe. The same problem breaks hooks that call .cmd shims such as npm or ts-node (#23154).

With Git Bash or Command Prompt, PATHEXT is not set at all. Go then falls back to its default extensions, and the hook works.

Release version

3.7.1-beta2 (x64); also seen on 3.6.12-beta2

Operating system

Windows 11 (10.0.26300), Git LFS 3.8.1, Git for Windows 2.56.1

Steps to reproduce the behavior

  1. Go to File → Options → Git → Hooks, enable "Load Git hook environment variables from shell" and choose Windows PowerShell (or PowerShell Core).
  2. Open a repository with the Git LFS hooks installed (git lfs install; .git/hooks/pre-push runs git lfs pre-push "$@").
  3. Commit and push.
  4. The "pre-push hook failed" dialog appears.

A simpler check that doesn't need LFS: a pre-push hook containing echo "PATHEXT=$PATHEXT" >&2; exit 1 should print PATHEXT=.CPL.

Log files

error: [ui] `git push --progress -- origin <branch>:<branch>` exited with an unexpected code: 1.
Running pre-push hook...
Error getting Git version: executable file not found in %PATH%
pre-push hook failed with code 2 after 0.47s
error: failed to push some refs to '<remote>'

Additional context

I reproduced this outside Desktop by replaying the getShellEnv + hooks-proxy flow with the same parameters. The replay spawns the shell with an empty environment and runs printenvz, sets GIT_EXEC_PATH from the system Git, and then runs git hook run pre-push with the bundled Git:

Hook shell Captured PATHEXT Result
Windows PowerShell .CPL fails, exit 2
PowerShell Core .CPL fails, exit 2
PowerShell, default PATHEXT put back into the hook environment default list passes
Git Bash not set passes
Command Prompt not set passes

Possible fix: on Windows, pass the parent's PATHEXT when spawning the shell, for example env: __WIN32__ && process.env.PATHEXT ? { PATHEXT: process.env.PATHEXT } : {}. Another option is to restore PATHEXT from process.env when the loaded environment is missing it or contains only .CPL.

Workaround: choose Git Bash or Command Prompt as the hook shell.

Related: #23154 (same root cause; ts-node.cmd is not found).

Activity

  1. added
    bug
    priority-2
    on Nov 27, 2026
  2. desktop-triage commented on Nov 27, 2026

    @desktop-triage

    Triage summary: This is a reproducible Windows bug affecting any user who selects PowerShell/PowerShell Core as the Git hooks shell and has a hook that resolves a .cmd/extension-less executable via PATHEXT (e.g., Git LFS, npm, ts-node); I'm requesting bug, priority-2, and windows with HIGH confidence, since the report includes precise repro steps, version info, error text, and a clear mechanism. This appears closely related to #23154 (same root cause, ts-node.cmd not found) — not a duplicate to close, since that issue reports the symptom without diagnosing the cause, but both should likely be fixed together.

    Initial hypothesis

    The reporter's analysis lines up with the current source: getShellEnv in app/src/lib/hooks/get-shell-env.ts (lines 33–39) spawns the configured hook shell with env: {}, i.e. no inherited environment. On Windows, child_process.spawn with an empty env causes Node/libuv to populate only a minimal required set of variables; PowerShell then initializes its own session and sets PATHEXT to a degenerate value (.CPL) rather than the Windows default list (.COM;.EXE;.BAT;.CMD;...). Because printenvz captures whatever PATHEXT exists in that shell session and the hook later runs with that captured environment, any subsequent lookup that depends on PATHEXT to resolve a non-.exe executable (Git LFS resolving git, or npm/ts-node.cmd shims) fails with "executable file not found". Git Bash and cmd.exe apparently don't set PATHEXT at all in this scenario, letting Go/npm fall back to built-in default extensions, which is why only the PowerShell hook shells are affected. This is consistent with both this issue and #23154 and points at the env: {} spawn option (or the missing PATHEXT restoration before running hooks) as the next thing for a maintainer to verify.

    Generated by Issue Triage (skills-driven) for #23245 · auto · 25.6 AIC · ⊞ 4.7K · ◷

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugpriority-2

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions