diff --git a/tools/distrib/check_trailing_newlines.sh b/tools/distrib/check_trailing_newlines.sh index 21e194097a1..9d139d73876 100755 --- a/tools/distrib/check_trailing_newlines.sh +++ b/tools/distrib/check_trailing_newlines.sh @@ -17,25 +17,19 @@ cd $(dirname $0)/../.. function find_without_newline() { - find . -type f -not -path './third_party/*' -and \( \ - -name '*.c' \ - -or -name '*.cc' \ - -or -name '*.proto' \ - -or -name '*.rb' \ - -or -name '*.py' \ - -or -name '*.cs' \ - -or -name '*.sh' \) -print0 \ - | while IFS= read -r -d '' f; do - if [[ ! -z $f ]]; then - if [[ $(tail -c 1 "$f") != $NEWLINE ]]; then - echo "Error: file '$f' is missing a trailing newline character." - if $1; then # fix - sed -i -e '$a\' $f - echo 'Fixed!' + git ls-files | + sed -En -e '/^third_party/d' -e '/\.(c|cc|proto|rb|py|cs|sh)$/p' | + while IFS= read -r -d '' f; do + if [[ ! -z $f ]]; then + if [[ $(tail -c 1 "$f") != $NEWLINE ]]; then + echo "Error: file '$f' is missing a trailing newline character." + if $1; then # fix + sed -i -e '$a\' $f + echo 'Fixed!' + fi fi fi - fi - done + done } if [[ $# == 1 && $1 == '--fix' ]]; then