gitignore.nix icon indicating copy to clipboard operation
gitignore.nix copied to clipboard

A filter that includes .git

Open infinisil opened this issue 4 years ago • 6 comments

Since I needed this myself, here is a gitignore filter that includes the .git directory itself (which is often needed for running git commands):

{ lib, gitignoreFilter }: path:
let
  ignoreFilter = gitignoreFilter path;
  dotGit = toString path + "/.git";
in lib.cleanSourceWith {
  src = path;
  filter = path: type: lib.hasPrefix dotGit path || ignoreFilter path type;
}

It might be worth adding a filter with this functionality to this library

infinisil avatar Jan 19 '20 03:01 infinisil

I think we can generalize this to a function that isn't specific to gitignore.nix. Something like unionFilterAndSource: (origSrc -> path -> type -> bool) -> src -> src. It can even memoize your dotGit by let binding the partially applied filter function.

roberth avatar Jan 19 '20 14:01 roberth

I guess combining filters with cleanSourceWith is like an AND statement, whereas this would add OR's, so the boolean logic equivalent is Disjunctive normal form. Maybe this can be a guiding principle in a generalized interface, e.g.

filterDNF [
  [ (only ".git") ]
  [ gitignore (not "foo" ) ]
]

For a filter that includes all of .git unioned with all files that pass both the gitignore and are not in the folder foo (or: .git OR (gitignore AND (NOT "foo")))

infinisil avatar Jan 19 '20 18:01 infinisil

Doesn't have to be normal form though and my thinking was that set terminology is more natural here, because at this level we're thinking about sets of files rather than bools.

roberth avatar Jan 19 '20 18:01 roberth

See https://github.com/NixOS/nixpkgs/pull/112083

roberth avatar Oct 13 '21 19:10 roberth

that set terminology is more natural here, because at this level we're thinking about sets of files rather than bools.

This is a good first intuition but not entirely accurate as illustrated by the example where the union of a and b/c necessarily includes b. This is just a theoretical observation at this point. https://github.com/NixOS/nixpkgs/pull/112083 takes care of it.

roberth avatar Oct 13 '21 19:10 roberth

my thinking was that set terminology is more natural here, because at this level we're thinking about sets of files rather than bools.

Just happen to come across this issue again, and indeed, I now also think of it as sets of files! :laughing: https://github.com/NixOS/nixpkgs/pull/222981

infinisil avatar Oct 26 '23 21:10 infinisil