Merge branch 'jk/escaped-wildcard-dwim'

Disambiguation logic to tell revisions and pathspec apart has been
tweaked so that backslash-escaped glob special characters do not
count in the "wildcards are pathspec" rule.

* jk/escaped-wildcard-dwim:
  verify_filename(): handle backslashes in "wildcards are pathspecs" rule
This commit is contained in:
Junio C Hamano 2020-02-12 12:41:35 -08:00
commit 341f8a6476
2 changed files with 34 additions and 3 deletions

23
setup.c
View File

@ -197,9 +197,26 @@ static void NORETURN die_verify_filename(struct repository *r,
*/
static int looks_like_pathspec(const char *arg)
{
/* anything with a wildcard character */
if (!no_wildcard(arg))
return 1;
const char *p;
int escaped = 0;
/*
* Wildcard characters imply the user is looking to match pathspecs
* that aren't in the filesystem. Note that this doesn't include
* backslash even though it's a glob special; by itself it doesn't
* cause any increase in the match. Likewise ignore backslash-escaped
* wildcard characters.
*/
for (p = arg; *p; p++) {
if (escaped) {
escaped = 0;
} else if (is_glob_special(*p)) {
if (*p == '\\')
escaped = 1;
else
return 1;
}
}
/* long-form pathspec magic */
if (starts_with(arg, ":("))

View File

@ -222,4 +222,18 @@ test_expect_success 'reject Nth ancestor if N is too high' '
test_must_fail git rev-parse HEAD~100000000000000000000000000000000
'
test_expect_success 'pathspecs with wildcards are not ambiguous' '
echo "*.c" >expect &&
git rev-parse "*.c" >actual &&
test_cmp expect actual
'
test_expect_success 'backslash does not trigger wildcard rule' '
test_must_fail git rev-parse "foo\\bar"
'
test_expect_success 'escaped char does not trigger wildcard rule' '
test_must_fail git rev-parse "foo\\*bar"
'
test_done