Skip to content

Commit 82881b3

Browse files
Matthew Ogilviegitster
authored andcommitted
gitattributes: Fix subdirectory attributes specified from root directory
Signed-off-by: Matthew Ogilvie <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 29df238 commit 82881b3

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

attr.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,9 @@ static int path_matches(const char *pathname, int pathlen,
546546
(baselen && pathname[baselen] != '/') ||
547547
strncmp(pathname, base, baselen))
548548
return 0;
549-
return fnmatch(pattern, pathname + baselen + 1, FNM_PATHNAME) == 0;
549+
if (baselen != 0)
550+
baselen++;
551+
return fnmatch(pattern, pathname + baselen, FNM_PATHNAME) == 0;
550552
}
551553

552554
static int fill_one(const char *what, struct match_attr *a, int rem)

t/t0003-attributes.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ test_expect_success 'setup' '
2121
mkdir -p a/b/d a/c &&
2222
(
2323
echo "f test=f"
24+
echo "a/i test=a/i"
2425
) >.gitattributes &&
2526
(
2627
echo "g test=a/g" &&
@@ -46,4 +47,11 @@ test_expect_success 'attribute test' '
4647
4748
'
4849

50+
test_expect_success 'root subdir attribute test' '
51+
52+
attr_check a/i a/i &&
53+
attr_check subdir/a/i unspecified
54+
55+
'
56+
4957
test_done

0 commit comments

Comments
 (0)