fix: pass full command to checkGit for cd target detection#32
Merged
George-iam merged 2 commits intomainfrom Apr 7, 2026
Merged
fix: pass full command to checkGit for cd target detection#32George-iam merged 2 commits intomainfrom
George-iam merged 2 commits intomainfrom
Conversation
splitCommandSegments was stripping cd /path from the command before passing to checkGit. detectBranch/extractGitCwd never saw the cd target, so merged-PR check failed on chained commands. Now checkGit receives the full command string.
Replace fragile command-text parsing with proper cd/pushd state tracking through command segments in pre-tool-use hook: - Track effectiveCwd cumulatively through cd/pushd segments - Parse git -C flag from git segments - Pass resolved cwd to checkGit/detectBranch explicitly - If cwd unresolvable (variables, subshells): BLOCK with instruction to use git -C /absolute/path - Remove extractGitCwd regex parsing from safety.ts - detectBranch/checkMergedBranch accept cwd parameter
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.
Summary
Hook's
splitCommandSegmentswas strippingcd /path &&prefix before passing tocheckGit.extractGitCwdindetectBranchnever saw the cd target, so merged-PR check silently passed.Fix: pass full command string to
checkGitinstead of individual segments.extractGitCwdcan now findcd /pathand rungit branch --show-currentin the correct directory.Root cause chain
splitCommandSegments("cd /path && git commit -m ...")-> segments:["cd /path ", " git commit -m ..."]git commitsegment passed tocheckGitextractGitCwd("git commit -m ...")-> no cd found -> undefinedgit branch --show-currentruns in workspace root (no .git) -> nullcheckMergedBranchskips (no branch detected) -> allowedTest plan
cd /path && git commiton merged branch is blocked