Merge pull request #54543 from thefloweringash/git-prefetch-errors

nix-prefetch-git: propagate errors under --quiet
This commit is contained in:
Matthew Bauer 2019-06-18 11:20:28 -04:00 committed by GitHub
commit c08cdfa781
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -270,7 +270,7 @@ make_deterministic_repo(){
} }
_clone_user_rev() { clone_user_rev() {
local dir="$1" local dir="$1"
local url="$2" local url="$2"
local rev="${3:-HEAD}" local rev="${3:-HEAD}"
@ -307,19 +307,29 @@ _clone_user_rev() {
fi fi
} }
clone_user_rev() { exit_handlers=()
if ! test -n "$QUIET"; then
_clone_user_rev "$@" run_exit_handlers() {
else exit_status=$?
errfile="$(mktemp "${TMPDIR:-/tmp}/git-checkout-err-XXXXXXXX")" for handler in "${exit_handlers[@]}"; do
# shellcheck disable=SC2064 eval "$handler $exit_status"
trap "rm -rf \"$errfile\"" EXIT done
_clone_user_rev "$@" 2> "$errfile" || ( }
status="$?"
cat "$errfile" >&2 trap run_exit_handlers EXIT
exit "$status"
) quiet_exit_handler() {
exec 2>&3 3>&-
if [ $1 -ne 0 ]; then
cat "$errfile" >&2
fi fi
rm -f "$errfile"
}
quiet_mode() {
errfile="$(mktemp "${TMPDIR:-/tmp}/git-checkout-err-XXXXXXXX")"
exit_handlers+=(quiet_exit_handler)
exec 3>&2 2>"$errfile"
} }
json_escape() { json_escape() {
@ -362,6 +372,14 @@ EOF
fi fi
} }
remove_tmpPath() {
rm -rf "$tmpPath"
}
if test -n "$QUIET"; then
quiet_mode
fi
if test -z "$branchName"; then if test -z "$branchName"; then
branchName=fetchgit branchName=fetchgit
fi fi
@ -390,8 +408,7 @@ else
if test -z "$finalPath"; then if test -z "$finalPath"; then
tmpPath="$(mktemp -d "${TMPDIR:-/tmp}/git-checkout-tmp-XXXXXXXX")" tmpPath="$(mktemp -d "${TMPDIR:-/tmp}/git-checkout-tmp-XXXXXXXX")"
# shellcheck disable=SC2064 exit_handlers+=(remove_tmpPath)
trap "rm -rf \"$tmpPath\"" EXIT
tmpFile="$tmpPath/$(url_to_name "$url" "$rev")" tmpFile="$tmpPath/$(url_to_name "$url" "$rev")"
mkdir -p "$tmpFile" mkdir -p "$tmpFile"