summaryrefslogtreecommitdiff
path: root/jenkins-helpers.sh
diff options
context:
space:
mode:
authorMaxim Kuvyrkov <maxim.kuvyrkov@linaro.org>2021-07-26 10:29:25 +0000
committerMaxim Kuvyrkov <maxim.kuvyrkov@linaro.org>2021-07-26 10:29:25 +0000
commitfb7852bee8f941240b046236188fbebc759cf2a5 (patch)
treec8168711e039314f9823b46c00e773f8d769a976 /jenkins-helpers.sh
parent268e16e2ba1eaef8e211d6a0728c92f8cbde14c0 (diff)
round-robin.sh (clone_repo): Fix checkout of branches
Change-Id: I750be137aa978be5334bdce258d674804650c6da
Diffstat (limited to 'jenkins-helpers.sh')
-rw-r--r--jenkins-helpers.sh29
1 files changed, 23 insertions, 6 deletions
diff --git a/jenkins-helpers.sh b/jenkins-helpers.sh
index 7feb3edf..771ace4b 100644
--- a/jenkins-helpers.sh
+++ b/jenkins-helpers.sh
@@ -514,6 +514,28 @@ clone_or_update_repo_no_checkout ()
)
}
+# Checkout branch/ref/SHA1 in a git repo
+# $1 -- repo directory
+# $2 -- ref to checkout
+# $3 -- name of the git remote
+git_checkout ()
+{
+ (
+ set -euf -o pipefail
+
+ local dir="$1"
+ local ref="$2"
+ local remote="$3"
+
+ git_clean "$dir"
+ # Convert git branch/tag names into SHA1
+ local sha1
+ sha1=$(git_rev_parse "$dir" "$ref" "$remote")
+ # Checkout
+ git -C "$dir" checkout --detach "$sha1"
+ )
+}
+
# Clone or update a git repo
# $1 -- repo directory
# $2 -- ref to checkout
@@ -536,12 +558,7 @@ clone_or_update_repo ()
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" "$remote")
- # Checkout
- git -C "$dir" checkout --detach "$sha1"
+ git_checkout "$dir" "$ref" "$remote"
)
}