Ignore empty directories

Fixes #12
This commit is contained in:
Robert Hensing 2019-09-17 14:01:17 +02:00
parent ec4a003915
commit 7f3958bb32
2 changed files with 10 additions and 3 deletions

View file

@ -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:

View file

@ -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"