git 1008 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. #!/bin/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. if [ -n "$(${GIT} ls-remote "${repo}" "${cset}" 2>&1)" ]; then
  19. printf "Doing shallow clone\n"
  20. if ${GIT} clone --depth 1 -b "${cset}" --bare "${repo}" "${basename}"; then
  21. git_done=1
  22. else
  23. printf "Shallow clone failed, falling back to doing a full clone\n"
  24. fi
  25. fi
  26. if [ ${git_done} -eq 0 ]; then
  27. printf "Doing full clone\n"
  28. ${GIT} clone --bare "${repo}" "${basename}"
  29. fi
  30. GIT_DIR="${basename}" \
  31. ${GIT} archive --prefix="${basename}/" -o "${output}" --format=tar "${cset}"
  32. gzip "${output}"