Skip to content

Commit d37441d

Browse files
committed
refactor options parsing
1 parent c050c4d commit d37441d

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

hooks/checkout

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,22 @@ fi
4343

4444
git clean -ffxdq
4545

46-
# fetch branch if commit is HEAD, respecting BUILDKITE_GIT_FETCH_FLAGS if set
47-
FETCH_FLAGS="${BUILDKITE_GIT_FETCH_FLAGS:-}"
46+
FETCH_FLAGS=()
47+
if [[ -n "${BUILDKITE_GIT_FETCH_FLAGS:-}" ]]; then
48+
# Use read -a to split the flags safely and shellcheck-compliantly
49+
read -r -a FETCH_FLAGS <<< "${BUILDKITE_GIT_FETCH_FLAGS}"
50+
fi
51+
52+
FETCH_FLAGS+=(--depth 1 origin)
53+
4854
if [[ ${BUILDKITE_COMMIT} = "HEAD" ]]; then
49-
git fetch --depth 1 "${FETCH_FLAGS}" origin "${BUILDKITE_BRANCH}"
55+
FETCH_FLAGS+=( "${BUILDKITE_BRANCH}" )
5056
else
51-
git fetch --depth 1 "${FETCH_FLAGS}" origin "${BUILDKITE_COMMIT}"
57+
FETCH_FLAGS+=( "${BUILDKITE_COMMIT}" )
5258
fi
5359

60+
git fetch "${FETCH_FLAGS[@]}"
61+
5462
git sparse-checkout set ${NO_CONE_PARAM:+--no-cone} "${CHECKOUT_PATHS[@]}"
5563
if [[ ${BUILDKITE_COMMIT} = "HEAD" ]]; then
5664
git checkout FETCH_HEAD

0 commit comments

Comments
 (0)