lib.fileset.fetchGit: Refactoring
This commit is contained in:
parent
2f3e65ad7b
commit
74f2e49543
1 changed files with 24 additions and 18 deletions
|
@ -861,28 +861,34 @@ rec {
|
||||||
# Type: String -> String -> Path -> Attrs -> FileSet
|
# Type: String -> String -> Path -> Attrs -> FileSet
|
||||||
_fromFetchGit = function: argument: path: extraFetchGitAttrs:
|
_fromFetchGit = function: argument: path: extraFetchGitAttrs:
|
||||||
let
|
let
|
||||||
# This imports the files unnecessarily, which currently can't be avoided
|
tryFetchGit =
|
||||||
# because `builtins.fetchGit` is the only function exposing which files are tracked by Git.
|
let
|
||||||
# With the [lazy trees PR](https://github.com/NixOS/nix/pull/6530),
|
# This imports the files unnecessarily, which currently can't be avoided
|
||||||
# the unnecessarily import could be avoided.
|
# because `builtins.fetchGit` is the only function exposing which files are tracked by Git.
|
||||||
# However a simpler alternative still would be [a builtins.gitLsFiles](https://github.com/NixOS/nix/issues/2944).
|
# With the [lazy trees PR](https://github.com/NixOS/nix/pull/6530),
|
||||||
fetchResult = fetchGit ({
|
# the unnecessarily import could be avoided.
|
||||||
url = path;
|
# However a simpler alternative still would be [a builtins.gitLsFiles](https://github.com/NixOS/nix/issues/2944).
|
||||||
} // extraFetchGitAttrs);
|
fetchResult = fetchGit ({
|
||||||
|
url = path;
|
||||||
|
} // extraFetchGitAttrs);
|
||||||
|
in
|
||||||
|
if inPureEvalMode then
|
||||||
|
throw "lib.fileset.${function}: 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."
|
||||||
|
# We can identify local working directories by checking for .git,
|
||||||
|
# see https://git-scm.com/docs/gitrepository-layout#_description.
|
||||||
|
# Note that `builtins.fetchGit` _does_ work for bare repositories (where there's no `.git`),
|
||||||
|
# even though `git ls-files` wouldn't return any files in that case.
|
||||||
|
else if ! pathExists (path + "/.git") then
|
||||||
|
throw "lib.fileset.${function}: Expected the ${argument} (${toString path}) to point to a local working tree of a Git repository, but it's not."
|
||||||
|
else
|
||||||
|
_mirrorStorePath path fetchResult.outPath;
|
||||||
|
|
||||||
in
|
in
|
||||||
if inPureEvalMode then
|
if ! isPath path then
|
||||||
throw "lib.fileset.${function}: 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."
|
|
||||||
else if ! isPath path then
|
|
||||||
throw "lib.fileset.${function}: Expected the ${argument} to be a path, but it's a ${typeOf path} instead."
|
throw "lib.fileset.${function}: Expected the ${argument} to be a path, but it's a ${typeOf path} instead."
|
||||||
else if pathType path != "directory" then
|
else if pathType path != "directory" then
|
||||||
throw "lib.fileset.${function}: Expected the ${argument} (${toString path}) to be a directory, but it's a file instead."
|
throw "lib.fileset.${function}: Expected the ${argument} (${toString path}) to be a directory, but it's a file instead."
|
||||||
# We can identify local working directories by checking for .git,
|
|
||||||
# see https://git-scm.com/docs/gitrepository-layout#_description.
|
|
||||||
# Note that `builtins.fetchGit` _does_ work for bare repositories (where there's no `.git`),
|
|
||||||
# even though `git ls-files` wouldn't return any files in that case.
|
|
||||||
else if ! pathExists (path + "/.git") then
|
|
||||||
throw "lib.fileset.${function}: Expected the ${argument} (${toString path}) to point to a local working tree of a Git repository, but it's not."
|
|
||||||
else
|
else
|
||||||
_mirrorStorePath path fetchResult.outPath;
|
tryFetchGit;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue