git 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #!/usr/bin/env bash
  2. # We want to catch any unexpected failure, and exit immediately
  3. set -e
  4. # Download helper for git, to be called from the download wrapper script
  5. #
  6. # Call it as:
  7. # .../git [-q] OUT_FILE REPO_URL CSET BASENAME
  8. #
  9. # Environment:
  10. # GIT : the git command to call
  11. verbose=-v
  12. while getopts :q OPT; do
  13. case "${OPT}" in
  14. q) verbose=-q;;
  15. \?) printf "unknown option '%s'\n" "${OPTARG}" >&2; exit 1;;
  16. esac
  17. done
  18. shift $((OPTIND-1))
  19. output="${1}"
  20. repo="${2}"
  21. cset="${3}"
  22. basename="${4}"
  23. # Try to see if we can do a shallow clone, since it is faster
  24. # than a full clone.
  25. git_done=0
  26. if [ -n "$(${GIT} ls-remote "${repo}" "${cset}" 2>&1)" ]; then
  27. printf "Doing shallow clone\n"
  28. if ${GIT} clone ${verbose} --depth 1 -b "${cset}" --bare "${repo}" "${basename}"; then
  29. git_done=1
  30. else
  31. printf "Shallow clone failed, falling back to doing a full clone\n"
  32. fi
  33. fi
  34. if [ ${git_done} -eq 0 ]; then
  35. printf "Doing full clone\n"
  36. ${GIT} clone ${verbose} --bare "${repo}" "${basename}"
  37. fi
  38. GIT_DIR="${basename}" \
  39. ${GIT} archive --prefix="${basename}/" -o "${output}.tmp" --format=tar "${cset}"
  40. gzip <"${output}.tmp" >"${output}"