gitattributes: fix relative path matching
There was an embarrassing pair of off-by-one miscounting that failed to match path "a/b/c" when "a/.gitattributes" tried to name it with relative path "b/c". This fixes it. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Junio C Hamano committed
Feb 7, 2008 at 00:02 UTC
cf94ccda356cc732a883f16342440330d3f644ec
2 files changed
+52
-3
attr.c
+3
-3
@@ -406,7 +406,7 @@ static void debug_info(const char *what, struct attr_stack *elem)
406
{
407
fprintf(stderr, "%s: %s\n", what, elem->origin ? elem->origin : "()");
408
}
409
-static void debug_set(const char *what, const char *match, struct git_attr *attr, void *v)
409
+static void debug_set(const char *what, const char *match, struct git_attr *attr, const void *v)
410
{
411
const char *value = v;
412
@@ -543,10 +543,10 @@ static int path_matches(const char *pathname, int pathlen,
543
if (*pattern == '/')
544
pattern++;
545
if (pathlen < baselen ||
546
- (baselen && pathname[baselen - 1] != '/') ||
546
+ (baselen && pathname[baselen] != '/') ||
547
strncmp(pathname, base, baselen))
548
return 0;
549
- return fnmatch(pattern, pathname + baselen, FNM_PATHNAME) == 0;
549
+ return fnmatch(pattern, pathname + baselen + 1, FNM_PATHNAME) == 0;
550
}
551
552
static int fill_one(const char *what, struct match_attr *a, int rem)
t/t0003-attributes.sh
new
+49
@@ -0,0 +1,49 @@
1
+#!/bin/sh
2
+
3
+test_description=gitattributes
4
+
5
+. ./test-lib.sh
6
+
7
+attr_check () {
8
+
9
+ path="$1"
10
+ expect="$2"
11
+
12
+ git check-attr test -- "$path" >actual &&
13
+ echo "$path: test: $2" >expect &&
14
+ diff -u expect actual
15
+
16
+}
17
+
18
+
19
+test_expect_success 'setup' '
20
+
21
+ mkdir -p a/b/d a/c &&
22
+ (
23
+ echo "f test=f"
24
+ ) >.gitattributes &&
25
+ (
26
+ echo "g test=a/g" &&
27
+ echo "b/g test=a/b/g"
28
+ ) >a/.gitattributes &&
29
+ (
30
+ echo "h test=a/b/h" &&
31
+ echo "d/* test=a/b/d/*"
32
+ ) >a/b/.gitattributes
33
+
34
+'
35
+
36
+test_expect_success 'attribute test' '
37
+
38
+ attr_check f f &&
39
+ attr_check a/f f &&
40
+ attr_check a/c/f f &&
41
+ attr_check a/g a/g &&
42
+ attr_check a/b/g a/b/g &&
43
+ attr_check b/g unspecified &&
44
+ attr_check a/b/h a/b/h &&
45
+ attr_check a/b/d/g "a/b/d/*"
46
+
47
+'
48
+
49
+test_done