diff options
author | Junio C Hamano <gitster@pobox.com> | 2020-02-12 23:41:35 +0300 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2020-02-12 23:41:35 +0300 |
commit | 341f8a6476d1d25c3906696489d87fc381739b59 (patch) | |
tree | 374572d5f341ca93ceef7129bde941187d763fec | |
parent | b486d2ee811d7471e7a31cd315eddca1be79fc19 (diff) | |
parent | 39e21c6ef5221a1dcb8a241f60d7e91d59bd6627 (diff) |
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
-rw-r--r-- | setup.c | 23 | ||||
-rwxr-xr-x | t/t1506-rev-parse-diagnosis.sh | 14 |
2 files changed, 34 insertions, 3 deletions
@@ -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, ":(")) diff --git a/t/t1506-rev-parse-diagnosis.sh b/t/t1506-rev-parse-diagnosis.sh index 6d951ca015..8a75f37a11 100755 --- a/t/t1506-rev-parse-diagnosis.sh +++ b/t/t1506-rev-parse-diagnosis.sh @@ -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 |