diff options
author | Maxim Kuvyrkov <maxim.kuvyrkov@linaro.org> | 2018-11-07 15:25:47 +0000 |
---|---|---|
committer | Maxim Kuvyrkov <maxim.kuvyrkov@linaro.org> | 2018-11-13 08:28:40 +0000 |
commit | 950f62f3bfb1c2c0a3ac138a0ae6b1928c5ca569 (patch) | |
tree | c29cadd98753b80c6218bbed4cc5a78ecba09e64 /jenkins-helpers.sh | |
parent | 6cb21c19ee5d939b7f7a5ed9c6f81c7c6d945b68 (diff) |
jenkins-helpers: Autodetect reference repos in clone_or_update_repo_no_checkout
Change-Id: I2543fd01f5c1238a9a083b1cbc9f181d5a4dc445
Diffstat (limited to 'jenkins-helpers.sh')
-rw-r--r-- | jenkins-helpers.sh | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/jenkins-helpers.sh b/jenkins-helpers.sh index 17388d36..b4f444e5 100644 --- a/jenkins-helpers.sh +++ b/jenkins-helpers.sh @@ -246,11 +246,24 @@ clone_or_update_repo_no_checkout () local dir="$1" local url="$2" - local refopt="" + local reference="$3" - if [ $# -ge 4 ]; then - refopt="--reference $4" - fi + local refopt="" + case "$reference" in + auto) + local ref_dir + for ref_dir in $url $dir; do + ref_dir=$(basename $ref_dir .git) + ref_dir="/home/tcwg-buildslave/snapshots-ref/$ref_dir.git" + if git -C $ref_dir rev-parse --git-dir >/dev/null 2>&1; then + refopt="--reference $ref_dir" + break + fi + done + ;; + none) ;; + *) refopt="--reference $reference" ;; + esac if ! [ -d "$dir/.git" ]; then rm -rf "$dir" @@ -273,7 +286,7 @@ clone_or_update_repo_no_checkout () # $1 -- repo directory # $2 -- ref to checkout # $3 -- master git repo -# $4 -- reference git repo (to speedup initial cloning) +# $4 -- optional reference git repo (to speedup initial cloning) clone_or_update_repo () { ( @@ -282,8 +295,13 @@ clone_or_update_repo () local dir="$1" local ref="$2" local url="$3" + local reference="auto" + + if [ $# -ge 4 ]; then + reference="$4" + fi - set +u; clone_or_update_repo_no_checkout "$dir" "$url" $4; set -u + clone_or_update_repo_no_checkout "$dir" "$url" "$reference" ( cd "$dir" |