Repository navigation
Read Git Bash Drive Spellings as Windows Paths in the Primary-Checkout Rule - #2468
Conversation
…t Rule On Windows, Git Bash hands git.exe `/c/repos/x` as `C:/repos/x`, and Claude Code reports the hook's cwd as `/c/...` once a Bash `cd /c/...` has run. The guard read both raw, joined them to a directory holding no repository, and rule 6 failed open. Reproduced natively on Windows 11 for -C, a leading cd, --work-tree, --git-dir, both env prefixes, and a plain command run from a `/c/...` cwd. Convert a leading `/<letter>` to `<LETTER>:` on Windows, in the one helper every directory value passes through and at classify's entry for the origin and push-branch lookups. The self-test forces the conversion on so every host covers each spelling. Fixes #2460 Co-Authored-By: Claude Opus 5.5 <[email protected]>
The classify-entry cwd conversion had no case of its own, since every rule 6 case reaches the conversion through `_expand_dir` too. A bare push now records the directory its branch lookup runs in. The repeated -C case named `/a`, which Windows now reads as drive `A:`, so the case allowed by failing open rather than by resolving the worktree. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configuration
📒 Files selected for processing (2)
Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review. 📝 WalkthroughWalkthroughOn Windows, the guard converts Git Bash drive paths in working directories and resolved Git target directories before rule checks. The requirement and self-tests describe and cover the conversion. ChangesWindows Path Resolution
Priority: ⬇️ Low Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: ⚪ Minimal · up to The guard now reads Git Bash drive paths such as /c/... as Windows paths, so the primary-checkout rule no longer fails open for them. No merge-blocking concerns remain. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #2468 +/- ##
========================================
Coverage 58.47% 58.47%
========================================
Files 16 16
Lines 8062 8062
========================================
Hits 4714 4714
Misses 3348 3348
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Copilot review overview
🔵 Needs a closer look
Origin resolution with a converted cwd is not yet covered by the self-tests.
Review effort: Lite
Findings: None
What changed in this PR
This PR normalizes Git Bash /c/... paths on Windows so the primary-checkout guard resolves working directories and Git arguments correctly.
Changes:
- Converts drive-prefixed Git Bash paths on Windows.
- Expands self-tests for
cwd, Git options, environment variables, and push resolution. - Documents the conversion and remaining rooted-path limitation.
| File | Summary | Findings |
|---|---|---|
host-setup/agent-safety/README.md |
Documents Git Bash path handling. | None. |
host-setup/agent-safety/claude/gh-write-guard.py |
Implements path normalization and expanded self-tests. | P2/moderate (1 vote): add coverage for origin resolution with converted cwd. Two nits (1 vote each): simplify the docstring and fix its grammar. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
Answering the Copilot overview on 4751163 (review round): the "Needs a closer look" note, "Origin resolution with a converted No change needed. The origin lookups do not take a separate path. |
|
@coderabbitai review |
✅ Action performedReview finished.
|
…hs in the Primary-Checkout Rule (#2469) ## Summary Promotes [#2468](#2468) to `main`. On Windows, Git Bash hands `git.exe` a `/c/repos/x` argument as `C:/repos/x`, and Claude Code reports the hook's `cwd` as `/c/...` once a Bash `cd /c/...` has run. The guard read both raw, so rule 6 failed open for `-C`, a leading `cd`, `--work-tree`, `--git-dir`, both env prefixes, and even a plain `git reset --hard` run from a `/c/...` cwd. The same raw `cwd` also cost a bare `git push` its branch under rule 4. The guard now reads a leading `/<letter>` as `<LETTER>:` on Windows. A rooted path with no drive segment stays unconverted, as the README states. A native Windows 11 reproduction against a real primary checkout showed every one of those spellings allowed before the change and denied after it. The guard self-test and `test_install` (137 tests, 23 skipped) pass natively on Windows. Closes #2460 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Summary
On Windows, the Bash tool runs Git Bash. MSYS converts a
/c/repos/xargument toC:/repos/xbeforegit.exesees it, andgit.exeitself refuses the unconverted spelling (fatal: cannot change to '/c/...'). The guard read the raw spelling, joined it to a directory holding no repository, and rule 6 failed open.A native reproduction on Windows 11 confirmed the gap and found a wider one than #2460 described. Claude Code reports the hook's
cwdin the/c/...form once a Bashcd /c/...has run (both forms appear in the session transcript'scwdfield). From then on, even a plaingit reset --hardwith no redirect at all was allowed in a primary checkout. The same rawcwdalso reached_current_push_branch, so a baregit pushlost its target under rule 4.Before and after, measured with the guard's own
classifyagainst a realgit initprimary checkout on Windows 11:cwd, plain command (baseline)/c/...cwd, plain commandgit -C /c/...git -C C:/...cd /c/... && git ...--git-dir=/c/... --work-tree=/c/...GIT_DIR=/c/... GIT_WORK_TREE=/c/...prefix/c/...cwd, relative-CChanges
_msys_drive_pathrewrites a leading/<letter>as<LETTER>:, on Windows only. It is applied in_expand_dir, which every directory value (-C, leadingcd,--work-tree,--git-dir, both env forms,export) passes through, and tocwdatclassifyentry for the origin and push-branch lookups.cwd, with the conversion forced on so Linux CI covers them too. With the conversion removed, those cases fail.-Cfixture/ais renamed/aa. On Windows,/anow reads as driveA:, so that case allowed by failing open rather than by resolving the worktree.A rooted path with no drive segment, such as
/tmp/x, is still read unconverted. MSYS maps it under the Git install root, and the hook cannot see that root without executing something.Verification
gh-write-guard.py --selftestpasses.test_installpasses, 137 tests with 23 skipped.local-strict-review: two rounds. Round 1 raised 2 test-coverage findings, both fixed in the second commit.Refs #2460, closed by the promotion PR.
🤖 Generated with Claude Code
Summary by CodeRabbit