cpplint_pre_commit.hook 800 字节
Newer Older
C
Channingss 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
#!/bin/bash

TOTAL_ERRORS=0
if [[ ! $TRAVIS_BRANCH ]]; then
  # install cpplint on local machine.
  if [[ ! $(which cpplint) ]]; then
    pip install cpplint
  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
# The trick to remove deleted files: https://stackoverflow.com/a/2413151
for file in $files; do
    if [[ $file =~ ^(patches/.*) ]]; then
        continue;
    else
        cpplint --filter=-readability/fn_size $file;
        TOTAL_ERRORS=$(expr $TOTAL_ERRORS + $?);
    fi
done

exit $TOTAL_ERRORS