query
On this page

gitTrackedWith

lib.fileset.gitTrackedWith

Docs pulled from | This Revision | 10 minutes ago


Create a file set containing all Git-tracked files in a repository. The first argument allows configuration with an attribute set, while the second argument is the path to the Git working tree.

gitTrackedWith does not perform any filtering when the path is a Nix store path and not a repository. In this way, it accommodates the use case where the expression that makes the gitTracked call does not reside in an actual git repository anymore, and has presumably already been fetched in a way that excludes untracked files. Fetchers with such equivalent behavior include builtins.fetchGit, builtins.fetchTree (experimental), and pkgs.fetchgit when used without leaveDotGit.

If you don't need the configuration, you can use gitTracked instead.

This is equivalent to the result of unions on all files returned by git ls-files (which uses --cached by default).

Currently this function is based on builtins.fetchGit As such, this function causes all Git-tracked files to be unnecessarily added to the Nix store, without being re-usable by toSource.

This may change in the future.

Inputs

options (attribute set)
recurseSubmodules (optional, default: false)
Whether to recurse into Git submodules to also include their tracked files. If true, this is equivalent to passing the --recurse-submodules flag to git ls-files.
path
The path to the working directory of a local Git repository. This directory must contain a .git file or subdirectory.

Type

gitTrackedWith :: { recurseSubmodules :: Bool ? false } -> Path -> FileSet

Examples

lib.fileset.gitTrackedWith usage example

# Include all files tracked by the Git repository in the current directory
# and any submodules under it
gitTracked { recurseSubmodules = true; } ./.

Noogle detected

Implementation

The following is the current implementation of this function.

gitTrackedWith =
    {
      recurseSubmodules ? false,
    }:
    path:
    if !isBool recurseSubmodules then
      throw "lib.fileset.gitTrackedWith: Expected the attribute `recurseSubmodules` of the first argument to be a boolean, but it's a ${typeOf recurseSubmodules} instead."
    else if recurseSubmodules && versionOlder nixVersion _fetchGitSubmodulesMinver then
      throw "lib.fileset.gitTrackedWith: Setting the attribute `recurseSubmodules` to `true` is only supported for Nix version ${_fetchGitSubmodulesMinver} and after, but Nix version ${nixVersion} is used."
    else
      _fromFetchGit "gitTrackedWith" "second argument" path
        # This is the only `fetchGit` parameter that makes sense in this context.
        # We can't just pass `submodules = recurseSubmodules` here because
        # this would fail for Nix versions that don't support `submodules`.
        (
          lib.optionalAttrs recurseSubmodules {
            submodules = true;
          }
        );