From 3382beadcc047405336e5e0476dfa03c4863497b Mon Sep 17 00:00:00 2001 From: Brian Stinson Date: Apr 16 2019 14:59:13 +0000 Subject: [PATCH 1/5] Get the proper branch name from the remote instead of the local branch name. This allows you to clone a commit directly by its hash, and not be required to set up a tracking branch (with a matching name) to its upstream. --- diff --git a/get_sources.sh b/get_sources.sh index 84e3a8e..44ef936 100755 --- a/get_sources.sh +++ b/get_sources.sh @@ -181,7 +181,7 @@ else else branches=("${branches[@]}" "$branch") fi - done <<< "$(git branch --contains HEAD)" + done <<< "$(git branch -r --contains HEAD | sed 's#origin/##g')" fi while read -r fsha fname ; do if [ ".${fsha}" = ".da39a3ee5e6b4b0d3255bfef95601890afd80709" ]; then From fd37ab58109351a89ff9fcd65edd09486eb221c4 Mon Sep 17 00:00:00 2001 From: Brian Stinson Date: Apr 16 2019 15:03:11 +0000 Subject: [PATCH 2/5] use command instead of which. this is more portable and doesn\'t require another dep --- diff --git a/get_sources.sh b/get_sources.sh index 44ef936..247c43e 100755 --- a/get_sources.sh +++ b/get_sources.sh @@ -102,13 +102,13 @@ else QUIET='' fi -which git >/dev/null 2>&1 +command -v git >/dev/null 2>&1 if [[ $? -ne 0 ]]; then echo 'You need git in PATH' >&2 exit 1 fi -which curl >/dev/null 2>&1 +command -v curl >/dev/null 2>&1 if [[ $? -ne 0 ]]; then echo 'You need curl in PATH' >&2 exit 1 From 9857597bf64b9bca378a9e63929727664f1bebad Mon Sep 17 00:00:00 2001 From: Brian Stinson Date: Apr 16 2019 18:06:51 +0000 Subject: [PATCH 3/5] add some quotes to make shellcheck happier --- diff --git a/get_sources.sh b/get_sources.sh index 247c43e..36d7114 100755 --- a/get_sources.sh +++ b/get_sources.sh @@ -117,7 +117,7 @@ fi # should go into a function section at some point weakHashDetection () { strHash=${1}; - case $((`echo ${strHash}|wc -m` - 1 )) in + case $((`echo "${strHash}"|wc -m` - 1 )) in 128) hashBin='sha512sum' ;; @@ -186,10 +186,10 @@ fi while read -r fsha fname ; do if [ ".${fsha}" = ".da39a3ee5e6b4b0d3255bfef95601890afd80709" ]; then # zero byte file - touch ${fname} + touch "${fname}" else if [ ${CHECK} -eq 1 ]; then - hashType=$(weakHashDetection ${fsha}) + hashType=$(weakHashDetection "${fsha}") if [ "${hashType}" == "unknown" ]; then echo 'Failure: Hash type unknown.' >&2 exit 1; @@ -203,15 +203,15 @@ while read -r fsha fname ; do fi if [ -e ${fname} -a ${CHECK} -eq 1 ]; then # check hash sum and force download if wrong - downsum=$(${hashType} ${fname} | awk '{print $1}') + downsum=$(${hashType} "${fname}" | awk '{print $1}') if [ "${fsha}" != "${downsum}" ]; then - rm -f ${fname} + rm -f "${fname}" fi fi if [ ! -e "${fname}" ]; then for br in "${branches[@]}" do - br=$(echo ${br}| sed -e s'|remotes/origin/||') + br=$(echo "${br}"| sed -e s'|remotes/origin/||') url="${SURL}/${pn}/${br}/${fsha}" echo "Retrieving ${url}" curl -L ${QUIET} -f "${url}" -o "${fname}" && break @@ -220,9 +220,9 @@ while read -r fsha fname ; do echo "${fname} exists. skipping" fi if [ ${CHECK} -eq 1 ]; then - downsum=$(${hashType} ${fname} | awk '{print $1}') + downsum=$(${hashType} "${fname}" | awk '{print $1}') if [ "${fsha}" != "${downsum}" ]; then - rm -f ${fname} + rm -f "${fname}" echo "Failure: ${fname} hash does not match hash from the .metadata file" >&2 exit 1; fi From 7707c61e8348bdbdefacafa4ab8b0e17e427f45c Mon Sep 17 00:00:00 2001 From: Brian Stinson Date: Apr 16 2019 18:10:19 +0000 Subject: [PATCH 4/5] A WHICH! BURN IT --- diff --git a/get_sources.sh b/get_sources.sh index 36d7114..577ac1d 100755 --- a/get_sources.sh +++ b/get_sources.sh @@ -194,7 +194,7 @@ while read -r fsha fname ; do echo 'Failure: Hash type unknown.' >&2 exit 1; else - which ${hashType} >/dev/null 2>&1 + command -v "${hashType}" >/dev/null 2>&1 if [[ $? -ne 0 ]]; then echo "Failure: You need ${hashType} in PATH." >&2 exit 1; From b2f5375fcf160ce6c55f760e488d9f02a605743e Mon Sep 17 00:00:00 2001 From: Brian Stinson Date: Apr 16 2019 18:10:24 +0000 Subject: [PATCH 5/5] add a grep to be sure we only check the origin remote (no forks) --- diff --git a/get_sources.sh b/get_sources.sh index 577ac1d..80c4b53 100755 --- a/get_sources.sh +++ b/get_sources.sh @@ -181,7 +181,7 @@ else else branches=("${branches[@]}" "$branch") fi - done <<< "$(git branch -r --contains HEAD | sed 's#origin/##g')" + done <<< "$(git branch -r --contains HEAD | grep '^\s\+origin/'| sed 's#origin/##g')" fi while read -r fsha fname ; do if [ ".${fsha}" = ".da39a3ee5e6b4b0d3255bfef95601890afd80709" ]; then