From 484cd263a245963dcb5aa767de6c39f4f580b145 Mon Sep 17 00:00:00 2001 From: Douglas Wilson Date: Fri, 6 Sep 2019 07:48:03 +0100 Subject: [PATCH 1/3] Add a failing test for a subdir ignoring itself The .gitignore in foo causes foo itself to be ignored --- tests/default.nix | 1 + tests/testdata.nix | 3 +++ 2 files changed, 4 insertions(+) diff --git a/tests/default.nix b/tests/default.nix index d8a9ebd..4eef480 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -20,5 +20,6 @@ in subdir-3 = runner.makeTest { name = "subdir-3"; rootDir = testdata.sourceUnfiltered + "/test-tree"; subpath = "3-wildcards"; }; subdir-4 = runner.makeTest { name = "subdir-4"; rootDir = testdata.sourceUnfiltered + "/test-tree"; subpath = "4-escapes"; }; subdir-9 = runner.makeTest { name = "subdir-9"; rootDir = testdata.sourceUnfiltered + "/test-tree"; subpath = "9-expected"; }; + subdir-10 = runner.makeTest { name = "subdir-10"; rootDir = testdata.sourceUnfiltered + "/test-tree"; subpath = "10-subdir-ignoring-itself"; }; } \ No newline at end of file diff --git a/tests/testdata.nix b/tests/testdata.nix index ac7c134..d26ae7e 100644 --- a/tests/testdata.nix +++ b/tests/testdata.nix @@ -30,6 +30,9 @@ let touches 5-directory {1,2,3,4,5,^,$,^$,$^,[,[[,],]],]]],ab,bb,\\,\\\\} touches 9-expected {unfiltered,filtered-via-aux-{filter,ignore,filepath}} + + touches 10-subdir-ignoring-itself/foo {foo,bar} + echo foo >10-subdir-ignoring-itself/foo/.gitignore ); } create-tree "$1" From f8d5bdfe76663007fcfd58c7c2de23fc534032e2 Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Fri, 6 Sep 2019 12:30:48 +0200 Subject: [PATCH 2/3] Refactor Extract getPatterns variable in gitignoreFilter to top-level --- find-files.nix | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/find-files.nix b/find-files.nix index 6c464fa..6860d42 100644 --- a/find-files.nix +++ b/find-files.nix @@ -26,19 +26,24 @@ rec { path: type: let localPath = removePrefix basePathStr (toString path); localPathElements = splitString "/" localPath; - getPatterns = patternTree: pathElems: - if length pathElems == 0 - then patternTree - else let hd = head pathElems; in - if hd == "" || hd == "." - then getPatterns patternTree (tail pathElems) - else if hasAttr hd patternTree - then getPatterns patternTree."${hd}" (tail pathElems) - else patternTree # Files are not in the tree, so we return the - # most patterns we could find here. - ; in parse-gitignore.runFilterPattern' (getPatterns patternsBelowP localPathElements)."/patterns" path type; + getPatterns = + patternTree: pathElems: + if length pathElems == 0 + then patternTree + else let hd = head pathElems; in + if hd == "" || hd == "." + then getPatterns patternTree (tail pathElems) + else + if hasAttr hd patternTree + then getPatterns patternTree."${hd}" (tail pathElems) + else + # Files are not in the tree, so we return the + # most patterns we could find here. + patternTree; + + ##### # Constructing a tree of patterns per non-ignored subdirectory, recursively # From cc23ac9d191a5fdb7958f1cf1da6c7d2fe944eef Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Fri, 6 Sep 2019 12:35:11 +0200 Subject: [PATCH 3/3] gitignoreFilter: don't use $path/.gitignore, only $path/../.gitignore --- find-files.nix | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/find-files.nix b/find-files.nix index 6860d42..191a0b6 100644 --- a/find-files.nix +++ b/find-files.nix @@ -24,9 +24,9 @@ rec { basePathStr = toString basePath; in path: type: let - localPath = removePrefix basePathStr (toString path); - localPathElements = splitString "/" localPath; - in parse-gitignore.runFilterPattern' (getPatterns patternsBelowP localPathElements)."/patterns" path type; + localDirPath = removePrefix basePathStr (toString (dirOf path)); + localDirPathElements = splitString "/" localDirPath; + in parse-gitignore.runFilterPattern' (getPatterns patternsBelowP localDirPathElements)."/patterns" path type; getPatterns = patternTree: pathElems: