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