Skip to content

Preserve Windows PATHEXT when loading hook shell environment - #23251

Open
aakifsaf wants to merge 1 commit into
desktop:developmentfrom
aakifsaf:fix/powershell-hooks-pathext
Open

aakifsaf wants to merge 1 commit into
desktop:developmentfrom
aakifsaf:fix/powershell-hooks-pathext

Conversation

@aakifsaf

Copy link
Copy Markdown

Closes #23245
Closes #23154

Description

  • On Windows, getShellEnv previously spawned the configured hook shell with env: {}. Because Node/libuv does not inject PATHEXT into an empty environment object, PowerShell (both Windows PowerShell 5.1 and PowerShell 7) initialized PATHEXT to .CPL alone, breaking extensionless lookup for tools like git (e.g., git-lfs pre-push) and .cmd shims (npm / ts-node) inside Git hooks.
  • Update app/src/lib/hooks/get-shell-env.ts to seed PATHEXT from process.env (looked up case-insensitively, falling back to .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC if unset) when spawning the shell on Windows (__WIN32__). Non-Windows platforms continue passing {}.
  • Seeding PATHEXT before spawning rather than patching afterward lets user PowerShell $PROFILE scripts extend or override $env:PATHEXT normally instead of starting from .CPL.
  • Added Windows assertions in app/test/unit/get-shell-env-test.ts verifying PATHEXT includes .EXE and .CMD across git-bash, pwsh, powershell, and cmd, plus fallback behavior when parent PATHEXT is absent.

How I verified

  • Reproduced PATHEXT=.CPL directly on Windows 11 with powershell.exe and pwsh.exe when spawned with env: {}.
  • Verified node script/test.mjs app/test/unit/get-shell-env-test.ts passes (5/5 tests across git-bash, pwsh, powershell, cmd, and missing-PATHEXT fallback).
  • Verified npm run prettier, npm run lint:src, npx tsc --noEmit, and npm run test:eslint (6/6) pass with zero warnings or errors.

Screenshots

N/A (no UI changes)

Release notes

Notes: [Fixed] Git hooks using PowerShell on Windows now preserve PATHEXT so Git LFS and command shims resolve correctly - #23245

@aakifsaf
aakifsaf requested a review from a team as a code owner November 30, 2026 16:18
@aakifsaf
aakifsaf requested review from tidy-dev and a balanced review from Copilot November 30, 2026 16:18
@github-actions github-actions Bot added external Pull request originating outside of the Desktop core team needs-triage unmet-requirements and removed needs-triage labels Nov 30, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for your pull request! Unfortunately, it doesn't meet the requirements for review:

  • None of the referenced issues have the help wanted label

Please update your PR to address the above. This PR will be automatically closed in 7 days if these requirements are not met.

Full contribution requirements
  1. Include a detailed description of what this PR does
  2. Link to an issue with the help wanted label (use Fixes #123 or Closes #123)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues block the change to preserve Windows PATHEXT for hook shells.

No open issues 🎉

What changed in this PR

This PR addresses #23245 and #23154 by preserving Windows PATHEXT when GitHub Desktop loads the hook shell environment, allowing PowerShell hooks to resolve executables and command shims correctly.

Changes:

  • Seeds Windows shell launches with the parent’s PATHEXT, using case-insensitive lookup and a default extension list when missing or empty.
  • Leaves non-Windows behavior unchanged and allows shell profiles to customize the seeded value.
  • Adds Windows assertions for .EXE and .CMD across supported shells, plus a missing-parent fallback test.
File Description
app/​test/​unit/​get-shell-env-test.ts Adds Windows PATHEXT assertions and PowerShell fallback coverage.
app/​src/​lib/​hooks/​get-shell-env.ts Seeds PATHEXT before spawning Windows hook shells.

Review effort: Balanced

This branch has not been deployed

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

Labels

external Pull request originating outside of the Desktop core team unmet-requirements

Projects

None yet

2 participants