From f95b34d52fb2ff58cddbc426f8f008f83734f96f Mon Sep 17 00:00:00 2001 From: Ray Donnelly Date: Sun, 11 Jan 2015 23:04:05 +0000 Subject: CT_GetGit: Allow cset to be a ref (branch or tag) Pass cset as ref=somename to use this feature. CT_GetGit echos the cset sha1 on exit since the caller will need to know that information as it forms part of the downloaded tarball name. Signed-off-by: Ray Donnelly diff --git a/scripts/functions b/scripts/functions index cd3d446..06b4769 100644 --- a/scripts/functions +++ b/scripts/functions @@ -832,18 +832,43 @@ CT_GetSVN() { # Prerequisites: either the server does not require password, # or the user has already taken any action to authenticate to the server. # The cloned tree will *not* be stored in the local tarballs dir! -# Usage: CT_GetGit +# cset_or_ref can be a branch or tag, if specified as 'ref=name' +# In this case, 'git ls-remote' is used to get the sha1 and can also +# be used to get a list valid refs (e.g. HEAD, refs/heads/master, refs/tags/v3.3.0) +# Usage: CT_GetGit CT_GetGit() { local basename="${1}" - local cset="${2}" + local cset_or_ref="${2}" local url="${3}" - local file="${basename}-${cset}.tar.gz" + local _out_cset="${4}" + + local ref=$(echo "${cset_or_ref}" | sed -n 's/^ref=\(.*\)/\1/p') + if [ -n "$ref" ]; then + local matches=$(git ls-remote --exit-code "$url" --refs "${ref}") + local result=$? + CT_TestAndAbort "Failed to find git ref ${ref} at ${url}" "${result}" != "0" + if [ $( echo "$matches" | wc -l) -gt 1 ]; then + CT_DoLog WARN "Ambiguous ref ${ref} at ${url}, using first" + fi + local cset=$(echo "$matches" | head -n1 | cut -c1-6) + CT_DoLog INFO "ref ${ref} at ${url} has cset of ${cset}" + else + local cset=${cset_or_ref} + CT_DoLog INFO "cset ${cset}" + fi + + if [ -n "${_out_cset}" ]; then + eval ${_out_cset}=\${cset} + fi + local dir="${CT_TARBALLS_DIR}/${basename}-${cset}.git" + local file="${basename}-${cset}.tar.gz" local dest="${CT_TARBALLS_DIR}/${file}" local tmp="${CT_TARBALLS_DIR}/${file}.tmp-dl" - # Do we alreadyhave it? + # Do we already have it? if CT_GetLocal "${file}"; then + echo ${cset} return 0 fi # Nope... @@ -877,6 +902,8 @@ CT_GetGit() { CT_SaveLocal "${dest}" CT_DoExecLog ALL rm -rf "${tmp}.tar.gz" "${tmp}.tar" "${tmp}" "${dir}" CT_Popd + echo ${cset} + return 0 else # Woops... CT_DoExecLog ALL rm -rf "${dir}" -- cgit v0.10.2-6-g49f6