threads / patch / 13218

patchgitattributes: Fix subdirectory attributes specified from root directory

Subject: [PATCH] gitattributes: Fix subdirectory attributes specified from root directory

## tl;dr

One message between Apr 22, 2008 and Apr 22, 2008. Diffs are folded; open one to read it.

replies: 0people: 1as markdown or json

Matthew Ogilvie· Apr 22, 2008, 18:19 UTC · lore
Signed-off-by: Matthew Ogilvie <mmogilvi_git@miniinfo.net>
---

I've been working on adding crlf attribute support for git-cvsserver, and noticed this little issue. I've included some tests and a fix. The cvsserver stuff is still incomplete and not included.

There are a couple of things I'm not sure about, but seem to make the most sense the way I coded it:

1. A test of the form "attr_check /a/i a/i" (notice the prefixed '/'
in the pathname) will "pass" without this patch, but will not
"pass" with this patch.  This seems slightly more correct, but
I'm not sure.
2. The first (non-setup) test in t0003-attributes.sh actually
batches up several checks as one test.  I figured there should be
some limit on how many individual checks get batched into one,
so I started a second test, but I could see an argument to just
include the new checks in the existing batch.
 attr.c                |    4 +++-
 t/t0003-attributes.sh |    8 ++++++++
 2 files changed, 11 insertions(+), 1 deletions(-)
Show changes to 2 files +11 −1

attr.c, t/t0003-attributes.sh

diff --git a/attr.c b/attr.c
index 64b77b1..1a15fad 100644
--- a/attr.c
+++ b/attr.c
@@ -546,7 +546,9 @@ static int path_matches(const char *pathname, int pathlen,
 	    (baselen && pathname[baselen] != '/') ||
 	    strncmp(pathname, base, baselen))
 		return 0;
-	return fnmatch(pattern, pathname + baselen + 1, FNM_PATHNAME) == 0;
+	if (baselen != 0)
+		baselen++;
+	return fnmatch(pattern, pathname + baselen, FNM_PATHNAME) == 0;
 }
 
 static int fill_one(const char *what, struct match_attr *a, int rem)
diff --git a/t/t0003-attributes.sh b/t/t0003-attributes.sh
index 3faf135..c56d2fb 100755
--- a/t/t0003-attributes.sh
+++ b/t/t0003-attributes.sh
@@ -21,6 +21,7 @@ test_expect_success 'setup' '
 	mkdir -p a/b/d a/c &&
 	(
 		echo "f	test=f"
+		echo "a/i test=a/i"
 	) >.gitattributes &&
 	(
 		echo "g test=a/g" &&
@@ -46,4 +47,11 @@ test_expect_success 'attribute test' '
 
 '
 
+test_expect_success 'root subdir attribute test' '
+
+	attr_check a/i a/i &&
+	attr_check subdir/a/i unspecified
+
+'
+
 test_done
-- 
1.5.5.1.57.g5909c

← back to recent threads