@@ -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
@@ -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.
@@ -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