summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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"
)
}