diff options
author | Alyssa Ross <hi@alyssa.is> | 2021-08-04 10:43:07 +0000 |
---|---|---|
committer | Alyssa Ross <hi@alyssa.is> | 2021-08-04 10:43:07 +0000 |
commit | 62614cbef7da005c1eda8c9400160f6bcd6546b8 (patch) | |
tree | c2630f69080637987b68acb1ee8676d2681fe304 /pkgs/build-support/fetchgit | |
parent | d9c82ed3044c72cecf01c6ea042489d30914577c (diff) | |
parent | e24069138dfec3ef94f211f1da005bb5395adc11 (diff) | |
download | nixpkgs-62614cbef7da005c1eda8c9400160f6bcd6546b8.tar nixpkgs-62614cbef7da005c1eda8c9400160f6bcd6546b8.tar.gz nixpkgs-62614cbef7da005c1eda8c9400160f6bcd6546b8.tar.bz2 nixpkgs-62614cbef7da005c1eda8c9400160f6bcd6546b8.tar.lz nixpkgs-62614cbef7da005c1eda8c9400160f6bcd6546b8.tar.xz nixpkgs-62614cbef7da005c1eda8c9400160f6bcd6546b8.tar.zst nixpkgs-62614cbef7da005c1eda8c9400160f6bcd6546b8.zip |
Merge branch 'nixpkgs-update' into master
Diffstat (limited to 'pkgs/build-support/fetchgit')
-rw-r--r-- | pkgs/build-support/fetchgit/builder.sh | 1 | ||||
-rw-r--r-- | pkgs/build-support/fetchgit/default.nix | 15 | ||||
-rwxr-xr-x | pkgs/build-support/fetchgit/nix-prefetch-git | 27 |
3 files changed, 34 insertions, 9 deletions
diff --git a/pkgs/build-support/fetchgit/builder.sh b/pkgs/build-support/fetchgit/builder.sh index 6ae46469738..0047a335c76 100644 --- a/pkgs/build-support/fetchgit/builder.sh +++ b/pkgs/build-support/fetchgit/builder.sh @@ -8,6 +8,7 @@ header "exporting $url (rev $rev) into $out" $SHELL $fetcher --builder --url "$url" --out "$out" --rev "$rev" \ ${leaveDotGit:+--leave-dotGit} \ + ${fetchLFS:+--fetch-lfs} \ ${deepClone:+--deepClone} \ ${fetchSubmodules:+--fetch-submodules} \ ${branchName:+--branch-name "$branchName"} diff --git a/pkgs/build-support/fetchgit/default.nix b/pkgs/build-support/fetchgit/default.nix index 0405951a9e4..3222866dc78 100644 --- a/pkgs/build-support/fetchgit/default.nix +++ b/pkgs/build-support/fetchgit/default.nix @@ -1,9 +1,9 @@ -{stdenvNoCC, git, cacert}: let +{lib, stdenvNoCC, git, git-lfs, cacert}: let urlToName = url: rev: let - inherit (stdenvNoCC.lib) removeSuffix splitString last; + inherit (lib) removeSuffix splitString last; base = last (splitString ":" (baseNameOf (removeSuffix "/" url))); - matched = builtins.match "(.*).git" base; + matched = builtins.match "(.*)\\.git" base; short = builtins.substring 0 7 rev; @@ -20,6 +20,7 @@ in # successfully. This can do things like check or transform the file. postFetch ? "" , preferLocalBuild ? true +, fetchLFS ? false }: /* NOTE: @@ -53,17 +54,19 @@ stdenvNoCC.mkDerivation { inherit name; builder = ./builder.sh; fetcher = ./nix-prefetch-git; # This must be a string to ensure it's called with bash. - nativeBuildInputs = [git]; + + nativeBuildInputs = [ git ] + ++ lib.optionals fetchLFS [ git-lfs ]; outputHashAlgo = "sha256"; outputHashMode = "recursive"; outputHash = sha256; - inherit url rev leaveDotGit fetchSubmodules deepClone branchName postFetch; + inherit url rev leaveDotGit fetchLFS fetchSubmodules deepClone branchName postFetch; GIT_SSL_CAINFO = "${cacert}/etc/ssl/certs/ca-bundle.crt"; - impureEnvVars = stdenvNoCC.lib.fetchers.proxyImpureEnvVars ++ [ + impureEnvVars = lib.fetchers.proxyImpureEnvVars ++ [ "GIT_PROXY_COMMAND" "SOCKS_SERVER" ]; diff --git a/pkgs/build-support/fetchgit/nix-prefetch-git b/pkgs/build-support/fetchgit/nix-prefetch-git index 43f7c5acd5a..8110d670e41 100755 --- a/pkgs/build-support/fetchgit/nix-prefetch-git +++ b/pkgs/build-support/fetchgit/nix-prefetch-git @@ -9,6 +9,7 @@ hashType=$NIX_HASH_ALGO deepClone=$NIX_PREFETCH_GIT_DEEP_CLONE leaveDotGit=$NIX_PREFETCH_GIT_LEAVE_DOT_GIT fetchSubmodules= +fetchLFS= builder= branchName=$NIX_PREFETCH_GIT_BRANCH_NAME @@ -46,6 +47,7 @@ Options: --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. --builder Clone as fetchgit does, but url, rev, and out option are mandatory. --quiet Only print the final json summary. @@ -72,6 +74,7 @@ for arg; do --quiet) QUIET=true;; --no-deepClone) deepClone=;; --leave-dotGit) leaveDotGit=true;; + --fetch-lfs) fetchLFS=true;; --fetch-submodules) fetchSubmodules=true;; --builder) builder=true;; -h|--help) usage; exit;; @@ -103,7 +106,7 @@ fi init_remote(){ local url=$1 - clean_git init + clean_git init --initial-branch=master clean_git remote add origin "$url" ( [ -n "$http_proxy" ] && clean_git config http.proxy "$http_proxy" ) || true } @@ -137,7 +140,7 @@ url_to_name(){ fi } -# Fetch everything and checkout the right sha1 +# Fetch and checkout the right sha1 checkout_hash(){ local hash="$1" local ref="$2" @@ -146,8 +149,21 @@ checkout_hash(){ hash=$(hash_from_ref "$ref") fi + clean_git fetch ${builder:+--progress} --depth=1 origin "$hash" || \ clean_git fetch -t ${builder:+--progress} origin || return 1 - clean_git checkout -b "$branchName" "$hash" || return 1 + + local object_type=$(git cat-file -t "$hash") + if [[ "$object_type" == "commit" ]]; then + clean_git checkout -b "$branchName" "$hash" || return 1 + elif [[ "$object_type" == "tree" ]]; then + clean_git config user.email "nix-prefetch-git@localhost" + clean_git config user.name "nix-prefetch-git" + local commit_id=$(git commit-tree "$hash" -m "Commit created from tree hash $hash") + clean_git checkout -b "$branchName" "$commit_id" || return 1 + else + echo "Unrecognized git object type: $object_type" + return 1 + fi } # Fetch only a branch/tag and checkout it. @@ -283,6 +299,11 @@ clone_user_rev() { local url="$2" local rev="${3:-HEAD}" + if [ -n "$fetchLFS" ]; then + HOME=$TMPDIR + git lfs install + fi + # Perform the checkout. case "$rev" in HEAD|refs/*) |