Skip to content

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:

  • revision

    (str | None) –

    If None (the default), tries to fetch the last commit.

  • additional_args

    (Iterable[str]) –

    Your custom additional arguments, e.g. --branch-name or --fetch-submodules.

Example
await prefetch_git(
    "https://github.com/PerchunPak/nixpkgs-updaters-library",
    additional_args=[
        "--branch-name", "foo",# (1)!
        "--leave-dotGit",
        "--fetch-submodules",
    ],
)
  1. If you provide --branch-name foo as a single string, it would equal to nix-prefetch-git ... '--branch-name foo'. Do you see the problem? Because additional_args is 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-git returns non-zero exit code or wrote something to stderr.

Response classes

GitPrefetchResult

Bases: NupdModel

date instance-attribute

date: datetime

deep_clone instance-attribute

deep_clone: bool

fetch_lfs instance-attribute

fetch_lfs: bool

fetch_submodules instance-attribute

fetch_submodules: bool

hash instance-attribute

hash: str

leave_dot_git instance-attribute

leave_dot_git: bool

path instance-attribute

path: str

rev instance-attribute

rev: str

url instance-attribute

url: str

GitPrefetchError

Bases: NetworkError