Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A filter that includes .git #38

Open
infinisil opened this issue Jan 19, 2020 · 6 comments
Open

A filter that includes .git #38

infinisil opened this issue Jan 19, 2020 · 6 comments

Comments

@infinisil
Copy link

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

@roberth
Copy link
Member

roberth commented Jan 19, 2020

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.

@infinisil
Copy link
Author

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

@roberth
Copy link
Member

roberth commented Jan 19, 2020

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
Copy link
Member

roberth commented Oct 13, 2021

See NixOS/nixpkgs#112083

@roberth
Copy link
Member

roberth commented Oct 13, 2021

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. NixOS/nixpkgs#112083 takes care of it.

@infinisil
Copy link
Author

infinisil commented Oct 26, 2023

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! 😆 NixOS/nixpkgs#222981

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants