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:
commit
341f8a6476
23
setup.c
23
setup.c
@ -197,9 +197,26 @@ static void NORETURN die_verify_filename(struct repository *r,
|
|||||||
*/
|
*/
|
||||||
static int looks_like_pathspec(const char *arg)
|
static int looks_like_pathspec(const char *arg)
|
||||||
{
|
{
|
||||||
/* anything with a wildcard character */
|
const char *p;
|
||||||
if (!no_wildcard(arg))
|
int escaped = 0;
|
||||||
return 1;
|
|
||||||
|
/*
|
||||||
|
* 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 */
|
/* long-form pathspec magic */
|
||||||
if (starts_with(arg, ":("))
|
if (starts_with(arg, ":("))
|
||||||
|
@ -222,4 +222,18 @@ test_expect_success 'reject Nth ancestor if N is too high' '
|
|||||||
test_must_fail git rev-parse HEAD~100000000000000000000000000000000
|
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
|
test_done
|
||||||
|
Loading…
Reference in New Issue
Block a user