fix(git): preserve whitespace in worktree paths - #199
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 175a5967a9
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| }, | ||
| ); | ||
| return stdout.trim(); | ||
| return stdout.replace(/\r?\n$/u, ""); |
There was a problem hiding this comment.
Preserve POSIX paths ending in carriage returns
When a POSIX worktree name ends in \r, Git emits that path followed by its \n record terminator, so this pattern interprets the path's carriage return plus Git's newline as a CRLF terminator and removes both. enclosingGitWorktreeRoot() then resolves the wrong path and returns null, while diff-target validation fails; strip only \n on POSIX and handle actual CRLF output platform-specifically.
Useful? React with 👍 / 👎.
|
Security review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
Summary
Root cause
The shared Git output helper called
stdout.trim(). Forgit rev-parse --show-toplevel, that also removes whitespace belonging to the path itself. A valid POSIX worktree such as/workspace/repositorywas therefore resolved as/workspace/repository, causing worktree-root discovery and diff-target validation to fail.Impact
Git-backed scans now preserve valid worktree path whitespace while continuing to remove the CRLF or LF record terminator emitted by Git. Commit and ref resolution behavior is unchanged.
Overlap check
Open issues and pull requests were searched for Git worktree whitespace, trailing-space paths, and the affected output handling. No active issue or pull request covers this bug. PR #143 also touches
targets.ts, but only the separate home-directory expansion helper; its hunk and behavior do not overlap this change. Issue #192 concerns non-ASCII subprocess decoding rather than whitespace removal.Validation
pnpm dlx bun test --timeout 30000 ./tests-ts/targets.test.ts— 13 passed, 1 Windows-only skippnpm exec tsc --noEmitpnpm exec prettier --check src/targets.ts tests-ts/targets.test.tsgit diff --cached --check