Skip to content

Commit 13ed10e

Browse files
committed
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
2 parents ce481ac + f4a8fde commit 13ed10e

File tree

2 files changed

+45
-3
lines changed

2 files changed

+45
-3
lines changed

dir.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ static int match_pathspec_item(struct index_state *istate,
376376
return 0;
377377

378378
if (item->attr_match_nr &&
379-
!match_pathspec_attrs(istate, name, namelen, item))
379+
!match_pathspec_attrs(istate, name - prefix, namelen + prefix, item))
380380
return 0;
381381

382382
/* If the match was just the prefix, we matched */

t/t6135-pathspec-with-attrs.sh

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ test_expect_success 'setup .gitattributes' '
6565
fileValue label=foo
6666
fileWrongLabel label☺
6767
EOF
68-
git add .gitattributes &&
68+
echo fileSetLabel label1 >sub/.gitattributes &&
69+
git add .gitattributes sub/.gitattributes &&
6970
git commit -m "add attributes"
7071
'
7172

@@ -78,7 +79,17 @@ test_expect_success 'check specific set attr' '
7879
test_cmp expect actual
7980
'
8081

81-
test_expect_success 'check specific set attr (2)' '
82+
test_expect_success 'check set attr with pathspec pattern' '
83+
echo sub/fileSetLabel >expect &&
84+
85+
git ls-files ":(attr:label)sub" >actual &&
86+
test_cmp expect actual &&
87+
88+
git ls-files ":(attr:label)sub/" >actual &&
89+
test_cmp expect actual
90+
'
91+
92+
test_expect_success 'check specific set attr in tree-ish' '
8293
cat <<-\EOF >expect &&
8394
HEAD:fileSetLabel
8495
HEAD:sub/fileSetLabel
@@ -87,6 +98,16 @@ test_expect_success 'check specific set attr (2)' '
8798
test_cmp expect actual
8899
'
89100

101+
test_expect_success 'check specific set attr with pathspec pattern in tree-ish' '
102+
echo HEAD:sub/fileSetLabel >expect &&
103+
104+
git grep -l content HEAD ":(attr:label)sub" >actual &&
105+
test_cmp expect actual &&
106+
107+
git grep -l content HEAD ":(attr:label)sub/" >actual &&
108+
test_cmp expect actual
109+
'
110+
90111
test_expect_success 'check specific unset attr' '
91112
cat <<-\EOF >expect &&
92113
fileUnsetLabel
@@ -137,6 +158,7 @@ test_expect_success 'check unspecified attr' '
137158
fileC
138159
fileNoLabel
139160
fileWrongLabel
161+
sub/.gitattributes
140162
sub/fileA
141163
sub/fileAB
142164
sub/fileAC
@@ -161,6 +183,7 @@ test_expect_success 'check unspecified attr (2)' '
161183
HEAD:fileC
162184
HEAD:fileNoLabel
163185
HEAD:fileWrongLabel
186+
HEAD:sub/.gitattributes
164187
HEAD:sub/fileA
165188
HEAD:sub/fileAB
166189
HEAD:sub/fileAC
@@ -180,6 +203,7 @@ test_expect_success 'check multiple unspecified attr' '
180203
fileC
181204
fileNoLabel
182205
fileWrongLabel
206+
sub/.gitattributes
183207
sub/fileC
184208
sub/fileNoLabel
185209
sub/fileWrongLabel
@@ -253,4 +277,22 @@ test_expect_success 'backslash cannot be used as a value' '
253277
test_i18ngrep "for value matching" actual
254278
'
255279

280+
test_expect_success 'reading from .gitattributes in a subdirectory (1)' '
281+
git ls-files ":(attr:label1)" >actual &&
282+
test_write_lines "sub/fileSetLabel" >expect &&
283+
test_cmp expect actual
284+
'
285+
286+
test_expect_success 'reading from .gitattributes in a subdirectory (2)' '
287+
git ls-files ":(attr:label1)sub" >actual &&
288+
test_write_lines "sub/fileSetLabel" >expect &&
289+
test_cmp expect actual
290+
'
291+
292+
test_expect_success 'reading from .gitattributes in a subdirectory (3)' '
293+
git ls-files ":(attr:label1)sub/" >actual &&
294+
test_write_lines "sub/fileSetLabel" >expect &&
295+
test_cmp expect actual
296+
'
297+
256298
test_done

0 commit comments

Comments
 (0)