]> git.ipfire.org Git - thirdparty/git.git/commit
check-whitespace: detect if no base_commit is provided
authorKarthik Nayak <karthik.188@gmail.com>
Tue, 23 Jul 2024 08:21:10 +0000 (10:21 +0200)
committerJunio C Hamano <gitster@pobox.com>
Tue, 23 Jul 2024 16:56:50 +0000 (09:56 -0700)
commit30c4f7e3504f04496c0475f5c0428b2ee261dce2
treea776562243e9fe7dd607c98ab36e718b46fa6609
parentbce7e52d4e70a8d8d824596654bac85545bf9d07
check-whitespace: detect if no base_commit is provided

The 'check-whitespace' CI script exits gracefully if no base commit is
provided or if an invalid revision is provided. This is not good because
if a particular CI provides an incorrect base_commit, it would fail
successfully.

This is exactly the case with the GitLab CI. The CI is using the
"$CI_MERGE_REQUEST_TARGET_BRANCH_SHA" variable to get the base commit
SHA, but variable is only defined for _merged_ pipelines. So it is empty
for regular pipelines [1]. This should've failed the check-whitespace
job.

Let's fallback to 'CI_MERGE_REQUEST_DIFF_BASE_SHA' if
"CI_MERGE_REQUEST_TARGET_BRANCH_SHA" isn't available in GitLab CI,
similar to the previous commit. Let's also add a check for incorrect
base_commit in the 'check-whitespace.sh' script. While here, fix a small
typo too.

[1]: https://docs.gitlab.com/ee/ci/variables/predefined_variables.html#predefined-variables-for-merge-request-pipelines

Helped-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Karthik Nayak <karthik.188@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
.gitlab-ci.yml
ci/check-whitespace.sh