Skip to content

fix(git): preserve whitespace in worktree paths - #199

Open
dipeshbabu wants to merge 2 commits into
openai:mainfrom
dipeshbabu:agent/preserve-git-worktree-whitespace
Open

fix(git): preserve whitespace in worktree paths#199
dipeshbabu wants to merge 2 commits into
openai:mainfrom
dipeshbabu:agent/preserve-git-worktree-whitespace

Conversation

@dipeshbabu

Copy link
Copy Markdown
Contributor

Summary

  • preserve legitimate trailing whitespace in Git worktree paths
  • remove only Git's final line terminator from command output instead of trimming the entire value
  • add regression coverage for a POSIX worktree whose directory name ends in a space

Root cause

The shared Git output helper called stdout.trim(). For git rev-parse --show-toplevel, that also removes whitespace belonging to the path itself. A valid POSIX worktree such as /workspace/repository was 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 skip
  • pnpm exec tsc --noEmit
  • pnpm exec prettier --check src/targets.ts tests-ts/targets.test.ts
  • git diff --cached --check

@mldangelo-oai mldangelo-oai added the bug Something isn't working label Aug 3, 2026
@mldangelo-oai mldangelo-oai changed the title Preserve whitespace in Git worktree paths fix(git): preserve whitespace in worktree paths Aug 3, 2026
@mldangelo-oai

Copy link
Copy Markdown
Collaborator

@codex review Please review exact head 175a596, focusing on trailing whitespace in Git worktree paths, trimming only command-output newlines, ref validation, and cross-platform behavior.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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, "");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

@chatgpt-codex-connector

Copy link
Copy Markdown

Security review completed. No security issues were found in this pull request.

Reviewed commit: 175a5967a9

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants