From 7f3958bb3212bd9f8389ad6ba22a847c56e2ecd8 Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Tue, 17 Sep 2019 14:01:17 +0200 Subject: [PATCH] Ignore empty directories Fixes #12 --- find-files.nix | 9 ++++++--- tests/testdata.nix | 4 ++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/find-files.nix b/find-files.nix index 9336ffa..26dec0d 100644 --- a/find-files.nix +++ b/find-files.nix @@ -6,9 +6,9 @@ in rec { inherit (builtins) dirOf baseNameOf abort split hasAttr readFile readDir; inherit (lib.lists) filter length head tail concatMap take; - inherit (lib.attrsets) filterAttrs mapAttrs; + inherit (lib.attrsets) filterAttrs mapAttrs attrNames; inherit (lib.strings) hasPrefix removePrefix splitString; - inherit (lib) strings flip; + inherit (lib) strings flip any; inherit lib; inherit parse-ini; @@ -25,7 +25,10 @@ rec { path: type: let localDirPath = removePrefix basePathStr (toString (dirOf path)); localDirPathElements = splitString "/" localDirPath; - in parse-gitignore.runFilterPattern (getPatterns patternsBelowP localDirPathElements)."/patterns" path type; + patternResult = parse-gitignore.runFilterPattern (getPatterns patternsBelowP localDirPathElements)."/patterns" path type; + nonempty = any (nodeName: gitignoreFilter (basePath + "/${nodeName}") != false) + (attrNames (builtins.readDir path)); + in patternResult && (type == "directory" -> nonempty); getPatterns = patternTree: pathElems: diff --git a/tests/testdata.nix b/tests/testdata.nix index d26ae7e..9c36ecb 100644 --- a/tests/testdata.nix +++ b/tests/testdata.nix @@ -33,6 +33,10 @@ let touches 10-subdir-ignoring-itself/foo {foo,bar} echo foo >10-subdir-ignoring-itself/foo/.gitignore + + mkdir 12-empty-dir + mkdir 12-not-empty-dir + touch 12-not-empty-dir/just-a-regular-file ); } create-tree "$1"