Commit d04cce68 authored by Felipe Lema's avatar Felipe Lema
Browse files

run `git clang-format` to suggest changes on diff

`git-clang-format` will suggest changes on diff lines, rather than on
the whole file

the last block prints the diff so contributors can apply it to their
code locally
parent 310da736
Pipeline #70885 passed with stage
in 1 minute and 4 seconds
#!/bin/bash -fxv
set -e
# download .clang-format into current directory
wget -c --output-document=.clang-format
git diff-tree --no-commit-id --name-only -r origin/$CI_MERGE_REQUEST_TARGET_BRANCH_NAME -r $CI_COMMIT_SHA -- \
| grep -P '[.](c|cc|cpp|hpp|h)$' \
| xargs --no-run-if-empty --verbose clang-format-11 --dry-run -Werror
# format source code inline
git clang-format-11 $(git merge-base origin/$CI_MERGE_REQUEST_TARGET_BRANCH_NAME $CI_COMMIT_SHA)
# if files were modified, then print the diff modified that would make the proper format
if !git diff-index --quiet HEAD; then
echo '*** Suggested changes to comply with KDE code conventions are below'
echo 'You can copy below this empty line, save the content to a format.diff file, then do `apply format.diff`'
echo ''
git --no-pager diff -U0
exit 1
exit 0
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment