summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--attr.c3
-rwxr-xr-xt/t0003-attributes.sh10
2 files changed, 12 insertions, 1 deletions
diff --git a/attr.c b/attr.c
index f6b3f7e850..924b4408d5 100644
--- a/attr.c
+++ b/attr.c
@@ -573,7 +573,8 @@ static void prepare_attr_stack(const char *path, int dirlen)
elem = attr_stack;
if (namelen <= dirlen &&
- !strncmp(elem->origin, path, namelen))
+ !strncmp(elem->origin, path, namelen) &&
+ (!namelen || path[namelen] == '/'))
break;
debug_pop(elem);
diff --git a/t/t0003-attributes.sh b/t/t0003-attributes.sh
index ebbc7554a7..61b5a2eba6 100755
--- a/t/t0003-attributes.sh
+++ b/t/t0003-attributes.sh
@@ -60,6 +60,16 @@ test_expect_success 'attribute test' '
'
+test_expect_success 'prefixes are not confused with leading directories' '
+ attr_check a_plus/g unspecified &&
+ cat >expect <<-\EOF &&
+ a/g: test: a/g
+ a_plus/g: test: unspecified
+ EOF
+ git check-attr test a/g a_plus/g >actual &&
+ test_cmp expect actual
+'
+
test_expect_success 'core.attributesfile' '
attr_check global unspecified &&
git config core.attributesfile "$HOME/global-gitattributes" &&