Skip to content

Commit 500ec11

Browse files
committed
worktree: reject empty string
`git worktree add ""` errors out with the message `BUG: How come '' becomes empty after sanitization?`, but not due to a bug in the sanitization code. An empty string should remain empty during sanitization. Instead reject the argument as invalid user input, if it's already empty before sanitization. Signed-off-by: Matthias Aßhauer <mha1993@live.de>
1 parent 6d24f9a commit 500ec11

1 file changed

Lines changed: 2 additions & 0 deletions

File tree

builtin/worktree.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,8 @@ static int add_worktree(const char *path, const char *refname,
496496
die(_("invalid reference: %s"), refname);
497497

498498
name = worktree_basename(path, &len);
499+
if (!len)
500+
die(_("the empty string is not a valid worktree"));
499501
strbuf_add(&sb, name, path + len - name);
500502
sanitize_refname_component(sb.buf, &sb_name);
501503
if (!sb_name.len)

0 commit comments

Comments
 (0)