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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Matthew Ogilvie <mmogilvi_git@xxxxxxxxxxxx>
---

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

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux