Skip to content

fix: make lefthook prepare guard work under cmd.exe on Windows - #284

Merged
panish16 merged 1 commit into
mainfrom
fix/lefthook-prepare-windows
Sep 28, 2026
Merged

panish16 merged 1 commit into
mainfrom
fix/lefthook-prepare-windows

Conversation

@panish16

Copy link
Copy Markdown
Collaborator

Follow-up to #282, part of the Git Hooks RFC rollout (bcgov/entity#34619).

Problem

The prepare guard from #282 silently skips installing the hook on Windows:

"prepare": "command -v git >/dev/null 2>&1 && lefthook install || true"

pnpm/npm run lifecycle scripts through cmd.exe on Windows by default. command -v and /dev/null don't exist there, so it prints "The system cannot find the path specified", falls through to || true, and the install exits 0 with no hook installed. Windows devs get no secret scanning and nothing telling them so.

Fix

"prepare": "git --version && lefthook install || exit 0"

Same semantics as #282 (don't attempt lefthook at all when git is absent, e.g. the Cloud Build CD image; never fail the install) but works in both cmd.exe and POSIX sh.

Verified

  • cmd.exe (via pnpm run prepare on Windows), git present: hook installed
  • cmd.exe, git absent: exits 0, lefthook not attempted
  • POSIX sh, git present / absent: same as above
  • Real git commit with a fake GitHub token on Windows: blocked by gitleaks

Same change pushed to bcgov/ppr#2377 and bcgov/namex#2019.

pnpm/npm run lifecycle scripts through cmd.exe on Windows by default,
where `command -v` and `/dev/null` do not exist. The previous guard
errored and fell through to `|| true`, exiting 0 without installing
the hook, so Windows developers silently got no secret scanning.

`git --version && lefthook install || exit 0` has the same semantics
(skip entirely when git is absent, never fail the install) and works
in both cmd.exe and POSIX sh.
@panish16

Copy link
Copy Markdown
Collaborator Author

/gcbrun

@bcregistry-sre

Copy link
Copy Markdown
Collaborator

Temporary Url for review: https://yfthig-dev--pr-284-kjy4e9jz.web.app

@panish16
panish16 merged commit a16e7b9 into main Sep 28, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants