From a51cd8e6f6724079a552b75e014f792f3f68e158 Mon Sep 17 00:00:00 2001 From: Russell Belfer Date: Mon, 16 Jan 2012 16:58:27 -0800 Subject: Fix handling of relative paths for attrs Per issue #533, the handling of relative paths in attribute and ignore files was not right. Fixed this by pre-joining the relative path of the attribute/ignore file onto the match string when a full path match is required. Unfortunately, fixing this required a bit more code than I would have liked because I had to juggle things around so that the fnmatch parser would have sufficient information to prepend the relative path when it was needed. --- tests/resources/attr/.gitted/info/attributes | 2 ++ tests/resources/attr/file | 1 + tests/resources/attr/gitignore | 2 ++ tests/resources/attr/ign | 1 + tests/resources/attr/sub/.gitattributes | 7 ++++++ tests/resources/attr/sub/abc | 37 ++++++++++++++++++++++++++++ tests/resources/attr/sub/file | 1 + tests/resources/attr/sub/ign | 1 + tests/resources/attr/sub/sub/file | 1 + tests/resources/attr/sub/sub/subsub.txt | 1 + tests/resources/attr/sub/subdir_test1 | 2 ++ tests/resources/attr/sub/subdir_test2.txt | 1 + tests/resources/attr/subdir/.gitattributes | 5 ---- tests/resources/attr/subdir/abc | 37 ---------------------------- tests/resources/attr/subdir/subdir_test1 | 2 -- tests/resources/attr/subdir/subdir_test2.txt | 1 - tests/resources/attr/subdir2/subdir2_test1 | 1 - 17 files changed, 57 insertions(+), 46 deletions(-) create mode 100644 tests/resources/attr/file create mode 100644 tests/resources/attr/gitignore create mode 100644 tests/resources/attr/ign create mode 100644 tests/resources/attr/sub/.gitattributes create mode 100644 tests/resources/attr/sub/abc create mode 100644 tests/resources/attr/sub/file create mode 100644 tests/resources/attr/sub/ign create mode 100644 tests/resources/attr/sub/sub/file create mode 100644 tests/resources/attr/sub/sub/subsub.txt create mode 100644 tests/resources/attr/sub/subdir_test1 create mode 100644 tests/resources/attr/sub/subdir_test2.txt delete mode 100644 tests/resources/attr/subdir/.gitattributes delete mode 100644 tests/resources/attr/subdir/abc delete mode 100644 tests/resources/attr/subdir/subdir_test1 delete mode 100644 tests/resources/attr/subdir/subdir_test2.txt delete mode 100644 tests/resources/attr/subdir2/subdir2_test1 (limited to 'tests') diff --git a/tests/resources/attr/.gitted/info/attributes b/tests/resources/attr/.gitted/info/attributes index 2e9643a5..5fe62a37 100644 --- a/tests/resources/attr/.gitted/info/attributes +++ b/tests/resources/attr/.gitted/info/attributes @@ -1,2 +1,4 @@ * repoattr a* foo !bar -baz +sub/*.txt reposub +sub/sub/*.txt reposubsub diff --git a/tests/resources/attr/file b/tests/resources/attr/file new file mode 100644 index 00000000..45b983be --- /dev/null +++ b/tests/resources/attr/file @@ -0,0 +1 @@ +hi diff --git a/tests/resources/attr/gitignore b/tests/resources/attr/gitignore new file mode 100644 index 00000000..66f77694 --- /dev/null +++ b/tests/resources/attr/gitignore @@ -0,0 +1,2 @@ +sub +ign diff --git a/tests/resources/attr/ign b/tests/resources/attr/ign new file mode 100644 index 00000000..592fd259 --- /dev/null +++ b/tests/resources/attr/ign @@ -0,0 +1 @@ +ignore me diff --git a/tests/resources/attr/sub/.gitattributes b/tests/resources/attr/sub/.gitattributes new file mode 100644 index 00000000..329c1c5b --- /dev/null +++ b/tests/resources/attr/sub/.gitattributes @@ -0,0 +1,7 @@ +* subattr=yes -negattr +*.txt another=zero +sub/*.txt another=one +ab* merge=filfre +abc -foo -bar +*.c frotz +deep/file deepdeep diff --git a/tests/resources/attr/sub/abc b/tests/resources/attr/sub/abc new file mode 100644 index 00000000..3e42ffc5 --- /dev/null +++ b/tests/resources/attr/sub/abc @@ -0,0 +1,37 @@ +# Test file from gitattributes(5) example: + +If you have these three gitattributes file: + + (in $GIT_DIR/info/attributes) + + a* foo !bar -baz + + (in .gitattributes) + abc foo bar baz + + (in t/.gitattributes) + ab* merge=filfre + abc -foo -bar + *.c frotz + +the attributes given to path t/abc are computed as follows: + +1. By examining t/.gitattributes (which is in the same directory as the path + in question), git finds that the first line matches. merge attribute is + set. It also finds that the second line matches, and attributes foo and + bar are unset. +2. Then it examines .gitattributes (which is in the parent directory), and + finds that the first line matches, but t/.gitattributes file already + decided how merge, foo and bar attributes should be given to this path, + so it leaves foo and bar unset. Attribute baz is set. +3. Finally it examines $GIT_DIR/info/attributes. This file is used to + override the in-tree settings. The first line is a match, and foo is set, + bar is reverted to unspecified state, and baz is unset. + +As the result, the attributes assignment to t/abc becomes: + + foo set to true + bar unspecified + baz set to false + merge set to string value "filfre" + frotz unspecified diff --git a/tests/resources/attr/sub/file b/tests/resources/attr/sub/file new file mode 100644 index 00000000..45b983be --- /dev/null +++ b/tests/resources/attr/sub/file @@ -0,0 +1 @@ +hi diff --git a/tests/resources/attr/sub/ign b/tests/resources/attr/sub/ign new file mode 100644 index 00000000..592fd259 --- /dev/null +++ b/tests/resources/attr/sub/ign @@ -0,0 +1 @@ +ignore me diff --git a/tests/resources/attr/sub/sub/file b/tests/resources/attr/sub/sub/file new file mode 100644 index 00000000..45b983be --- /dev/null +++ b/tests/resources/attr/sub/sub/file @@ -0,0 +1 @@ +hi diff --git a/tests/resources/attr/sub/sub/subsub.txt b/tests/resources/attr/sub/sub/subsub.txt new file mode 100644 index 00000000..9e5bdc47 --- /dev/null +++ b/tests/resources/attr/sub/sub/subsub.txt @@ -0,0 +1 @@ +subsub diff --git a/tests/resources/attr/sub/subdir_test1 b/tests/resources/attr/sub/subdir_test1 new file mode 100644 index 00000000..e563cf47 --- /dev/null +++ b/tests/resources/attr/sub/subdir_test1 @@ -0,0 +1,2 @@ +Hello from the subdir + diff --git a/tests/resources/attr/sub/subdir_test2.txt b/tests/resources/attr/sub/subdir_test2.txt new file mode 100644 index 00000000..fb5067b1 --- /dev/null +++ b/tests/resources/attr/sub/subdir_test2.txt @@ -0,0 +1 @@ +Hello again diff --git a/tests/resources/attr/subdir/.gitattributes b/tests/resources/attr/subdir/.gitattributes deleted file mode 100644 index 99eae476..00000000 --- a/tests/resources/attr/subdir/.gitattributes +++ /dev/null @@ -1,5 +0,0 @@ -* subattr=yes -negattr -subdir/*.txt another=one -ab* merge=filfre -abc -foo -bar -*.c frotz diff --git a/tests/resources/attr/subdir/abc b/tests/resources/attr/subdir/abc deleted file mode 100644 index 3e42ffc5..00000000 --- a/tests/resources/attr/subdir/abc +++ /dev/null @@ -1,37 +0,0 @@ -# Test file from gitattributes(5) example: - -If you have these three gitattributes file: - - (in $GIT_DIR/info/attributes) - - a* foo !bar -baz - - (in .gitattributes) - abc foo bar baz - - (in t/.gitattributes) - ab* merge=filfre - abc -foo -bar - *.c frotz - -the attributes given to path t/abc are computed as follows: - -1. By examining t/.gitattributes (which is in the same directory as the path - in question), git finds that the first line matches. merge attribute is - set. It also finds that the second line matches, and attributes foo and - bar are unset. -2. Then it examines .gitattributes (which is in the parent directory), and - finds that the first line matches, but t/.gitattributes file already - decided how merge, foo and bar attributes should be given to this path, - so it leaves foo and bar unset. Attribute baz is set. -3. Finally it examines $GIT_DIR/info/attributes. This file is used to - override the in-tree settings. The first line is a match, and foo is set, - bar is reverted to unspecified state, and baz is unset. - -As the result, the attributes assignment to t/abc becomes: - - foo set to true - bar unspecified - baz set to false - merge set to string value "filfre" - frotz unspecified diff --git a/tests/resources/attr/subdir/subdir_test1 b/tests/resources/attr/subdir/subdir_test1 deleted file mode 100644 index e563cf47..00000000 --- a/tests/resources/attr/subdir/subdir_test1 +++ /dev/null @@ -1,2 +0,0 @@ -Hello from the subdir - diff --git a/tests/resources/attr/subdir/subdir_test2.txt b/tests/resources/attr/subdir/subdir_test2.txt deleted file mode 100644 index fb5067b1..00000000 --- a/tests/resources/attr/subdir/subdir_test2.txt +++ /dev/null @@ -1 +0,0 @@ -Hello again diff --git a/tests/resources/attr/subdir2/subdir2_test1 b/tests/resources/attr/subdir2/subdir2_test1 deleted file mode 100644 index dccada46..00000000 --- a/tests/resources/attr/subdir2/subdir2_test1 +++ /dev/null @@ -1 +0,0 @@ -Hello from subdir2 -- cgit v1.2.1