summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaxim Kuvyrkov <maxim.kuvyrkov@linaro.org>2021-07-20 08:31:51 +0000
committerMaxim Kuvyrkov <maxim.kuvyrkov@linaro.org>2021-07-20 09:48:33 +0000
commit1ac1a651a54906e23df9fbc7527493050db41998 (patch)
treed2ce1d1e26e333ecb5d3d3893ff075bfae833c55
parent85c1c90af3e827b9d785e65d4828c63a1dc64163 (diff)
downloadjenkins-scripts-1ac1a651a54906e23df9fbc7527493050db41998.tar.gz
jenkins-helpers.sh (git_set_remote): New function
Use it in clone_or_update_repo_no_checkout() and git_init_linaro_local_remote(). Change-Id: Ibc6292eaaa977a20ff8b0604fde2a5011d44d9e2
-rw-r--r--jenkins-helpers.sh53
1 files changed, 32 insertions, 21 deletions
diff --git a/jenkins-helpers.sh b/jenkins-helpers.sh
index 2e8d8ee6..066aacb9 100644
--- a/jenkins-helpers.sh
+++ b/jenkins-helpers.sh
@@ -420,6 +420,26 @@ function run_with_timeout_and_retry {
return ${ret}
}
+# Configure git remote
+# $1: git repo directory
+# $2: remote name
+# $3: git url
+# $4: optional single branch
+git_set_remote ()
+{
+ (
+ set -euf -o pipefail
+
+ local dir="$1"
+ local remote="$2"
+ local url="$3"
+ local single_branch="${4-}"
+
+ git -C "$dir" remote rm "$remote" > /dev/null 2>&1 || true
+ git -C "$dir" remote add ${single_branch:+-t "$single_branch"} "$remote" "$url"
+ )
+}
+
# Clone or update a git repo
# $1 -- repo directory
# $2 -- master git repo
@@ -481,21 +501,16 @@ clone_or_update_repo_no_checkout ()
find "$dir/.git" -name "*.lock" -delete
fi
- (
- cd "$dir"
+ git_set_remote "$dir" "$remote" "$url" "$single_branch"
- # Update from URL.
- git remote rm "$remote" > /dev/null 2>&1 || true
- git remote add ${single_branch:+-t "$single_branch"} "$remote" "$url"
-
- local refspec="+refs/changes/*:refs/changes/*"
- if [ x"$single_branch" = x"" ]; then
- run_with_timeout_and_retry 1h 3 git remote update -p "$remote"
- else
- refspec="+refs/heads/$single_branch:refs/remotes/$remote/$single_branch"
- fi
- run_with_timeout_and_retry 1h 3 git fetch -q $remote $refspec --prune
- )
+ local refspec
+ if [ x"$single_branch" = x"" ]; then
+ run_with_timeout_and_retry 1h 3 git -C "$dir" remote update -p "$remote"
+ refspec="+refs/changes/*:refs/changes/*"
+ else
+ refspec="+refs/heads/$single_branch:refs/remotes/$remote/$single_branch"
+ fi
+ run_with_timeout_and_retry 1h 3 git -C "$dir" fetch -q $remote $refspec --prune
)
}
@@ -1079,7 +1094,7 @@ git_clean () {
)
}
-# Add git remote pointing to linaro's git repo/mirros with writable
+# Add git remote pointing to linaro's git repo/mirrors with writable
# toolchain/ci/* repo. Deduce repo's URL from URL of existing
# "origin" git remote.
# $1: Git clone directory (must have "origin" remote configured)
@@ -1093,10 +1108,9 @@ git_init_linaro_local_remote ()
local remote="$2"
local read_only="$3"
- cd $dir
local origin_url
local new_url
- origin_url=$(git remote get-url origin)
+ origin_url=$(git -C "$dir" remote get-url origin)
# Figure out mirror repo on linaro's servers.
case "$origin_url" in
@@ -1121,10 +1135,7 @@ git_init_linaro_local_remote ()
new_url="ssh://$new_url"
fi
- # Set-url fails if there's no existing remote, so, rather than
- # check-and-add-if-not-present, always add and ignore result.
- git remote add $remote "$new_url" > /dev/null 2>&1 || true
- git remote set-url $remote "$new_url"
+ git_set_remote "$dir" "$remote" "$new_url"
)
}