git 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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. # Expected arguments:
  6. # $1: output file
  7. # $2: git repo
  8. # $3: git cset
  9. # $4: package's basename (eg. foobar-1.2.3)
  10. # And this environment:
  11. # GIT : the git command to call
  12. output="${1}"
  13. repo="${2}"
  14. cset="${3}"
  15. basename="${4}"
  16. # Try to see if we can do a shallow clone, since it is faster
  17. # than a full clone.
  18. git_done=0
  19. if [ -n "$(${GIT} ls-remote "${repo}" "${cset}" 2>&1)" ]; then
  20. printf "Doing shallow clone\n"
  21. if ${GIT} clone --depth 1 -b "${cset}" --bare "${repo}" "${basename}"; then
  22. git_done=1
  23. else
  24. printf "Shallow clone failed, falling back to doing a full clone\n"
  25. fi
  26. fi
  27. if [ ${git_done} -eq 0 ]; then
  28. printf "Doing full clone\n"
  29. ${GIT} clone --bare "${repo}" "${basename}"
  30. fi
  31. GIT_DIR="${basename}" \
  32. ${GIT} archive --prefix="${basename}/" -o "${output}.tmp" --format=tar "${cset}"
  33. gzip <"${output}.tmp" >"${output}"