lin
2025-07-30 fcd736bf35fd93b563e9bbf594f2aa7b62028cc9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/bin/bash
 
# Runs clang-format on the files changed between HEAD and $1, which defaults to
# origin/master.
 
# to pick up git-clang-format from scripts/
export PATH=$(dirname $0):$PATH
 
CLANG_FORMAT=${CLANG_FORMAT:-clang-format}
GITREF=${1:-origin/master}
 
if ! hash $CLANG_FORMAT 2> /dev/null; then
  echo "Could not find clang-format tool" 1>&2
  exit 1
fi
 
cmd="git clang-format $GITREF --binary $CLANG_FORMAT --diff --extensions h,c,cc"
 
n=$($cmd --quiet | wc -l)
if [ $n -gt 0 ]; then
  $cmd -v
  exit 1
fi