specs/066-worktree-newline-registration/spec.md
Specification: Newline-safe worktree registration
Created: 2026-10-15 Status: Clarified Input: Continue finding repository bugs, publish confirmed fixes and merge after checks.
User story
Task cleanup may delete a leftover directory only after Git says that path is not a registered worktree. A registered checkout whose path contains a newline must still count as registered, so a failed git worktree remove cannot be followed by remove_dir_all.
Requirements
- FR-001:
is_worktree_registeredreports a checkout registered whengit worktree list --porcelain -zlists that path, including when the path contains a newline or when a UTF-8 symlink's canonical bytes are not UTF-8. - FR-002: A path Git does not list stays unregistered. When Git itself fails, the path stays registered (fail closed).
- FR-003: The comparison still accepts the caller's path or its canonical form. No IPC, persisted data, or cleanup policy change.
Acceptance scenarios
- A worktree added at an absolute path containing a newline is registered.
- The existing guard still reports a normal path unregistered before add, registered after add, and unregistered after remove.
- A failed Git listing does not become "not registered".
- A UTF-8 symlink whose canonical worktree path is not UTF-8 stays registered.
Success criteria
The server unit test creates a real Git worktree whose path contains a newline and requires is_worktree_registered to return true. Existing registration tests pass. Full repository verification passes.
Clarification
No user questions are required. The leftover-directory guard already refuses to delete a checkout Git still claims. The defect is the line-oriented parser hiding that claim. Sharing one porcelain parser with worktree listing is a later cleanup, not this correction.