blob: 932d9c0d506411081d69ab49160fb54a6c04d69d [file] [log] [blame]
Patrick Georgif7437282018-05-24 17:36:41 +02001#!/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
18LC_ALL=C export LC_ALL
19
20# until we require this by default, we need a list of opted-in directories
21if [ ! -f .clang-format-scope ]; then
22 exit 0
23fi
24
25files_to_check=$(git log HEAD~..HEAD --format= --name-only $(cat .clang-format-scope) |grep "\.[ch]$")
26
27# nothing to do
28if [ -z "$files_to_check" ]; then
29 exit 0
30fi
31
32if [ $(clang-format $files_to_check | wc -l) -gt 0 ]; then
33 git diff HEAD~..HEAD -- $files_to_check | clang-format-diff
34fi