git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #80091 from NixOS/npregit-dumpall

nix-prefetch-git: report deepClone & leaveDotGit

commit477ea066ca101eee497433e2a0027374788e82a1 authorJan Tojnar <jtojnar@gmail.com> dateWed 19 Feb 2020, 07:37 (7 years ago) parentdcce49428faf5b
1 file changed+24−17
pkgs/build-support/fetchgit/nix-prefetch-git+24−17
pkgs/build-support/fetchgit/nix-prefetch-git+24−17
@@ -25,7 +25,7 @@ commitDateStrict8601=
2525if test -n "$deepClone"; then
2626 deepClone=true
2727else
28− deepClone=false
28+ deepClone=
2929fi
3030
3131if test "$leaveDotGit" != 1; then
@@ -53,6 +53,11 @@ Options:
5353 exit 1
5454}
5555
56+# some git commands print to stdout, which would contaminate our JSON output
57+clean_git(){
58+ git "$@" >&2
59+}
60+
5661argi=0
5762argfun=""
5863for arg; do
@@ -65,7 +70,7 @@ for arg; do
6570 --branch-name) argfun=set_branchName;;
6671 --deepClone) deepClone=true;;
6772 --quiet) QUIET=true;;
68− --no-deepClone) deepClone=false;;
73+ --no-deepClone) deepClone=;;
6974 --leave-dotGit) leaveDotGit=true;;
7075 --fetch-submodules) fetchSubmodules=true;;
7176 --builder) builder=true;;
@@ -98,9 +103,9 @@ fi
98103
99104init_remote(){
100105 local url=$1
101− git init
102− git remote add origin "$url"
103− ( [ -n "$http_proxy" ] && git config http.proxy "$http_proxy" ) || true
106+ clean_git init
107+ clean_git remote add origin "$url"
108+ ( [ -n "$http_proxy" ] && clean_git config http.proxy "$http_proxy" ) || true
104109}
105110
106111# Return the reference of an hash if it exists on the remote repository.
@@ -141,8 +146,8 @@ checkout_hash(){
141146 hash=$(hash_from_ref "$ref")
142147 fi
143148
144− git fetch -t ${builder:+--progress} origin || return 1
145− git checkout -b "$branchName" "$hash" || return 1
149+ clean_git fetch -t ${builder:+--progress} origin || return 1
150+ clean_git checkout -b "$branchName" "$hash" || return 1
146151}
147152
148153# Fetch only a branch/tag and checkout it.
@@ -150,7 +155,7 @@ checkout_ref(){
150155 local hash="$1"
151156 local ref="$2"
152157
153− if "$deepClone"; then
158+ if [[ -n "$deepClone" ]]; then
154159 # The caller explicitly asked for a deep clone. Deep clones
155160 # allow "git describe" and similar tools to work. See
156161 # https://marc.info/?l=nix-dev&m=139641582514772
@@ -164,8 +169,8 @@ checkout_ref(){
164169
165170 if test -n "$ref"; then
166171 # --depth option is ignored on http repository.
167− git fetch ${builder:+--progress} --depth 1 origin +"$ref" || return 1
168− git checkout -b "$branchName" FETCH_HEAD || return 1
172+ clean_git fetch ${builder:+--progress} --depth 1 origin +"$ref" || return 1
173+ clean_git checkout -b "$branchName" FETCH_HEAD || return 1
169174 else
170175 return 1
171176 fi
@@ -174,7 +179,7 @@ checkout_ref(){
174179# Update submodules
175180init_submodules(){
176181 # Add urls into .git/config file
177− git submodule init
182+ clean_git submodule init
178183
179184 # list submodule directories and their hashes
180185 git submodule status |
@@ -248,7 +253,7 @@ make_deterministic_repo(){
248253
249254 # Remove all remote branches.
250255 git branch -r | while read -r branch; do
251− git branch -rD "$branch" >&2
256+ clean_git branch -rD "$branch"
252257 done
253258
254259 # Remove tags not reachable from HEAD. If we're exactly on a tag, don't
@@ -256,19 +261,19 @@ make_deterministic_repo(){
256261 maybe_tag=$(git tag --points-at HEAD)
257262 git tag --contains HEAD | while read -r tag; do
258263 if [ "$tag" != "$maybe_tag" ]; then
259− git tag -d "$tag" >&2
264+ clean_git tag -d "$tag"
260265 fi
261266 done
262267
263268 # Do a full repack. Must run single-threaded, or else we lose determinism.
264− git config pack.threads 1
265− git repack -A -d -f
269+ clean_git config pack.threads 1
270+ clean_git repack -A -d -f
266271 rm -f .git/config
267272
268273 # Garbage collect unreferenced objects.
269274 # Note: --keep-largest-pack prevents non-deterministic ordering of packs
270275 # listed in .git/objects/info/packs by only using a single pack
271− git gc --prune=all --keep-largest-pack
276+ clean_git gc --prune=all --keep-largest-pack
272277 )
273278}
274279
@@ -369,7 +374,9 @@ print_results() {
369374 "rev": "$(json_escape "$fullRev")",
370375 "date": "$(json_escape "$commitDateStrict8601")",
371376 "$(json_escape "$hashType")": "$(json_escape "$hash")",
372− "fetchSubmodules": $([[ -n "$fetchSubmodules" ]] && echo true || echo false)
377+ "fetchSubmodules": $([[ -n "$fetchSubmodules" ]] && echo true || echo false),
378+ "deepClone": $([[ -n "$deepClone" ]] && echo true || echo false),
379+ "leaveDotGit": $([[ -n "$leaveDotGit" ]] && echo true || echo false)
373380}
374381EOF
375382 fi