git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
MOMatthew Ogilvie <mmogilvi_git@miniinfo.net>
Date
Apr 22, 2008, 18:19 UTC
Message-ID
<1208888352-7519-1-git-send-email-mmogilvi_git@miniinfo.net>
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(-)
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
Message 1 of 1 in “gitattributes: Fix subdirectory attributes specified from root directory”
  1. gitattributes: Fix subdirectory attributes specified from root directoryMatthew Ogilvie, Apr 22, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.