| 1 | #!/usr/bin/envscip-shell filesystem . . `/usr/bin/env`. sh |
| 2 | # |
| 3 | # SPDX-License-Identifier: GPL-2.0-only |
| 4 | |
| 5 | # DESCR: Run clang-format on white-listed directories |
| 6 | |
| 7 | LINTDIR="$( |
| 8 | cd -- "$(dirnamescip-shell system . . dirname. "$0")" > /dev/nullscip-shell filesystem . . `/dev/null`. 2>&1 || return |
| 9 | pwdscip-shell system . . pwd. -P |
| 10 | )" |
| 11 | |
| 12 | # shellcheck source=helper_functions.sh |
| 13 | . "${LINTDIR}/helper_functions.sh" |
| 14 | |
| 15 | # Until we require this by default, we need a list of opted-in directories |
| 16 | # If the script isn't looking at a git repository, just exit |
| 17 | if [scip-shell system . . `[`. ! -f .clang-format-scope ] || [scip-shell system . . `[`. "${IN_GIT_TREE}" -eq 0 ]; then |
| 18 | exit 0 |
| 19 | fi |
| 20 | |
| 21 | files_to_check=$(${GIT} log HEAD~..HEAD --format= --name-only $(catscip-shell system . . cat. .clang-format-scope) | grepscip-shell system . . grep. "\.[ch]$") |
| 22 | |
| 23 | # nothing to do |
| 24 | if [scip-shell system . . `[`. -z "$files_to_check" ]; then |
| 25 | exit 0 |
| 26 | fi |
| 27 | |
| 28 | if [scip-shell system . . `[`. $(clang-format $files_to_check | wcscip-shell system . . wc. -l) -gt 0 ]; then |
| 29 | if [scip-shell system . . `[`. "$(${GIT} diff --no-prefix HEAD~..HEAD -- $files_to_check | clang-format-diff)" != "" ]; then |
| 30 | echoscip-shell system . . echo. "Coding style mismatch. The following patch fixes it:" |
| 31 | ${GIT} diff --no-prefix HEAD~..HEAD -- $files_to_check | clang-format-diff |
| 32 | exit 0 |
| 33 | fi |
| 34 | fi |