worktree add: sanitize worktree names

Worktree names are based on $(basename $GIT_WORK_TREE). They aren't
significant until 3a3b9d8cde (refs: new ref types to make per-worktree
refs visible to all worktrees - 2018-10-21), where worktree name could
be part of a refname and must follow refname rules.

Update 'worktree add' code to remove special characters to follow
these rules. In the future the user will be able to specify the
worktree name by themselves if they're not happy with this dumb
character substitution.

Reported-by: Konstantin Kharlamov <hi-angel@yandex.ru>
Helped-by: Jeff King <peff@peff.net>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Nguyễn Thái Ngọc Duy
2019-03-08 16:28:34 +07:00
committed by Junio C Hamano
parent 7d0c1f4556
commit 1de16aecf5
4 changed files with 110 additions and 21 deletions

6
refs.h
View File

@ -460,6 +460,12 @@ int for_each_reflog(each_ref_fn fn, void *cb_data);
*/
int check_refname_format(const char *refname, int flags);
/*
* Apply the rules from check_refname_format, but mutate the result until it
* is acceptable, and place the result in "out".
*/
void sanitize_refname_component(const char *refname, struct strbuf *out);
const char *prettify_refname(const char *refname);
char *shorten_unambiguous_ref(const char *refname, int strict);