hercules-ci/gitignore.nix

Ignore empty directories

Closed this issue · 5 comments

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.

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

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

Can confirm:

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

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

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