jjb: lttng-tools/babeltrace: smokebuild proof-of-concept
[lttng-ci.git] / scripts / common / check-format.sh
CommitLineData
1ad4c3d0
MJ
1#!/bin/bash
2# SPDX-FileCopyrightText: 2023 Michael Jeanson <mjeanson@efficios.com>
3# SPDX-License-Identifier: GPL-2.0-or-later
4
5set -exu
6
7print_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
27cd "src/$PROJECT_NAME"
28
29# Check if the topmost patch is properly formatted
30git diff -U0 --no-color --relative HEAD^ | clang-format-diff-14 -p1 -i
31
32# If the tree has local changes, the formatting was incorrect
33GIT_DIFF_OUTPUT=$(git diff)
34if [ -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
38fi
39
40print_header "clang-format is happy!"
41# EOF
This page took 0.023705 seconds and 4 git commands to generate.