nix-prefetch-git wrapper
nix-prefetch-git is a script, that exists purely inside nixpkgs. You can read
its source code here
(permalink)
or read its --help on the moment of the writing:
$ nix-prefetch-git --help
syntax: nix-prefetch-git [options] [URL [REVISION [EXPECTED-HASH]]]
Options:
--out path Path where the output would be stored.
--url url Any url understood by 'git clone'.
--rev ref Any sha1 or references (such as refs/heads/master)
--hash h Expected hash.
--name n Symbolic store path name to use for the result (default: based on URL)
--branch-name Branch name to check out into
--sparse-checkout Only fetch and checkout part of the repository.
--non-cone-mode Use non-cone mode for sparse checkouts.
--deepClone Clone the entire repository.
--no-deepClone Make a shallow clone of just the required ref.
--leave-dotGit Keep the .git directories.
--fetch-lfs Fetch git Large File Storage (LFS) files.
--fetch-submodules Fetch submodules.
--fetch-tags Fetch all tags (useful for git describe).
--builder Clone as fetchgit does, but url, rev, and out option are mandatory.
--quiet Only print the final json summary.
Info
All requests to the functions are automatically cached.
prefetch_git
async
prefetch_git(
url: str,
*,
revision: str | None,
additional_args: Iterable[str],
) -> GitPrefetchResult
Just a fancy wrapper around nix-prefetch-git to handle edge-cases like caching.
Parameters:
-
(revisionstr | None) –If
None(the default), tries to fetch the last commit. -
(additional_argsIterable[str]) –Your custom additional arguments, e.g.
--branch-nameor--fetch-submodules.
Example
await prefetch_git(
"https://github.com/PerchunPak/nixpkgs-updaters-library",
additional_args=[
"--branch-name", "foo",# (1)!
"--leave-dotGit",
"--fetch-submodules",
],
)
- If you provide
--branch-name fooas a single string, it would equal tonix-prefetch-git ... '--branch-name foo'. Do you see the problem? Becauseadditional_argsis not parsed by a shell (/bin/sh), you have to manually separate each word, otherwise the script won't recognize it as separate words, which leads to an obscure error.
Raises:
-
GitPrefetchError–If
nix-prefetch-gitreturns non-zero exit code or wrote something to stderr.
Response classes
GitPrefetchResult
Bases: NupdModel
GitPrefetchError
Bases: NetworkError