Skip to content

Preserve whitespace in Git worktree paths - #199

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

Preserve whitespace in Git worktree paths#199
dipeshbabu wants to merge 1 commit 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

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.

1 participant