Patrick Georgi | f743728 | 2018-05-24 17:36:41 +0200 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # This file is part of the coreboot project. |
| 3 | # |
| 4 | # Copyright (C) 2018 Google Inc. |
| 5 | # |
| 6 | # This program is free software; you can redistribute it and/or modify |
| 7 | # it under the terms of the GNU General Public License as published by |
| 8 | # the Free Software Foundation; version 2 of the License. |
| 9 | # |
| 10 | # This program is distributed in the hope that it will be useful, |
| 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | # GNU General Public License for more details. |
| 14 | # |
| 15 | # |
| 16 | # DESCR: Run clang-format on white-listed directories |
| 17 | |
| 18 | LC_ALL=C export LC_ALL |
| 19 | |
| 20 | # until we require this by default, we need a list of opted-in directories |
| 21 | if [ ! -f .clang-format-scope ]; then |
| 22 | exit 0 |
| 23 | fi |
| 24 | |
| 25 | files_to_check=$(git log HEAD~..HEAD --format= --name-only $(cat .clang-format-scope) |grep "\.[ch]$") |
| 26 | |
| 27 | # nothing to do |
| 28 | if [ -z "$files_to_check" ]; then |
| 29 | exit 0 |
| 30 | fi |
| 31 | |
| 32 | if [ $(clang-format $files_to_check | wc -l) -gt 0 ]; then |
| 33 | git diff HEAD~..HEAD -- $files_to_check | clang-format-diff |
| 34 | fi |