diff options
author | Maxim Kuvyrkov <maxim.kuvyrkov@linaro.org> | 2019-04-26 06:51:41 +0000 |
---|---|---|
committer | Maxim Kuvyrkov <maxim.kuvyrkov@linaro.org> | 2019-04-27 08:35:36 +0000 |
commit | 3fffc30738d93d39ac4c58b87ef15fe8ecdfdaf1 (patch) | |
tree | 0a34824530b9b1f6b4bd4f789bb2d99e7dfb0cab /jenkins-helpers.sh | |
parent | b5a392008ec6d9f06e0439002beaeba2f5c78061 (diff) |
jenkins-helpers.sh: Generalize clone_or_update_repo*
... to handle non-origin remotes. This is a prerequisite for
next change.
Change-Id: Ic961c25c089e853f53423eb99dff1036c147baa9
Diffstat (limited to 'jenkins-helpers.sh')
-rw-r--r-- | jenkins-helpers.sh | 37 |
1 files changed, 21 insertions, 16 deletions
diff --git a/jenkins-helpers.sh b/jenkins-helpers.sh index 5f68c9a1..83896600 100644 --- a/jenkins-helpers.sh +++ b/jenkins-helpers.sh @@ -409,6 +409,8 @@ function run_with_timeout_and_retry { # $1 -- repo directory # $2 -- master git repo # $3 -- reference git repo (to speedup initial cloning) +# $4 -- single-branch to reduce fetching from remote repo +# $5 -- name of remote clone_or_update_repo_no_checkout () { ( @@ -418,6 +420,7 @@ clone_or_update_repo_no_checkout () local url="$2" local reference="$3" local single_branch="$4" + local remote="$5" local refopt="" case "$reference" in @@ -465,15 +468,20 @@ clone_or_update_repo_no_checkout () cd "$dir" # Update from URL. - git remote add origin "$url" > /dev/null 2>&1 || true - git remote set-url origin "$url" + git remote add "$remote" "$url" > /dev/null 2>&1 || true + git remote set-url "$remote" "$url" + if [ x"$single_branch" = x"" ]; then + git remote set-branches "$remote" "*" + else + git remote set-branches "$remote" "$single_branch" + fi local refspec="+refs/changes/*:refs/changes/*" if [ x"$single_branch" = x"" ]; then run_with_timeout_and_retry 1h 3 git remote update -p else - refspec="+refs/heads/$single_branch:refs/remotes/origin/$single_branch" + refspec="+refs/heads/$single_branch:refs/remotes/$remote/$single_branch" fi - run_with_timeout_and_retry 1h 3 git fetch -q origin $refspec --prune + run_with_timeout_and_retry 1h 3 git fetch -q $remote $refspec --prune ) ) } @@ -483,30 +491,27 @@ clone_or_update_repo_no_checkout () # $2 -- ref to checkout # $3 -- master git repo # $4 -- optional reference git repo (to speedup initial cloning) +# $5 -- optional single-branch to reduce fetching from remote repo +# $6 -- optional name of remote (default is "origin") clone_or_update_repo () { ( - set -ef -o pipefail + set -euf -o pipefail local dir="$1" local ref="$2" local url="$3" - local reference="auto" - local single_branch="" - - if [ $# -ge 4 ]; then - if [ $# -ge 5 ]; then - single_branch="$5" - fi - reference="$4" - fi + local reference="${4-auto}" + local single_branch="${5-}" + local remote="${6-origin}" - clone_or_update_repo_no_checkout "$dir" "$url" "$reference" "$single_branch" + clone_or_update_repo_no_checkout "$dir" "$url" "$reference" \ + "$single_branch" "$remote" git_clean "$dir" # Convert git branch/tag names into SHA1 local sha1 - sha1=$(git_rev_parse "$dir" "$ref") + sha1=$(git_rev_parse "$dir" "$ref" "$remote") # Checkout git -C "$dir" checkout --detach "$sha1" ) |