-
-
Notifications
You must be signed in to change notification settings - Fork 14.4k
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
lib.fileset.gitTracked
: init
#264891
lib.fileset.gitTracked
: init
#264891
Conversation
61d564a
to
12d8a38
Compare
Please rename it to, say, |
While this adds means to strengthen build purity, which user demand is driving this change? |
@fricklerhandwerk Pretty much every Git-based project using stable Nix can benefit from this function, since it provides a good base set of files to further customise. Even manually it's not practically possible to do this without this function, because you'd have to list each file tracked in Git individually in a Comparatively, this is already possible with There is a possibility of having a # Equivalent to the proposed lib.fileset.gitTracked ./.
lib.fileset.unions (lib.git.lsTrackedFiles ./.) But:
I'd prefer just having |
The fact that it can be done with existing library functions, especially as trivially as you're showing, and especially given you're already working on |
@fricklerhandwerk No it cannot be done with existing functions (unless you pretty much copy what I did in this PR). I really think something like this PR is required for an enjoyable experience with the file set library. Nobody (me included) wants to have to manually filter out files not tracked by Git. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not pretty, the way it is, or where it is, but it's useful. One request; otherwise lgtm.
Perhaps also relevant is a helper that only applies this when there's a |
Am I nobody to you? ;) EDIT: actually it's not possible, because tracked and non-ignored are different sets, where tracked requires reading the staging area, which I don't think is feasible. |
This could be done with if builtins.pathExists ./.git then
gitTracked ./.
else
./. But yeah having a convenience function for this might be nice. Better in a separate PR though :)
Hehe yeah, I wonder if we should have a combination of the two though, something like "all files that would be tracked if you ran git add -A". Probably that would be let
tracked = gitTracked ./.;
ignored = gitIgnored ./.;
in
union tracked
(intersection
(difference ./. tracked)
(difference ./. ignored)
) (and probably some nice set identity could be used to make this smaller). But that's also for another PR :) |
lib/fileset/default.nix
Outdated
*/ | ||
gitTracked = | ||
/* | ||
The [path](https://nixos.org/manual/nix/stable/language/values#type-path) to a local working directory of the Git repository whose tracked files to include. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The [path](https://nixos.org/manual/nix/stable/language/values#type-path) to a local working directory of the Git repository whose tracked files to include. | |
The [path](https://nixos.org/manual/nix/stable/language/values#type-path) to a local Git repository. |
- Remove "working directory" because that's less unambiguously the root of the repo.
- Don't state too much of the obvious.
Not sure where to document the return value, but I'll make another suggestion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do think for correctness we should use working directory, because there's also bare repositories without a working directory, see https://git-scm.com/docs/gitrepository-layout#_description.
I do agree to remove the "whose tracked files to include" though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The [path](https://nixos.org/manual/nix/stable/language/values#type-path) to a local working directory of the Git repository whose tracked files to include. | |
The [path](https://nixos.org/manual/nix/stable/language/values#type-path) to a local working directory of the Git repository. | |
This directory must contain a `.git` file or subdirectory. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The [path](https://nixos.org/manual/nix/stable/language/values#type-path) to a local working directory of the Git repository whose tracked files to include. | |
The [path](https://nixos.org/manual/nix/stable/language/values#type-path) to the working directory of a local Git repository. | |
This directory must contain a `.git` file or subdirectory. |
- Switch "the" and "a" around, so we don't suggest there's any choice of directories within a repo. (Technically it may have worktrees but that's not even of secondary importance, and can be fully explained by a small vagueness on our end when it comes to the definition of repository.)
If that's not ok, consider
The [path](https://nixos.org/manual/nix/stable/language/values#type-path) to a local working directory of the Git repository whose tracked files to include. | |
The [path](https://nixos.org/manual/nix/stable/language/values#type-path) to a local non-bare Git repository. | |
This directory must contain a `.git` file or subdirectory. |
or if you don't mind an association with the worktree feature, we can be really brief:
The [path](https://nixos.org/manual/nix/stable/language/values#type-path) to a local working directory of the Git repository whose tracked files to include. | |
The [path](https://nixos.org/manual/nix/stable/language/values#type-path) to a local Git worktree with a valid `.git` file or directory. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the first suggestion, will apply.
lib/fileset/default.nix
Outdated
@@ -510,4 +516,107 @@ If a directory does not recursively contain any file, it is omitted from the sto | |||
# We could also return the original fileset argument here, | |||
# but that would then duplicate work for consumers of the fileset, because then they have to coerce it again | |||
actualFileset; | |||
|
|||
/* | |||
Like [`gitTrackedWith`](#function-library-lib.fileset.gitTrackedWith) with `{}` as the first argument, therefore using the defaults. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like [`gitTrackedWith`](#function-library-lib.fileset.gitTrackedWith) with `{}` as the first argument, therefore using the defaults. | |
A fileset with all files from a repository; typically passed to [`intersect`](#function-library-lib.fileset.intersect). | |
This function behaves like [`gitTrackedWith { }`](#function-library-lib.fileset.gitTrackedWith) - using the defaults. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like [`gitTrackedWith`](#function-library-lib.fileset.gitTrackedWith) with `{}` as the first argument, therefore using the defaults. | |
Create a file set containing all [Git-tracked files](https://git-scm.com/book/en/v2/Git-Basics-Recording-Changes-to-the-Repository) in a repository. | |
This function behaves like [`gitTrackedWith { }`](#function-library-lib.fileset.gitTrackedWith) - using the defaults. |
f034955
to
a87f43e
Compare
A configuration parameter for gitTrackedWith will be introduced in the next commit
Force push to apply the suggestions: (diff) Now rebasing on top of master, I think this is ready. |
a87f43e
to
bd13e36
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM after
lib/fileset/default.nix
Outdated
fetchResult = builtins.fetchGit path; | ||
in | ||
if inPureEvalMode then | ||
throw "lib.fileset.gitTracked: This function is currently not supported in pure evaluation mode, since it currently relies on `builtins.fetchGit`, see https://github.com/NixOS/nix/issues/9292." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
throw "lib.fileset.gitTracked: This function is currently not supported in pure evaluation mode, since it currently relies on `builtins.fetchGit`, see https://github.com/NixOS/nix/issues/9292." | |
throw "lib.fileset.gitTracked: This function is currently not supported in pure evaluation mode, since it currently relies on `builtins.fetchGit`. See https://github.com/NixOS/nix/issues/9292." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test needs it too :/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haha right, it's annoying but I'd be very much screwed without these tests
Pushed
bd13e36
to
948534a
Compare
948534a
to
ada680b
Compare
Description of changes
This adds two new functions to
lib.fileset
:lib.fileset.gitTracked :: Path -> FileSet
: Create a file set containing all Git-tracked files in the working tree of a local Git repository.lib.fileset.gitTrackedWith :: { recurseSubmodules :: Bool ? false } -> Path -> FileSet
: Same, but optionally also recurse into submodules.These functions are useful since it's very common to only want to include files tracked by Git. So much so that Flakes does it by default.
Combined with the fact that Flakes currently always copies all files to the Nix store, these functions are somewhat useless with Flakes:
git+file:
input, Flakes will have already implicitly filtered out all files not tracked by Git, including.git
, so this function can't even be called on the local directory then.path:.
input instead of implicitly letting Flakes treat it as a Git directory, it will import all files into the Nix store, which is exactly what this library is trying to let you control.builtins.fetchGit
dirty mode almost unusable in pure evaluation mode nix#9292But for stable Nix, these functions are a requirement, since it's not otherwise possible to create a file set from just Git-tracked files (
builtins.fetchGit
returns a store path, which doesn't work with file sets).This work is sponsored by Antithesis ✨
Things done