summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--jenkins-helpers.sh29
-rw-r--r--round-robin.sh3
2 files changed, 24 insertions, 8 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"
)
}
diff --git a/round-robin.sh b/round-robin.sh
index feeafae3..5015c716 100644
--- a/round-robin.sh
+++ b/round-robin.sh
@@ -165,8 +165,7 @@ clone_repo ()
# Allow manifest override
branch="${rr[${project}_rev]-$branch}"
-
- git -C $project checkout --detach "$branch"
+ git_checkout "$project" "$branch" origin
local cur_rev
cur_rev=$(git -C $project rev-parse HEAD)