3 # Copyright (c) 2017 The Bitcoin Core developers
4 # Distributed under the MIT software license, see the accompanying
5 # file COPYING or http://www.opensource.org/licenses/mit-license.php.
7 # Check for new lines in diff that introduce trailing whitespace.
9 # We can't run this check unless we know the commit range for the PR.
10 if [ -z "${TRAVIS_COMMIT_RANGE}" ]; then
11 echo "Cannot run lint-whitespace.sh without commit range. To run locally, use:"
12 echo "TRAVIS_COMMIT_RANGE='<commit range>' .lint-whitespace.sh"
14 echo "TRAVIS_COMMIT_RANGE='47ba2c3...ee50c9e' .lint-whitespace.sh"
19 if ! git
diff -U0 "${TRAVIS_COMMIT_RANGE}" -- "." ":(exclude)src/leveldb/" ":(exclude)src/secp256k1/" ":(exclude)src/univalue/"; then
20 echo "Failed to get a diff"
26 if ! git
diff -U0 "${TRAVIS_COMMIT_RANGE}" -- *.cpp
*.h
*.md
*.py
*.sh
":(exclude)src/leveldb/" ":(exclude)src/secp256k1/" ":(exclude)src/univalue/"; then
27 echo "Failed to get a diff"
34 # Check if trailing whitespace was found in the diff.
35 if showdiff |
grep -E -q '^\+.*\s+$'; then
36 echo "This diff appears to have added new lines with trailing whitespace."
37 echo "The following changes were suspected:"
40 while read -r line
; do
41 if [[ "$line" =~ ^
diff ]]; then
44 elif [[ "$line" =~ ^@@
]]; then
47 if [ "$SEEN" -eq 0 ]; then
48 # The first time a file is seen with trailing whitespace, we print the
49 # filename (preceded by a newline).
57 done < <(showdiff |
grep -E '^(diff --git |@@|\+.*\s+$)')
61 # Check if tab characters were found in the diff.
62 if showcodediff |
grep -P -q '^\+.*\t'; then
63 echo "This diff appears to have added new lines with tab characters instead of spaces."
64 echo "The following changes were suspected:"
67 while read -r line
; do
68 if [[ "$line" =~ ^
diff ]]; then
71 elif [[ "$line" =~ ^@@
]]; then
74 if [ "$SEEN" -eq 0 ]; then
75 # The first time a file is seen with a tab character, we print the
76 # filename (preceded by a newline).
84 done < <(showcodediff |
grep -P '^(diff --git |@@|\+.*\t)')