Skip to content

x: worktree, fix worktreeNameRE, tests#1879

Open
0xDEC0DE wants to merge 1 commit intogo-git:mainfrom
0xDEC0DE:worktree/regex
Open

x: worktree, fix worktreeNameRE, tests#1879
0xDEC0DE wants to merge 1 commit intogo-git:mainfrom
0xDEC0DE:worktree/regex

Conversation

@0xDEC0DE
Copy link
Copy Markdown
Contributor

@0xDEC0DE 0xDEC0DE commented Mar 5, 2026

Update the FuzzAdd test in x/plumbing/worktree/worktree_test.go to capture whether the Add command should throw an error or not, rather than leaving it up to a regex expansion. This can help surface bugs in the regex itself.

Also update the regex to expand what it considers a valid name.

@0xDEC0DE 0xDEC0DE changed the title x/plumbing/worktree: fix worktreeNameRE, tests plumbing: x/worktree, fix worktreeNameRE, tests Mar 5, 2026
@0xDEC0DE 0xDEC0DE changed the title plumbing: x/worktree, fix worktreeNameRE, tests x: worktree, fix worktreeNameRE, tests Mar 5, 2026

var (
worktreeNameRE = regexp.MustCompile(`^[a-zA-Z0-9\-]+$`)
worktreeNameRE = regexp.MustCompile(`^[a-zA-Z0-9._\-]+$`)
Copy link
Copy Markdown
Contributor Author

@0xDEC0DE 0xDEC0DE Mar 5, 2026

Choose a reason for hiding this comment

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

I'm honestly at a loss as to why this guard is here. git worktree add is profoundly forgiving when it comes to the names of worktrees, I'm pretty sure it accepts anything that is allowed in a pathname, i.e., nearly the full Unicode character set is allowed.

But at minimum, accepting all the common characters you're likely to find in a Unix pathname is a better place to be in.

@0xDEC0DE 0xDEC0DE force-pushed the worktree/regex branch 3 times, most recently from 6238fe1 to 3ef85d5 Compare March 6, 2026 04:40
@0xDEC0DE 0xDEC0DE force-pushed the worktree/regex branch 3 times, most recently from 80d4e07 to ba5bc3c Compare March 30, 2026 04:31
Update the FuzzAdd test in x/plumbing/worktree/worktree_test.go to
capture whether the Add command should throw an error or not, rather
than leaving it up to a regex expansion.  This can help surface
bugs in the regex itself.

Also update the regex to expand what it considers a valid name.
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