Skip to content

Commit acc4fb3

Browse files
jltoblergitster
authored andcommitted
ci: fix base commit fallback for check-whitespace and check-style
The check-whitespace and check-style CI scripts require a base commit. In GitLab CI, the base commit can be provided by several different predefined CI variables depending on the type of pipeline being performed. In 30c4f7e (check-whitespace: detect if no base_commit is provided, 2024-07-23), the GitLab check-whitespace CI job was modified to support CI_MERGE_REQUEST_DIFF_BASE_SHA as a fallback base commit if CI_MERGE_REQUEST_TARGET_BRANCH_SHA was not provided. The same fallback strategy was also implemented for the GitLab check-style CI job in bce7e52 (ci: run style check on GitHub and GitLab, 2024-07-23). The base commit fallback is implemented using shell parameter expansion where, if the first variable is unset, the second variable is used as fallback. In GitLab CI, these variables can be set but null. This has the unintended effect of selecting an empty first variable which results in CI jobs providing an invalid base commit and failing. Fix the issue by defaulting to the fallback variable if the first is unset or null. Signed-off-by: Justin Tobler <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f93ff17 commit acc4fb3

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

.gitlab-ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ check-whitespace:
183183
# be defined in all pipelines.
184184
script:
185185
- |
186-
R=${CI_MERGE_REQUEST_TARGET_BRANCH_SHA-${CI_MERGE_REQUEST_DIFF_BASE_SHA:?}} || exit
186+
R=${CI_MERGE_REQUEST_TARGET_BRANCH_SHA:-${CI_MERGE_REQUEST_DIFF_BASE_SHA:?}} || exit
187187
./ci/check-whitespace.sh "$R"
188188
rules:
189189
- if: $CI_PIPELINE_SOURCE == 'merge_request_event'
@@ -203,7 +203,7 @@ check-style:
203203
# be defined in all pipelines.
204204
script:
205205
- |
206-
R=${CI_MERGE_REQUEST_TARGET_BRANCH_SHA-${CI_MERGE_REQUEST_DIFF_BASE_SHA:?}} || exit
206+
R=${CI_MERGE_REQUEST_TARGET_BRANCH_SHA:-${CI_MERGE_REQUEST_DIFF_BASE_SHA:?}} || exit
207207
./ci/run-style-check.sh "$R"
208208
rules:
209209
- if: $CI_PIPELINE_SOURCE == 'merge_request_event'

0 commit comments

Comments
 (0)