summaryrefslogtreecommitdiffstats
path: root/pkgs/build-support/fetchgit/nix-prefetch-git
diff options
context:
space:
mode:
authorZhong Jianxin <azuwis@gmail.com>2021-08-27 16:25:20 +0800
committerZhong Jianxin <azuwis@gmail.com>2022-01-24 11:23:56 +0800
commitd03a07d5a74ef780b9de78225a7d7d59db8f9169 (patch)
treed00dda0be68b3a3ab7efce2314fa23148ab01fc0 /pkgs/build-support/fetchgit/nix-prefetch-git
parente8d0231396d1642cefe7940b2897451fbf128729 (diff)
fetchgit: Support sparse checkout
This allow git checkout small parts of a large repo, and avoid fetching unnecessary blobs from server.
Diffstat (limited to 'pkgs/build-support/fetchgit/nix-prefetch-git')
-rwxr-xr-xpkgs/build-support/fetchgit/nix-prefetch-git8
1 files changed, 7 insertions, 1 deletions
diff --git a/pkgs/build-support/fetchgit/nix-prefetch-git b/pkgs/build-support/fetchgit/nix-prefetch-git
index be5068c7ad31..4e6f25b8dd7d 100755
--- a/pkgs/build-support/fetchgit/nix-prefetch-git
+++ b/pkgs/build-support/fetchgit/nix-prefetch-git
@@ -48,6 +48,7 @@ Options:
--rev ref Any sha1 or references (such as refs/heads/master)
--hash h Expected hash.
--branch-name Branch name to check out into
+ --sparse-checkout Only fetch and checkout part of the repository.
--deepClone Clone the entire repository.
--no-deepClone Make a shallow clone of just the required ref.
--leave-dotGit Keep the .git directories.
@@ -75,6 +76,7 @@ for arg; do
--hash) argfun=set_hashType;;
--branch-name) argfun=set_branchName;;
--deepClone) deepClone=true;;
+ --sparse-checkout) argfun=set_sparseCheckout;;
--quiet) QUIET=true;;
--no-deepClone) deepClone=;;
--leave-dotGit) leaveDotGit=true;;
@@ -96,7 +98,7 @@ for arg; do
case $argfun in
set_*)
var=${argfun#set_}
- eval $var=$arg
+ eval "$var=$(printf %q "$arg")"
;;
esac
argfun=""
@@ -112,6 +114,10 @@ init_remote(){
local url=$1
clean_git init --initial-branch=master
clean_git remote add origin "$url"
+ if [ -n "$sparseCheckout" ]; then
+ git config remote.origin.partialclonefilter "blob:none"
+ echo "$sparseCheckout" | git sparse-checkout set --stdin
+ fi
( [ -n "$http_proxy" ] && clean_git config http.proxy "$http_proxy" ) || true
}