Skip to content

Read Git Bash Drive Spellings as Windows Paths in the Primary-Checkout Rule - #2468

Merged
ptr727 merged 2 commits into
developfrom
fix/2460-msys-drive-paths
Oct 7, 2026
Merged

ptr727 merged 2 commits into
developfrom
fix/2460-msys-drive-paths

Conversation

@ptr727

@ptr727 ptr727 commented Oct 7, 2026 •

Copy link
Copy Markdown
Owner

Summary

On Windows, the Bash tool runs Git Bash. MSYS converts a /c/repos/x argument to C:/repos/x before git.exe sees it, and git.exe itself 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 cwd in the /c/... form once a Bash cd /c/... has run (both forms appear in the session transcript's cwd field). From then on, even a plain git reset --hard with no redirect at all was allowed in a primary checkout. The same raw cwd also reached _current_push_branch, so a bare git push lost its target under rule 4.

Before and after, measured with the guard's own classify against a real git init primary checkout on Windows 11:

Spelling Before After
Windows cwd, plain command (baseline) deny deny
/c/... cwd, plain command allow deny
git -C /c/... allow deny
git -C C:/... deny deny
cd /c/... && git ... allow deny
--git-dir=/c/... --work-tree=/c/... allow deny
GIT_DIR=/c/... GIT_WORK_TREE=/c/... prefix allow deny
/c/... cwd, relative -C allow deny

Changes

  • _msys_drive_path rewrites a leading /<letter> as <LETTER>:, on Windows only. It is applied in _expand_dir, which every directory value (-C, leading cd, --work-tree, --git-dir, both env forms, export) passes through, and to cwd at classify entry for the origin and push-branch lookups.
  • Self-test cases cover each spelling and the push-branch cwd, with the conversion forced on so Linux CI covers them too. With the conversion removed, those cases fail.
  • The repeated -C fixture /a is renamed /aa. On Windows, /a now reads as drive A:, so that case allowed by failing open rather than by resolving the worktree.
  • The README's rule 6 paragraph states the conversion and its one remaining gap.

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

  • Native Windows 11: gh-write-guard.py --selftest passes. test_install passes, 137 tests with 23 skipped.
  • The before/after table above is from a native run against a real primary checkout.
  • 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

  • Bug Fixes
    • Safety checks now correctly recognize Git Bash-style Windows paths, including paths provided as targets or reported working directories. This helps ensure applicable rules are checked when working from Git Bash.
    • Rooted paths without a drive letter and paths on non-Windows systems retain their existing handling.
  • Documentation
    • Clarified how Windows drive paths are resolved during safety checks.

ptr727 and others added 2 commits October 6, 2026 22:06
…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]>
Copilot AI lite review requested due to automatic review settings October 7, 2026 05:13
@coderabbitai

coderabbitai Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: ptr727/ProjectTemplate/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 4685f882-4aec-47e5-9a70-0028efc06932
📥 Commits

Reviewing files that changed from the base of the PR and between 4d99637 and 4751163.

📒 Files selected for processing (2)
  • host-setup/agent-safety/README.md
  • host-setup/agent-safety/claude/gh-write-guard.py

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

On 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.

Changes

Windows Path Resolution

Layer / File(s) Summary
Convert paths before guard checks
host-setup/agent-safety/claude/gh-write-guard.py, host-setup/agent-safety/README.md
classify and directory resolution convert Git Bash drive paths on Windows. Self-tests cover cwd and target path forms, linked-worktree handling, and bare-push branch lookup. The requirement documents the conversion.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to 47511

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)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: interpreting Git Bash drive paths as Windows paths for the primary-checkout rule.
Docstring Coverage ✅ Passed Docstring coverage is 80.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 1 files. (1 skipped: 1 u…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Oct 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 58.47%. Comparing base (4d99637) to head (4751163).

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           
Flag Coverage Δ
python-3.13 58.47% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@ptr727

ptr727 commented Oct 7, 2026

Copy link
Copy Markdown
Owner Author

Answering the Copilot overview on 4751163 (review round): the "Needs a closer look" note, "Origin resolution with a converted cwd is not yet covered by the self-tests." Findings: 0.

No change needed. The origin lookups do not take a separate path. classify rebinds cwd = _msys_drive_path(cwd) once at entry (gh-write-guard.py:3548). Every consumer after that reads the same local: _check_push_bypass -> _origin_owner_repo(cwd) (:2020), the gh-write gate's _origin_owner_repo(cwd) (:3603), and _push_targets -> _current_push_branch(cwd) (:1960). The new self-test case records the cwd that _current_push_branch receives. With line 3548 deleted, that case fails (got ['/c/repos/primary'], SELFTEST FAIL, exit 1, run natively on Windows 11). An origin-specific case would therefore guard the same line a second time.

@ptr727

ptr727 commented Oct 7, 2026

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@ptr727
ptr727 merged commit 9b1326c into develop Oct 7, 2026
13 checks passed
@ptr727
ptr727 deleted the fix/2460-msys-drive-paths branch October 7, 2026 05:39
ptr727 added a commit that referenced this pull request Oct 7, 2026
…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)
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