Skip to content

fix: Use POSIX redirect in pre-commit gitleaks guard - #2486

Merged
homin-bt merged 1 commit into
mainfrom
homin/fix-pre-commit-gitleaks-guard
Sep 14, 2026
Merged

homin-bt merged 1 commit into
mainfrom
homin/fix-pre-commit-gitleaks-guard

Conversation

@homin-bt

Copy link
Copy Markdown
Contributor

&> /dev/null in .husky/pre-commit is a bashism. Husky runs hooks under /bin/sh, so on systems where that is dash (Linux CI runners) the guard parses as a backgrounded command -v gitleaks & followed by a bare > /dev/null redirection, whose exit status is always 0. The if is therefore always true: gitleaks protect runs even when gitleaks is not installed, and the warning branch is unreachable. This was failing on CI with Linux runners.

Verified with the dash on macOS:

$ dash -c 'if command -v nonexistent &> /dev/null; then echo then; else echo else; fi'
then          # wrong
$ dash -c 'if command -v nonexistent >/dev/null 2>&1; then echo then; else echo else; fi'
else          # correct

After the change, running the hook under dash with gitleaks absent takes the else branch and prints the intended warning.

`&> /dev/null` is a bashism. Husky runs hooks under `/bin/sh`, so on
systems where that is dash the guard parsed as a backgrounded
`command -v gitleaks &` followed by a bare `> /dev/null` redirection,
whose exit status is always 0. That made the `if` always true, so
`gitleaks protect` ran even when gitleaks was not installed and the
warning branch was unreachable.

This was failing on CI with Linux runners.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 14, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-14T18:13:33.250727Z 058ad4e PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@homin-bt
homin-bt merged commit aad6256 into main Sep 14, 2026
53 checks passed
@homin-bt
homin-bt deleted the homin/fix-pre-commit-gitleaks-guard branch September 14, 2026 19:40
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.

2 participants