diff options
author | Junio C Hamano <gitster@pobox.com> | 2024-07-31 22:34:18 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2024-07-31 22:34:18 +0200 |
commit | 468ebc52f3a8221e2f4863e0194059f113618273 (patch) | |
tree | cf3eeeff83ee0a0f03add1a09fd34b45e0b6dfa6 /ci | |
parent | Merge branch 'jc/checkout-no-op-switch-errors' (diff) | |
parent | ci/style-check: add `RemoveBracesLLVM` in CI job (diff) | |
download | git-468ebc52f3a8221e2f4863e0194059f113618273.tar.xz git-468ebc52f3a8221e2f4863e0194059f113618273.zip |
Merge branch 'kn/ci-clang-format'
A CI job that use clang-format to check coding style issues in new
code has been added.
* kn/ci-clang-format:
ci/style-check: add `RemoveBracesLLVM` in CI job
check-whitespace: detect if no base_commit is provided
ci: run style check on GitHub and GitLab
clang-format: formalize some of the spacing rules
clang-format: avoid spacing around bitfield colon
clang-format: indent preprocessor directives after hash
Diffstat (limited to 'ci')
-rwxr-xr-x | ci/check-whitespace.sh | 10 | ||||
-rwxr-xr-x | ci/install-dependencies.sh | 4 | ||||
-rwxr-xr-x | ci/run-style-check.sh | 25 |
3 files changed, 37 insertions, 2 deletions
diff --git a/ci/check-whitespace.sh b/ci/check-whitespace.sh index db399097a5..c40804394c 100755 --- a/ci/check-whitespace.sh +++ b/ci/check-whitespace.sh @@ -9,7 +9,7 @@ baseCommit=$1 outputFile=$2 url=$3 -if test "$#" -ne 1 && test "$#" -ne 3 +if test "$#" -ne 1 && test "$#" -ne 3 || test -z "$1" then echo "USAGE: $0 <BASE_COMMIT> [<OUTPUT_FILE> <URL>]" exit 1 @@ -21,6 +21,12 @@ commitText= commitTextmd= goodParent= +if ! git rev-parse --quiet --verify "${baseCommit}" +then + echo "Invalid <BASE_COMMIT> '${baseCommit}'" + exit 1 +fi + while read dash sha etc do case "${dash}" in @@ -67,7 +73,7 @@ then goodParent=${baseCommit: 0:7} fi - echo "A whitespace issue was found in onen of more of the commits." + echo "A whitespace issue was found in one or more of the commits." echo "Run the following command to resolve whitespace issues:" echo "git rebase --whitespace=fix ${goodParent}" 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..6cd4b1d934 --- /dev/null +++ b/ci/run-style-check.sh @@ -0,0 +1,25 @@ +#!/bin/sh +# +# Perform style check +# + +baseCommit=$1 + +# Remove optional braces of control statements (if, else, for, and while) +# according to the LLVM coding style. This avoids braces on simple +# single-statement bodies of statements but keeps braces if one side of +# if/else if/.../else cascade has multi-statement body. +# +# As this rule comes with a warning [1], we want to experiment with it +# before adding it in-tree. since the CI job for the style check is allowed +# to fail, appending the rule here allows us to validate its efficacy. +# While also ensuring that end-users are not affected directly. +# +# [1]: https://clang.llvm.org/docs/ClangFormatStyleOptions.html#removebracesllvm +{ + cat .clang-format + echo "RemoveBracesLLVM: true" +} >/tmp/clang-format-rules + +git clang-format --style=file:/tmp/clang-format-rules \ + --diff --extensions c,h "$baseCommit" |