1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-05-29 16:46:10 +02:00

Merge branch 'jc/pathspec-match-with-common-prefix'

"git ls-files '(attr:X)D/'" that triggers the common prefix
optimization codepath failed to read from "D/.gitattributes",
which has been corrected.

* jc/pathspec-match-with-common-prefix:
  dir: match "attr" pathspec magic with correct paths
  t6135: attr magic with path pattern
This commit is contained in:
Junio C Hamano 2023-07-17 11:30:42 -07:00
commit 13ed10efd4
2 changed files with 45 additions and 3 deletions

2
dir.c
View File

@ -376,7 +376,7 @@ static int match_pathspec_item(struct index_state *istate,
return 0;
if (item->attr_match_nr &&
!match_pathspec_attrs(istate, name, namelen, item))
!match_pathspec_attrs(istate, name - prefix, namelen + prefix, item))
return 0;
/* If the match was just the prefix, we matched */

View File

@ -65,7 +65,8 @@ test_expect_success 'setup .gitattributes' '
fileValue label=foo
fileWrongLabel label☺
EOF
git add .gitattributes &&
echo fileSetLabel label1 >sub/.gitattributes &&
git add .gitattributes sub/.gitattributes &&
git commit -m "add attributes"
'
@ -78,7 +79,17 @@ test_expect_success 'check specific set attr' '
test_cmp expect actual
'
test_expect_success 'check specific set attr (2)' '
test_expect_success 'check set attr with pathspec pattern' '
echo sub/fileSetLabel >expect &&
git ls-files ":(attr:label)sub" >actual &&
test_cmp expect actual &&
git ls-files ":(attr:label)sub/" >actual &&
test_cmp expect actual
'
test_expect_success 'check specific set attr in tree-ish' '
cat <<-\EOF >expect &&
HEAD:fileSetLabel
HEAD:sub/fileSetLabel
@ -87,6 +98,16 @@ test_expect_success 'check specific set attr (2)' '
test_cmp expect actual
'
test_expect_success 'check specific set attr with pathspec pattern in tree-ish' '
echo HEAD:sub/fileSetLabel >expect &&
git grep -l content HEAD ":(attr:label)sub" >actual &&
test_cmp expect actual &&
git grep -l content HEAD ":(attr:label)sub/" >actual &&
test_cmp expect actual
'
test_expect_success 'check specific unset attr' '
cat <<-\EOF >expect &&
fileUnsetLabel
@ -137,6 +158,7 @@ test_expect_success 'check unspecified attr' '
fileC
fileNoLabel
fileWrongLabel
sub/.gitattributes
sub/fileA
sub/fileAB
sub/fileAC
@ -161,6 +183,7 @@ test_expect_success 'check unspecified attr (2)' '
HEAD:fileC
HEAD:fileNoLabel
HEAD:fileWrongLabel
HEAD:sub/.gitattributes
HEAD:sub/fileA
HEAD:sub/fileAB
HEAD:sub/fileAC
@ -180,6 +203,7 @@ test_expect_success 'check multiple unspecified attr' '
fileC
fileNoLabel
fileWrongLabel
sub/.gitattributes
sub/fileC
sub/fileNoLabel
sub/fileWrongLabel
@ -253,4 +277,22 @@ test_expect_success 'backslash cannot be used as a value' '
test_i18ngrep "for value matching" actual
'
test_expect_success 'reading from .gitattributes in a subdirectory (1)' '
git ls-files ":(attr:label1)" >actual &&
test_write_lines "sub/fileSetLabel" >expect &&
test_cmp expect actual
'
test_expect_success 'reading from .gitattributes in a subdirectory (2)' '
git ls-files ":(attr:label1)sub" >actual &&
test_write_lines "sub/fileSetLabel" >expect &&
test_cmp expect actual
'
test_expect_success 'reading from .gitattributes in a subdirectory (3)' '
git ls-files ":(attr:label1)sub/" >actual &&
test_write_lines "sub/fileSetLabel" >expect &&
test_cmp expect actual
'
test_done