File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -42,13 +42,23 @@ if [[ ! -d .git ]]; then
4242fi
4343
4444git clean -ffxdq
45- # fetch branch if commit is HEAD
45+
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+
4654if [[ ${BUILDKITE_COMMIT} = " HEAD" ]]; then
47- git fetch --depth 1 origin " ${BUILDKITE_BRANCH} "
55+ FETCH_FLAGS+=( " ${BUILDKITE_BRANCH} " )
4856else
49- git fetch --depth 1 origin " ${BUILDKITE_COMMIT} "
57+ FETCH_FLAGS+=( " ${BUILDKITE_COMMIT} " )
5058fi
5159
60+ git fetch " ${FETCH_FLAGS[@]} "
61+
5262git sparse-checkout set ${NO_CONE_PARAM: +--no-cone} " ${CHECKOUT_PATHS[@]} "
5363if [[ ${BUILDKITE_COMMIT} = " HEAD" ]]; then
5464 git checkout FETCH_HEAD
Original file line number Diff line number Diff line change @@ -80,3 +80,23 @@ setup() {
8080
8181 unstub git
8282}
83+
84+ @test " Respects BUILDKITE_GIT_FETCH_FLAGS in git fetch" {
85+ export BUILDKITE_GIT_FETCH_FLAGS=" --prune --verbose"
86+ export BUILDKITE_COMMIT=" HEAD"
87+ export BUILDKITE_BRANCH=" main"
88+
89+ stub ssh-keyscan " * : echo 'keyscan'"
90+ stub git " clean * : echo 'git clean'"
91+ stub git " fetch --prune --verbose --depth 1 origin * : echo 'git fetch with flags'"
92+ stub git " sparse-checkout set * * : echo 'git sparse-checkout'"
93+ stub git " checkout * : echo 'checkout'"
94+
95+ run " $PWD " /hooks/checkout
96+
97+ assert_success
98+ assert_output --partial ' git fetch with flags'
99+
100+ unstub ssh-keyscan
101+ unstub git
102+ }
You can’t perform that action at this time.
0 commit comments