From: Junio C Hamano Date: Thu, 18 Jul 2024 14:56:12 GMT Subject: Re: [PATCH v5 4/6] ci: run style check on GitHub and GitLab Message-ID: In-Reply-To: <20240718081605.452366-5-karthik.188@gmail.com> Karthik Nayak writes: > + # Since $CI_MERGE_REQUEST_TARGET_BRANCH_SHA is only defined for merged > + # pipelines, we fallback to $CI_MERGE_REQUEST_DIFF_BASE_SHA, which should > + # be defined in all pipelines. > + script: > + - | > + R=${CI_MERGE_REQUEST_TARGET_BRANCH_SHA-${CI_MERGE_REQUEST_DIFF_BASE_SHA?}} > + > + if test -z "$R" > + then > + echo "CI_MERGE_REQUEST_DIFF_BASE_SHA should always exist!" > + exit 1 > + fi If you update the assignment to R to R=${CI_MERGE_REQUEST_TARGET_BRANCH_SHA-${CI_MERGE_REQUEST_DIFF_BASE_SHA:?}} an unset CI_MERGE_REQUEST_DIFF_BASE_SHA1 or an empty value in it will be rejected there. Then you can lose the if/then/fi here. > + ./ci/run-style-check.sh "$R" > + rules: > + - if: $CI_PIPELINE_SOURCE == 'merge_request_event' > + > documentation: > image: ubuntu:latest > variables: > diff --git a/ci/install-dependencies.sh b/ci/install-dependencies.sh > index 6ec0f85972..fb34ced8f0 100755 > --- a/ci/install-dependencies.sh > +++ b/ci/install-dependencies.sh > @@ -87,6 +87,10 @@ macos-*) > esac > > case "$jobname" in > +ClangFormat) > + sudo apt-get -q update > + sudo apt-get -q -y install clang-format > + ;; > StaticAnalysis) > sudo apt-get -q update > sudo apt-get -q -y install coccinelle libcurl4-openssl-dev libssl-dev \ > diff --git a/ci/run-style-check.sh b/ci/run-style-check.sh > new file mode 100755 > index 0000000000..76dd37d22b > --- /dev/null > +++ b/ci/run-style-check.sh > @@ -0,0 +1,8 @@ > +#!/bin/sh > +# > +# Perform style check > +# > + > +baseCommit=$1 > + > +git clang-format --style file --diff --extensions c,h "$baseCommit"