osmith has uploaded this change for review.

View Change

lint/lint_diff: run clang-format if config was found

The osmo-asf4-dfu and osmo-ccid-firmware now have clang-format configs.
Adjust the lint script to run clang-format if such a config is found in
the repository for which the lint script is running.

Change-Id: Ie210966ebfbada43dd8507b9b48218df4925820d
---
M lint/lint_diff.sh
1 file changed, 20 insertions(+), 0 deletions(-)

git pull ssh://gerrit.osmocom.org:29418/osmo-ci refs/changes/96/39796/1
diff --git a/lint/lint_diff.sh b/lint/lint_diff.sh
index 9458ca7..60fd8b1 100755
--- a/lint/lint_diff.sh
+++ b/lint/lint_diff.sh
@@ -46,6 +46,25 @@
fi
}

+test_clang_format() {
+ if ! [ -e ".clang-format" ] || ! command -v clang-format >/dev/null; then
+ return
+ fi
+
+ echo "Running clang-format on 'git diff $COMMIT'..."
+ echo
+
+ # Run clang-format-diff and colorize its output
+ local diff="$(git diff -U0 --relative "$COMMIT" \
+ | clang-format-diff -p1 \
+ | sed 's/^-/\x1b[41m-/;s/^+/\x1b[42m+/;s/^@/\x1b[34m@/;s/$/\x1b[0m/')"
+
+ if ! [ -z "$diff" ]; then
+ ERROR=1
+ echo "$diff"
+ fi
+}
+
show_error() {
echo
echo "Please fix the linting errors above. More information:"
@@ -86,6 +105,7 @@
set_commit
test_docker_run_rm
test_checkpatch
+test_clang_format

if [ "$ERROR" = 1 ]; then
show_error

To view, visit change 39796. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-MessageType: newchange
Gerrit-Project: osmo-ci
Gerrit-Branch: master
Gerrit-Change-Id: Ie210966ebfbada43dd8507b9b48218df4925820d
Gerrit-Change-Number: 39796
Gerrit-PatchSet: 1
Gerrit-Owner: osmith <osmith@sysmocom.de>