summary refs log tree commit diff
path: root/pkgs
diff options
context:
space:
mode:
authorWinter <winter@winter.cafe>2022-08-04 15:26:03 -0400
committerRick van Schijndel <Mindavi@users.noreply.github.com>2022-08-14 23:03:07 +0200
commitdbd18a63a7e8bb59efa9e556241786ac2169033a (patch)
treedf645807f0065b6c3d21ac78cba20406b7fa27e5 /pkgs
parent989b7550e6f2b65230f64233a0216cce4ec6ddf8 (diff)
downloadnixpkgs-dbd18a63a7e8bb59efa9e556241786ac2169033a.tar
nixpkgs-dbd18a63a7e8bb59efa9e556241786ac2169033a.tar.gz
nixpkgs-dbd18a63a7e8bb59efa9e556241786ac2169033a.tar.bz2
nixpkgs-dbd18a63a7e8bb59efa9e556241786ac2169033a.tar.lz
nixpkgs-dbd18a63a7e8bb59efa9e556241786ac2169033a.tar.xz
nixpkgs-dbd18a63a7e8bb59efa9e556241786ac2169033a.tar.zst
nixpkgs-dbd18a63a7e8bb59efa9e556241786ac2169033a.zip
fetchgit: allow disabling cone mode for sparse checkouts, fix test
Diffstat (limited to 'pkgs')
-rw-r--r--pkgs/build-support/fetchgit/builder.sh1
-rw-r--r--pkgs/build-support/fetchgit/default.nix4
-rwxr-xr-xpkgs/build-support/fetchgit/nix-prefetch-git4
-rw-r--r--pkgs/build-support/fetchgit/tests.nix12
4 files changed, 19 insertions, 2 deletions
diff --git a/pkgs/build-support/fetchgit/builder.sh b/pkgs/build-support/fetchgit/builder.sh
index c7c7d21709a..66b6c168e41 100644
--- a/pkgs/build-support/fetchgit/builder.sh
+++ b/pkgs/build-support/fetchgit/builder.sh
@@ -12,6 +12,7 @@ $SHELL $fetcher --builder --url "$url" --out "$out" --rev "$rev" \
   ${deepClone:+--deepClone} \
   ${fetchSubmodules:+--fetch-submodules} \
   ${sparseCheckout:+--sparse-checkout "$sparseCheckout"} \
+  ${nonConeMode:+--non-cone-mode} \
   ${branchName:+--branch-name "$branchName"}
 
 runHook postFetch
diff --git a/pkgs/build-support/fetchgit/default.nix b/pkgs/build-support/fetchgit/default.nix
index 84f2278db29..f516c3d5a03 100644
--- a/pkgs/build-support/fetchgit/default.nix
+++ b/pkgs/build-support/fetchgit/default.nix
@@ -16,6 +16,7 @@ in
 , fetchSubmodules ? true, deepClone ? false
 , branchName ? null
 , sparseCheckout ? ""
+, nonConeMode ? false
 , name ? urlToName url rev
 , # Shell code executed after the file has been fetched
   # successfully. This can do things like check or transform the file.
@@ -54,6 +55,7 @@ in
 */
 
 assert deepClone -> leaveDotGit;
+assert nonConeMode -> (sparseCheckout != "");
 
 if md5 != "" then
   throw "fetchgit does not support md5 anymore, please use sha256"
@@ -77,7 +79,7 @@ stdenvNoCC.mkDerivation {
   else
     lib.fakeSha256;
 
-  inherit url rev leaveDotGit fetchLFS fetchSubmodules deepClone branchName sparseCheckout postFetch;
+  inherit url rev leaveDotGit fetchLFS fetchSubmodules deepClone branchName sparseCheckout nonConeMode postFetch;
 
   postHook = if netrcPhase == null then null else ''
     ${netrcPhase}
diff --git a/pkgs/build-support/fetchgit/nix-prefetch-git b/pkgs/build-support/fetchgit/nix-prefetch-git
index 4e6f25b8dd7..9c2048066ce 100755
--- a/pkgs/build-support/fetchgit/nix-prefetch-git
+++ b/pkgs/build-support/fetchgit/nix-prefetch-git
@@ -49,6 +49,7 @@ Options:
       --hash h        Expected hash.
       --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.
@@ -77,6 +78,7 @@ for arg; do
             --branch-name) argfun=set_branchName;;
             --deepClone) deepClone=true;;
             --sparse-checkout) argfun=set_sparseCheckout;;
+            --non-cone-mode) nonConeMode=true;;
             --quiet) QUIET=true;;
             --no-deepClone) deepClone=;;
             --leave-dotGit) leaveDotGit=true;;
@@ -116,7 +118,7 @@ init_remote(){
     clean_git remote add origin "$url"
     if [ -n "$sparseCheckout" ]; then
         git config remote.origin.partialclonefilter "blob:none"
-        echo "$sparseCheckout" | git sparse-checkout set --stdin
+        echo "$sparseCheckout" | git sparse-checkout set --stdin ${nonConeMode:+--no-cone}
     fi
     ( [ -n "$http_proxy" ] && clean_git config http.proxy "$http_proxy" ) || true
 }
diff --git a/pkgs/build-support/fetchgit/tests.nix b/pkgs/build-support/fetchgit/tests.nix
index b9ab66d9353..62fe3f77bbd 100644
--- a/pkgs/build-support/fetchgit/tests.nix
+++ b/pkgs/build-support/fetchgit/tests.nix
@@ -16,6 +16,18 @@
       src
       tests
     '';
+    sha256 = "sha256-g1PHGTWgAcd/+sXHo1o6AjVWCvC6HiocOfMbMh873LQ=";
+  };
+
+  sparseCheckoutNonConeMode = testers.invalidateFetcherByDrvHash fetchgit {
+    name = "nix-source";
+    url = "https://github.com/NixOS/nix";
+    rev = "9d9dbe6ed05854e03811c361a3380e09183f4f4a";
+    sparseCheckout = ''
+      src
+      tests
+    '';
+    nonConeMode = true;
     sha256 = "sha256-FknO6C/PSnMPfhUqObD4vsW4PhkwdmPa9blNzcNvJQ4=";
   };
 }