pathspec: allow escaped query values
In our own .gitattributes file we have attributes such as: *.[ch] whitespace=indent,trail,space When querying for attributes we want to be able to ask for the exact value, i.e. git ls-files :(attr:whitespace=indent,trail,space) should work, but the commas are used in the attr magic to introduce the next attr, such that this query currently fails with fatal: Invalid pathspec magic 'trail' in ':(attr:whitespace=indent,trail,space)' This change allows escaping characters by a backslash, such that the query git ls-files :(attr:whitespace=indent\,trail\,space) will match all path that have the value "indent,trail,space" for the whitespace attribute. To accomplish this, we need to modify two places. First `parse_long_magic` needs to not stop early upon seeing a comma or closing paren that is escaped. As a second step we need to remove any escaping from the attr value. Based on a patch by Stefan Beller <sbeller@google.com> Signed-off-by: Brandon Williams <bmwill@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
b0db704652
commit
c5af19f9ab
@ -178,4 +178,23 @@ test_expect_success 'abort on asking for wrong magic' '
|
||||
test_must_fail git ls-files . ":(attr:!label=foo)"
|
||||
'
|
||||
|
||||
test_expect_success 'check attribute list' '
|
||||
cat <<-EOF >>.gitattributes &&
|
||||
* whitespace=indent,trail,space
|
||||
EOF
|
||||
git ls-files ":(attr:whitespace=indent\,trail\,space)" >actual &&
|
||||
git ls-files >expect &&
|
||||
test_cmp expect actual
|
||||
'
|
||||
|
||||
test_expect_success 'backslash cannot be the last character' '
|
||||
test_must_fail git ls-files ":(attr:label=foo\\ labelA=bar)" 2>actual &&
|
||||
test_i18ngrep "not allowed as last character in attr value" actual
|
||||
'
|
||||
|
||||
test_expect_success 'backslash cannot be used as a value' '
|
||||
test_must_fail git ls-files ":(attr:label=f\\\oo)" 2>actual &&
|
||||
test_i18ngrep "for value matching" actual
|
||||
'
|
||||
|
||||
test_done
|
||||
|
Reference in New Issue
Block a user