diff options
| author | ibbem <ibbem@ibbem.net> | 2024-01-30 17:55:30 +0100 |
|---|---|---|
| committer | ibbem <ibbem@ibbem.net> | 2024-02-01 00:01:26 +0100 |
| commit | 6558e891777932e8066080e89bdc773e6127e1e7 (patch) | |
| tree | eee8933729d7cacb8202b8c63ef489016bcd3bb7 /lib/fileset/internal.nix | |
| parent | Merge pull request #275493 from chitochi/guile-chickadee (diff) | |
| download | nixpkgs-6558e891777932e8066080e89bdc773e6127e1e7.tar.gz | |
lib.fileset.gitTracked: Allow clones of shallow repositories
The only reason shallow clones are not the default in
`builtins.fetchGit` is that `revCount` can't be provided when cloning a
shallow repository. However, `revCount` isn't used or exposed by
`lib.fileset`. Hence, allowing cloning shallow repositories makes
`gitTracked` more general without any drawbacks.
Co-authored-by: Silvan Mosberger <github@infinisil.com>
Diffstat (limited to 'lib/fileset/internal.nix')
| -rw-r--r-- | lib/fileset/internal.nix | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/lib/fileset/internal.nix b/lib/fileset/internal.nix index 4059d2e24426..f4fcc83e1012 100644 --- a/lib/fileset/internal.nix +++ b/lib/fileset/internal.nix @@ -5,6 +5,7 @@ let isAttrs isPath isString + nixVersion pathExists readDir split @@ -17,6 +18,7 @@ let attrNames attrValues mapAttrs + optionalAttrs zipAttrsWith ; @@ -56,6 +58,7 @@ let substring stringLength hasSuffix + versionAtLeast ; inherit (lib.trivial) @@ -840,6 +843,10 @@ rec { # https://github.com/NixOS/nix/commit/55cefd41d63368d4286568e2956afd535cb44018 _fetchGitSubmodulesMinver = "2.4"; + # Support for `builtins.fetchGit` with `shallow = true` was introduced in 2.4 + # https://github.com/NixOS/nix/commit/d1165d8791f559352ff6aa7348e1293b2873db1c + _fetchGitShallowMinver = "2.4"; + # Mirrors the contents of a Nix store path relative to a local path as a file set. # Some notes: # - The store path is read at evaluation time. @@ -894,7 +901,17 @@ rec { # However a simpler alternative still would be [a builtins.gitLsFiles](https://github.com/NixOS/nix/issues/2944). fetchResult = fetchGit ({ url = path; - } // extraFetchGitAttrs); + } + # In older Nix versions, repositories were always assumed to be deep clones, which made `fetchGit` fail for shallow clones + # For newer versions this was fixed, but the `shallow` flag is required. + # The only behavioral difference is that for shallow clones, `fetchGit` doesn't return a `revCount`, + # which we don't need here, so it's fine to always pass it. + + # Unfortunately this means older Nix versions get a poor error message for shallow repositories, and there's no good way to improve that. + # Checking for `.git/shallow` doesn't seem worth it, especially since that's more of an implementation detail, + # and would also require more code to handle worktrees where `.git` is a file. + // optionalAttrs (versionAtLeast nixVersion _fetchGitShallowMinver) { shallow = true; } + // extraFetchGitAttrs); in # We can identify local working directories by checking for .git, # see https://git-scm.com/docs/gitrepository-layout#_description. |
