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 # Caller needs to single-quote its arguments to prevent them from
29 # being expanded a second time (in case there are spaces in them)
34 # Try a shallow clone, since it is faster than a full clone - but that only
35 # works if the version is a ref (tag or branch). Before trying to do a shallow
36 # clone we check if ${cset} is in the list provided by git ls-remote. If not
37 # we fall back on a full clone.
39 # Messages for the type of clone used are provided to ease debugging in case of
42 if [ -n "$(_git ls-remote "'${repo}'" "'${cset}'" 2>&1)" ]; then
43 printf "Doing shallow clone\n"
44 if _git clone
${verbose} --depth 1 -b "'${cset}'" --bare "'${repo}'" "'${basename}'"; then
47 printf "Shallow clone failed, falling back to doing a full clone\n"
50 if [ ${git_done} -eq 0 ]; then
51 printf "Doing full clone\n"
52 _git clone ${verbose} --mirror "'${repo}'" "'${basename}'"
55 GIT_DIR="${basename}" \
56 _git archive --prefix="'${basename}/'" -o "'${output}.tmp'" --format=tar "'${cset}'"
58 gzip <"${output}.tmp
" >"${output}"