hercules-ci / gitignore.nix

Nix functions for filtering local git sources
The Unlicense
243 stars 20 forks source link

Ignore empty directories #12

Closed lukateras closed 4 years ago

lukateras commented 5 years ago

It seems that one of the few remaining sources of mismatch between Git ignore logic and hercules-ci/gitignore is empty directory handling: Git will effectively ignore any empty directory, while gitignoreFilter does not.

lukateras commented 5 years ago

I wonder if name: type: !(type == "directory" && builtins.readDir name == {}) would work.

roberth commented 5 years ago

We probably have to ignore directories with all-ignored files, but I haven't confirmed this yet.

lukateras commented 5 years ago

Can confirm:

$ tree
.
└── hello
    └── foo
$ cat .gitignore
/hello/foo
$ git status
On branch master
nothing to commit, working tree clean
kvtb commented 3 years ago

It seems like an imminent flaw of builtins.path which use filter function result for both action: visiting the directory and including directory in the output.

If a directory have to be visited, it will be included into the output. Even if no interesting files are found inside

So "ignore directories with all-ignored files" is the best we can do without resorting to C++ coding

roberth commented 3 years ago

@kvtb nothing stops you from using readDir and "visiting" the files inside, as demonstrated in the PR that resolved this issue, #23. The Nix builtins are designed to be minimal but powerful. Friendlier interfaces can be implemented in Nix itself, as deemed useful by Nixpkgs lib contributors and other library authors.