3 # We want to catch any unexpected failure, and exit immediately
6 # Download helper for git, to be called from the download wrapper script
9 # .../git [-q] OUT_FILE REPO_URL CSET BASENAME
12 # GIT : the git command to call
15 while getopts :q OPT; do
17 q) verbose=-q; exec >/dev/null;;
18 \?) printf "unknown option '%s'\n" "${OPTARG}" >&2; exit 1;;
28 # Try a shallow clone, since it is faster than a full clone - but that only
29 # works if the version is a ref (tag or branch). Before trying to do a shallow
30 # clone we check if ${cset} is in the list provided by git ls-remote. If not
31 # we fall back on a full clone.
33 # Messages for the type of clone used are provided to ease debugging in case of
36 if [ -n "$(${GIT} ls-remote "${repo}" "${cset}" 2>&1)" ]; then
37 printf "Doing shallow clone\n"
38 if ${GIT} clone ${verbose} --depth 1 -b "${cset}" --bare "${repo}" "${basename}"; then
41 printf "Shallow clone failed, falling back to doing a full clone\n"
44 if [ ${git_done} -eq 0 ]; then
45 printf "Doing full clone\n"
46 ${GIT} clone ${verbose} --bare "${repo}" "${basename}"
49 GIT_DIR="${basename}" \
50 ${GIT} archive --prefix="${basename}/" -o "${output}.tmp" --format=tar "${cset}"
52 gzip <"${output}.tmp" >"${output}"