Merge pull request #11671 from timbertson/fetchgit

fetchgit: output improvements

+53 -12
+53 -12
pkgs/build-support/fetchgit/nix-prefetch-git
··· 12 builder= 13 branchName=$NIX_PREFETCH_GIT_BRANCH_NAME 14 15 if test -n "$deepClone"; then 16 deepClone=true 17 else ··· 52 --hash) argfun=set_hashType;; 53 --branch-name) argfun=set_branchName;; 54 --deepClone) deepClone=true;; 55 --no-deepClone) deepClone=false;; 56 --leave-dotGit) leaveDotGit=true;; 57 --fetch-submodules) fetchSubmodules=true;; ··· 254 } 255 256 257 - clone_user_rev() { 258 local dir="$1" 259 local url="$2" 260 local rev="${3:-HEAD}" ··· 272 fi;; 273 esac 274 275 - local full_revision=$(cd $dir && (git rev-parse $rev 2> /dev/null || git rev-parse refs/heads/$branchName) | tail -n1) 276 - echo "git revision is $full_revision" 277 - echo "git human-readable version is $(cd $dir && (git describe $full_revision 2> /dev/null || git describe --tags $full_revision 2> /dev/null || echo -- none --))" >&2 278 - echo "Commit date is $(cd $dir && git show --no-patch --pretty=%ci $full_revision)" 279 280 # Allow doing additional processing before .git removal 281 eval "$NIX_PREFETCH_GIT_CHECKOUT_HOOK" 282 if test -z "$leaveDotGit"; then 283 echo "removing \`.git'..." >&2 284 - find $dir -name .git\* | xargs rm -rf 285 else 286 - find $dir -name .git | while read gitdir; do 287 make_deterministic_repo "$(readlink -f "$gitdir/..")" 288 done 289 fi 290 } 291 292 if test -z "$branchName"; then 293 branchName=fetchgit 294 fi ··· 327 328 # Compute the hash. 329 hash=$(nix-hash --type $hashType --base32 $tmpFile) 330 - if ! test -n "$QUIET"; then echo "hash is $hash" >&2; fi 331 332 # Add the downloaded file to the Nix store. 333 finalPath=$(nix-store --add-fixed --recursive "$hashType" "$tmpFile") 334 335 if test -n "$expHash" -a "$expHash" != "$hash"; then 336 - echo "hash mismatch for URL \`$url'" 337 exit 1 338 fi 339 fi 340 341 - if ! test -n "$QUIET"; then echo "path is $finalPath" >&2; fi 342 - 343 - echo $hash 344 345 if test -n "$PRINT_PATH"; then 346 echo $finalPath
··· 12 builder= 13 branchName=$NIX_PREFETCH_GIT_BRANCH_NAME 14 15 + # populated by clone_user_rev() 16 + fullRev= 17 + humanReadableRev= 18 + commitDate= 19 + 20 if test -n "$deepClone"; then 21 deepClone=true 22 else ··· 57 --hash) argfun=set_hashType;; 58 --branch-name) argfun=set_branchName;; 59 --deepClone) deepClone=true;; 60 + --quiet) QUIET=true;; 61 --no-deepClone) deepClone=false;; 62 --leave-dotGit) leaveDotGit=true;; 63 --fetch-submodules) fetchSubmodules=true;; ··· 260 } 261 262 263 + _clone_user_rev() { 264 local dir="$1" 265 local url="$2" 266 local rev="${3:-HEAD}" ··· 278 fi;; 279 esac 280 281 + fullRev="$(cd $dir && (git rev-parse $rev 2> /dev/null || git rev-parse refs/heads/$branchName) | tail -n1)" 282 + humanReadableRev="$(cd $dir && (git describe $fullRev 2> /dev/null || git describe --tags $fullRev 2> /dev/null || echo -- none --))" 283 + commitDate="$(cd $dir && git show --no-patch --pretty=%ci $fullRev)" 284 285 # Allow doing additional processing before .git removal 286 eval "$NIX_PREFETCH_GIT_CHECKOUT_HOOK" 287 if test -z "$leaveDotGit"; then 288 echo "removing \`.git'..." >&2 289 + find "$dir" -name .git\* -print0 | xargs -0 rm -rf 290 else 291 + find "$dir" -name .git | while read gitdir; do 292 make_deterministic_repo "$(readlink -f "$gitdir/..")" 293 done 294 fi 295 } 296 297 + clone_user_rev() { 298 + if ! test -n "$QUIET"; then 299 + _clone_user_rev "$@" 300 + else 301 + errfile="$(mktemp "${TMPDIR:-/tmp}/git-checkout-err-XXXXXXXX")" 302 + trap "rm -rf \"$errfile\"" EXIT 303 + _clone_user_rev "$@" 2> "$errfile" || ( 304 + status="$?" 305 + cat "$errfile" >&2 306 + exit "$status" 307 + ) 308 + fi 309 + } 310 + 311 + 312 + print_results() { 313 + hash="$1" 314 + if ! test -n "$QUIET"; then 315 + echo "" >&2 316 + echo "git revision is $fullRev" >&2 317 + if test -n "$finalPath"; then 318 + echo "path is $finalPath" >&2 319 + fi 320 + echo "git human-readable version is $humanReadableRev" >&2 321 + echo "Commit date is $commitDate" >&2 322 + if test -n "$hash"; then 323 + echo "hash is $hash" >&2 324 + fi 325 + fi 326 + if test -n "$hash"; then 327 + echo "{" 328 + echo " url = \"$url\";" 329 + echo " rev = \"$fullRev\";" 330 + echo " $hashType = \"$hash\";" 331 + echo "}" 332 + fi 333 + } 334 + 335 if test -z "$branchName"; then 336 branchName=fetchgit 337 fi ··· 370 371 # Compute the hash. 372 hash=$(nix-hash --type $hashType --base32 $tmpFile) 373 374 # Add the downloaded file to the Nix store. 375 finalPath=$(nix-store --add-fixed --recursive "$hashType" "$tmpFile") 376 377 if test -n "$expHash" -a "$expHash" != "$hash"; then 378 + print_metadata 379 + echo "hash mismatch for URL \`$url'" >&2 380 exit 1 381 fi 382 fi 383 384 + print_results "$hash" 385 386 if test -n "$PRINT_PATH"; then 387 echo $finalPath