Repository navigation
Conversation
…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]>
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configuration
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 @@
## main #2469 +/- ##
=======================================
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
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.
|
Answering the Copilot overview on 9b1326c: the "Needs a closer look" note, "Exported |
…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]>
|
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 |
Summary
Promotes #2468 to
main. On Windows, Git Bash handsgit.exea/c/repos/xargument asC:/repos/x, and Claude Code reports the hook'scwdas/c/...once a Bashcd /c/...has run. The guard read both raw, so rule 6 failed open for-C, a leadingcd,--work-tree,--git-dir, both env prefixes, and even a plaingit reset --hardrun from a/c/...cwd. The same rawcwdalso cost a baregit pushits 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