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