whitespace_test revision d8899526551cbfe112e0ecc8280003a8349fc531
2128N/A#!/bin/bash
2128N/A
2128N/Aset -e -u -o pipefail
2128N/A
2128N/A# An AWK regex matching tracked file paths to be excluded from the search.
2128N/A# Example: '.*\.po|README'
2128N/APATH_EXCLUDE_REGEX='.*\.po|.*\.patch|.*\.diff|\/debian\/.*'
2128N/A
2128N/Aexport GIT_DIR="$ABS_TOP_SRCDIR/.git"
2128N/Aexport GIT_WORK_TREE="$ABS_TOP_SRCDIR"
2128N/A
2128N/Aif [ ! -d "$GIT_DIR" ]; then
2128N/A echo "Git repository is required for this test!" 1>&2
2128N/A exit 77
2128N/Afi
2128N/A
2128N/A{
2128N/A # Look for lines with trailing whitespace in all files tracked by Git
2128N/A git grep -n -I '\s\+$' -- "$(git rev-parse --show-toplevel)" ||
2128N/A # Don't fail if no such lines were found anywhere
5680N/A [[ $? == 1 ]]
5680N/A} |
5591N/A awk -- "
2128N/A BEGIN {
5680N/A found = 0
2923N/A }
2128N/A ! /^($PATH_EXCLUDE_REGEX):/ {
2128N/A if (!found) {
2128N/A print \"Trailing whitespace found:\"
6031N/A found = 1
2128N/A }
6031N/A print
5591N/A }
2128N/A END {
2128N/A exit found
2128N/A }
6031N/A "
6031N/A