Skip to content

Promote develop to main: Read Git Bash Drive Spellings as Windows Paths in the Primary-Checkout Rule - #2469

Merged
ptr727 merged 2 commits into
mainfrom
develop
Oct 7, 2026
Merged

ptr727 merged 2 commits into
mainfrom
develop

Conversation

@ptr727

@ptr727 ptr727 commented Oct 7, 2026

Copy link
Copy Markdown
Owner

Summary

Promotes #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

…t Rule (#2468)

## 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](https://claude.com/claude-code)


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

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

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
Copilot AI lite review requested due to automatic review settings October 7, 2026 05:40
@coderabbitai

coderabbitai Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration
  • Configuration used: Repository: ptr727/ProjectTemplate/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c76b4020-0bd7-45c0-93ea-8bf11c58f154
  • 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 (c9b2c66).
⚠️ Report is 319 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2469   +/-   ##
=======================================
  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

Exported GIT_WORK_TREE/GIT_DIR path coverage remains incomplete.

Review effort: Lite
Findings: None

What changed in this PR

Updates the agent safety guard to recognize Git Bash /c/... paths as Windows drive paths when enforcing checkout and push safeguards.

Changes:

  • Normalizes Git Bash drive paths on Windows.
  • Applies normalization to command targets, cwd, and push-branch lookup.
  • Expands self-tests and documents the rooted-path limitation.
File Summary
host-setup/​agent-safety/​README.md Documents Git Bash path handling.
host-setup/​agent-safety/​claude/​gh-write-guard.py Implements normalization and expands self-test coverage.

💡 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 9b1326c: the "Needs a closer look" note, "Exported GIT_WORK_TREE/GIT_DIR path coverage remains incomplete." Findings: 0. Real, so it is being fixed in #2470 (commit 3099fa2). That PR adds self-test cases for both export NAME=/c/... && forms. The guard code already converted them, and both cases fail with the conversion removed. This PR's diff picks the fix up once #2470 lands on develop.

…uard Self-Test (#2470)

## Summary

Copilot's overview on the promotion PR
[#2469](#2469) noted that
the exported `GIT_WORK_TREE`/`GIT_DIR` spelling had no self-test case.
#2460 asks for one per spelling. This adds both `export NAME=/c/... &&
git reset --hard` forms to the Git Bash drive block. The guard code is
unchanged, since `_leading_export_dirs` values already pass through
`_expand_dir`.

## Verification

- Both cases pass natively on Windows 11. With `_msys_drive_path`
replaced by identity, both fail.
- `local-strict-review` raised no findings. It also showed that with
`_leading_export_dirs` stubbed out, both cases allow, so it is the
export parse that makes them deny. The same probe under WSL Linux
matched.

Refs #2460

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 5.5 <[email protected]>

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

The safety-critical guard changes warrant final human review despite only a minor documentation nit.

Review effort: Lite
Findings: None

@ptr727

ptr727 commented Oct 7, 2026

Copy link
Copy Markdown
Owner Author

Answering the Copilot overview on c9b2c66: "The safety-critical guard changes warrant final human review despite only a minor documentation nit." Findings: 0, no threads, and the review body names no nit. No change needed. The only documentation candidate the local strict review found is host-setup/agent-safety/README.md rule 6, where the line ending "...without executing something. Fail open" runs to 134 characters inside a paragraph wrapped near 100. That is a wrapping preference. MD013 is disabled, and the Markdown lint checks pass on this head (12/12). The note asking for a final human review is satisfied by the maintainer's merge decision on this promotion PR. The earlier note, on exported GIT_WORK_TREE/GIT_DIR coverage, was fixed in #2470, which this head now carries.

@ptr727
ptr727 merged commit ac50fd1 into main Oct 7, 2026
14 checks passed
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.

Resolve Git Bash Drive-Prefixed Paths in the Primary-Checkout Rule on Windows

2 participants