cpplint_pre_commit.hook 1014 字节
Newer Older
Y
Yi Wang 已提交
1 2 3
#!/bin/bash

TOTAL_ERRORS=0
4 5 6 7 8

readonly VERSION="1.6.0"

version=$(cpplint --version)

T
Tao Luo 已提交
9 10
if [[ ! $TRAVIS_BRANCH ]]; then
  # install cpplint on local machine.
11 12
  if ! [[ $version == *"$VERSION"* ]]; then
    pip install cpplint==1.6.0
T
Tao Luo 已提交
13 14 15 16 17 18 19 20 21
  fi
  # diff files on local machine. 
  files=$(git diff --cached --name-status | awk '$1 != "D" {print $2}')
else
  # diff files between PR and latest commit on Travis CI. 
  branch_ref=$(git rev-parse "$TRAVIS_BRANCH")
  head_ref=$(git rev-parse HEAD)
  files=$(git diff --name-status $branch_ref $head_ref | awk '$1 != "D" {print $2}')
fi
Y
Yi Wang 已提交
22
# The trick to remove deleted files: https://stackoverflow.com/a/2413151
T
Tao Luo 已提交
23
for file in $files; do
24 25
    echo $file
    if [[ $file =~ ^(patches/.*) || $file =~ ^(paddle/fluid/operators/collective/thirdparty/json.h) ]]; then
W
Wu Yi 已提交
26 27
        continue;
    else
28
        cpplint --filter=-readability/fn_size,-build/include_what_you_use,-build/c++11,-whitespace/parens $file;
W
Wu Yi 已提交
29 30
        TOTAL_ERRORS=$(expr $TOTAL_ERRORS + $?);
    fi
Y
Yi Wang 已提交
31 32 33
done

exit $TOTAL_ERRORS