fix(hooks): guard GRAPHIFY_BIN assignment against sh -e exit when graphify not in PATH#1078
Open
j-strum wants to merge 1 commit into
Open
fix(hooks): guard GRAPHIFY_BIN assignment against sh -e exit when graphify not in PATH#1078j-strum wants to merge 1 commit into
j-strum wants to merge 1 commit into
Conversation
…phify not in PATH Husky v9's `h` runner invokes hooks with `sh -e`. On macOS (and any POSIX sh), a failing command substitution in a variable assignment — VAR=$(cmd_that_returns_1) — propagates the non-zero exit code, and sh -e terminates the script immediately. When graphify is installed via pyenv (shim at ~/.pyenv/shims/graphify) and a GUI git client like SourceTree runs git with a stripped PATH that excludes ~/.pyenv/shims, `command -v graphify` returns exit code 1. The entire hook exits with code 1 before reaching the graceful `exit 0` fallback — causing Husky to report "post-checkout script failed (code 1)" and "post-commit script failed (code 1)". The fix: || true absorbs the non-zero exit so the assignment always succeeds. GRAPHIFY_BIN is left empty, and the existing if [ -n "$GRAPHIFY_BIN" ] guard + python3 fallback + final exit 0 handle the "not found" case correctly as intended. Affects any tool that strips user PATH entries: SourceTree, Tower, VS Code's built-in git, cron, and CI runners. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Improves the robustness of the embedded shell snippet used to detect the graphify executable so the hook logic doesn’t fail when graphify isn’t on PATH.
Changes:
- Make
command -v graphifynon-fatal by appending|| trueto the assignment line.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Husky v9's
hrunner invokes hooks withsh -e. On macOS (and any POSIX sh), a failing command substitution in a variable assignment —VAR=$(cmd_that_returns_1)— propagates the non-zero exit code, andsh -eterminates the script immediately.When graphify is installed via pyenv (shim at
~/.pyenv/shims/graphify) and a GUI git client like SourceTree runs git with a stripped PATH that excludes~/.pyenv/shims,command -v graphifyreturns exit code 1. The entire hook exits with code 1 before reaching the gracefulexit 0fallback — causing Husky to report:Reproducible with:
The same issue affects any tool that strips user PATH entries: SourceTree, Tower, VS Code's built-in git, cron, and CI runners.
Fix
|| trueabsorbs the non-zero exit so the assignment always succeeds.GRAPHIFY_BINis left empty, and the existingif [ -n "$GRAPHIFY_BIN" ]guard + python3 fallback + finalexit 0handle the "not found" case correctly as intended.Change
One line in
graphify/hooks.py— the_PYTHON_DETECTshell template string shared by both the post-commit and post-checkout hook generators.