| 1 | #!/bin/bash |
| 2 | # |
| 3 | # SPDX-FileCopyrightText: 2023 Michael Jeanson <mjeanson@efficios.com> |
| 4 | # SPDX-License-Identifier: GPL-2.0-or-later |
| 5 | |
| 6 | set -exu |
| 7 | |
| 8 | print_header() { |
| 9 | set +x |
| 10 | |
| 11 | local message=" $1 " |
| 12 | local message_len |
| 13 | local padding_len |
| 14 | |
| 15 | message_len="${#message}" |
| 16 | padding_len=$(( (80 - (message_len)) / 2 )) |
| 17 | |
| 18 | |
| 19 | printf '\n'; printf -- '#%.0s' {1..80}; printf '\n' |
| 20 | printf -- '-%.0s' {1..80}; printf '\n' |
| 21 | printf -- '#%.0s' $(seq 1 $padding_len); printf '%s' "$message"; printf -- '#%.0s' $(seq 1 $padding_len); printf '\n' |
| 22 | printf -- '-%.0s' {1..80}; printf '\n' |
| 23 | printf -- '#%.0s' {1..80}; printf '\n\n' |
| 24 | |
| 25 | set -x |
| 26 | } |
| 27 | |
| 28 | cd "src/$PROJECT_NAME" |
| 29 | |
| 30 | # Check if the topmost patch is properly formatted |
| 31 | git diff -U0 --no-color --relative HEAD^ | clang-format-diff-14 -p1 -i |
| 32 | |
| 33 | # If the tree has local changes, the formatting was incorrect |
| 34 | GIT_DIFF_OUTPUT=$(git diff) |
| 35 | if [ -n "$GIT_DIFF_OUTPUT" ]; then |
| 36 | print_header "Saving clang-format proposed fixes in clang-format-fixes.diff" |
| 37 | git diff > "$WORKSPACE/clang-format-fixes.diff" |
| 38 | exit 1 |
| 39 | fi |
| 40 | |
| 41 | print_header "clang-format is happy!" |
| 42 | |
| 43 | # EOF |
| 44 | # vim: expandtab tabstop=4 shiftwidth=4 |