Patrick Georgi | f743728 | 2018-05-24 17:36:41 +0200 | [diff] [blame] | 1 | #!/bin/sh |
Patrick Georgi | f743728 | 2018-05-24 17:36:41 +0200 | [diff] [blame] | 2 | # |
Patrick Georgi | 7333a11 | 2020-05-08 20:48:04 +0200 | [diff] [blame] | 3 | # SPDX-License-Identifier: GPL-2.0-only |
| 4 | |
Patrick Georgi | f743728 | 2018-05-24 17:36:41 +0200 | [diff] [blame] | 5 | # DESCR: Run clang-format on white-listed directories |
| 6 | |
| 7 | LC_ALL=C export LC_ALL |
| 8 | |
| 9 | # until we require this by default, we need a list of opted-in directories |
| 10 | if [ ! -f .clang-format-scope ]; then |
| 11 | exit 0 |
| 12 | fi |
| 13 | |
| 14 | files_to_check=$(git log HEAD~..HEAD --format= --name-only $(cat .clang-format-scope) |grep "\.[ch]$") |
| 15 | |
| 16 | # nothing to do |
| 17 | if [ -z "$files_to_check" ]; then |
| 18 | exit 0 |
| 19 | fi |
| 20 | |
| 21 | if [ $(clang-format $files_to_check | wc -l) -gt 0 ]; then |
Patrick Georgi | 2785290 | 2019-02-27 22:02:04 +0100 | [diff] [blame] | 22 | if [ "$(git diff --no-prefix HEAD~..HEAD -- $files_to_check | clang-format-diff)" != "" ]; then |
| 23 | echo "Coding style mismatch. The following patch fixes it:" |
| 24 | git diff --no-prefix HEAD~..HEAD -- $files_to_check | clang-format-diff |
Angel Pons | ce828b6 | 2019-08-31 02:46:42 +0200 | [diff] [blame] | 25 | exit 0 |
Patrick Georgi | 2785290 | 2019-02-27 22:02:04 +0100 | [diff] [blame] | 26 | fi |
Patrick Georgi | f743728 | 2018-05-24 17:36:41 +0200 | [diff] [blame] | 27 | fi |