v5 is basically Jeff's version from one of the replies in v4, where check_refname_component is enhanced to optionally sanitize. I was reluctant to go this way because it makes check_refname_component more complex (turns out still manageable) and burns worktree rules in it. But there may never be the second sanitization user, we deal with it when it comes. As said, refs.c is pretty much Jeff's except two major changes: - handle foo.lock.lock correctly by stripping .lock repeatedly - sanitize refname _components_ instead of full refs. I could construct worktrees/<name> and pass to Jeff's sanitize_refname. But then I need to strip worktrees/ after that. I took credits so that bugs come to me first (then I'll blame him anyway while doing some evil laughs) Nguyễn Thái Ngọc Duy (1): worktree add: sanitize worktree names builtin/worktree.c | 10 +++- refs.c | 103 ++++++++++++++++++++++++++++++++-------- refs.h | 6 +++ t/t2400-worktree-add.sh | 5 ++ 4 files changed, 104 insertions(+), 20 deletions(-) -- 2.21.0.rc1.337.gdf7f8d0522