Skip to content

git: Allow MkdirAll on worktree-root paths#2115

Merged
pjbgf merged 1 commit into
go-git:mainfrom
hiddeco:worktree-fs-mkdirall-root-noop
May 12, 2026
Merged

git: Allow MkdirAll on worktree-root paths#2115
pjbgf merged 1 commit into
go-git:mainfrom
hiddeco:worktree-fs-mkdirall-root-noop

Conversation

@hiddeco

@hiddeco hiddeco commented May 12, 2026

Copy link
Copy Markdown
Member

The worktree filesystem wrapper rejects "", ".", and "/" in MkdirAll via validPath, even though validReadPath was already relaxed to treat those paths as legitimate references to the worktree root. The asymmetry was deliberate for genuine mutations — mutating the root itself is not a sensible operation for Create or Remove — but MkdirAll on an existing directory is not a mutation: it asks the filesystem to ensure a directory exists, against one that always does.

Short-circuit MkdirAll to a no-op for root-equivalents before validPath runs. validPath itself stays strict, so the other mutating operations continue to reject the root and the existing TestValidPath table is untouched. A new TestWorktreeFilesystemMkdirAllRootIsNoop locks in the no-op contract against the wrapper.

The worktree filesystem wrapper rejects `""`, `"."`, and `"/"` in
`MkdirAll` via `validPath`, even though `validReadPath` was already
relaxed to treat those paths as legitimate references to the worktree
root. The asymmetry was deliberate for genuine mutations — mutating
the root itself is not a sensible operation for `Create` or `Remove`
— but `MkdirAll` on an existing directory is not a mutation: it asks
the filesystem to ensure a directory exists, against one that always
does.

Short-circuit `MkdirAll` to a no-op for root-equivalents before
`validPath` runs. `validPath` itself stays strict, so the other
mutating operations continue to reject the root and the existing
`TestValidPath` table is untouched. A new
`TestWorktreeFilesystemMkdirAllRootIsNoop` locks in the no-op
contract against the wrapper.

Assisted-by: Claude Opus 4.7
Signed-off-by: Hidde Beydals <hidde@hhh.computer>
@hiddeco hiddeco force-pushed the worktree-fs-mkdirall-root-noop branch from 7cc8317 to 6b1eb62 Compare May 12, 2026 14:01

@pjbgf pjbgf left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@hiddeco thanks for working on this. 🙇

@pjbgf pjbgf merged commit 533ba09 into go-git:main May 12, 2026
20 of 21 checks passed
pjbgf pushed a commit that referenced this pull request May 12, 2026
The worktree filesystem wrapper rejects `""`, `"."`, and `"/"` in
`MkdirAll` via `validPath`, even though `validReadPath` was already
relaxed to treat those paths as legitimate references to the worktree
root. The asymmetry was deliberate for genuine mutations — mutating
the root itself is not a sensible operation for `Create` or `Remove`
— but `MkdirAll` on an existing directory is not a mutation: it asks
the filesystem to ensure a directory exists, against one that always
does.

Short-circuit `MkdirAll` to a no-op for root-equivalents before
`validPath` runs. `validPath` itself stays strict, so the other
mutating operations continue to reject the root and the existing
`TestValidPath` table is untouched. A new
`TestWorktreeFilesystemMkdirAllRootIsNoop` locks in the no-op
contract against the wrapper.

Backport of #2115.

Assisted-by: Claude Opus 4.7
Signed-off-by: Hidde Beydals <hidde@hhh.computer>
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.

2 participants