mirror of
https://github.com/dashpay/dash.git
synced 2024-12-26 20:42:59 +01:00
a53ef19d99
BACKPORT NOTICE There's some difference with original PR but that's not important because we do not actually use travis. The variable TRAVIS_BRANCH would be removed anyway in bitcoin#20697 - let's just skip it for simplicity -------------- a91ab86fae91d416d664d19d2f482a8d19c115a6 lint: Use TRAVIS_BRANCH in lint-git-commit-check.sh (Fabian Jahr) c11dc995c98e908dfd9cea64d4b34329b1dbb5c6 lint: Don't use TRAVIS_COMMIT_RANGE in whitespace linter (Fabian Jahr) 1b41ce8f5f3debae03ca60e4acada14680df9185 lint: Don't use TRAVIS_COMMIT_RANGE for commit-script-check (Fabian Jahr) Pull request description: This is causing problems again, very similar to #19654. UPDATE: This now removes all remaining usages of TRAVIS_COMMIT_RANGE and instead uses TRAVIS_BRANCH for the range, including `lint-git-commit-check` where TRAVIS_COMMIT_RANGE had already been removed. For builds triggered by a pull request, TRAVIS_BRANCH is the name of the branch targeted by the pull request. In the linters there is still a fallback that assumes master as the target branch. ACKs for top commit: sipa: ACK a91ab86fae91d416d664d19d2f482a8d19c115a6. See test I tried in #20075. Tree-SHA512: 1378bdebd5d8787a83fbda5d9999cc9447209423e7f0218fe5eb240e6a32dc1b51d1cd53b4f8cd1f71574d935ac5e22e203dfe09cce17e9976a48416038e1263
116 lines
3.4 KiB
Bash
Executable File
116 lines
3.4 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
#
|
|
# Copyright (c) 2017-2019 The Bitcoin Core developers
|
|
# Distributed under the MIT software license, see the accompanying
|
|
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
#
|
|
# Check for new lines in diff that introduce trailing whitespace.
|
|
|
|
# We can't run this check unless we know the commit range for the PR.
|
|
|
|
export LC_ALL=C
|
|
while getopts "?" opt; do
|
|
case $opt in
|
|
?)
|
|
echo "Usage: $0 [N]"
|
|
echo " COMMIT_RANGE='<commit range>' $0"
|
|
echo " $0 -?"
|
|
echo "Checks unstaged changes, the previous N commits, or a commit range."
|
|
echo "COMMIT_RANGE='47ba2c3...ee50c9e' $0"
|
|
exit 0
|
|
;;
|
|
esac
|
|
done
|
|
|
|
if [ -z "${COMMIT_RANGE}" ]; then
|
|
if [ -n "$1" ]; then
|
|
COMMIT_RANGE="HEAD~$1...HEAD"
|
|
else
|
|
# This assumes that the target branch of the pull request will be develop.
|
|
MERGE_BASE=$(git merge-base HEAD develop)
|
|
COMMIT_RANGE="$MERGE_BASE..HEAD"
|
|
fi
|
|
fi
|
|
|
|
showdiff() {
|
|
if ! git diff -U0 "${COMMIT_RANGE}" -- "." ":(exclude)depends/patches/" ":(exclude)contrib/guix/patches/" ":(exclude)src/dashbls/" ":(exclude)src/util/expected.h" ":(exclude)src/immer/" ":(exclude)src/leveldb/" ":(exclude)src/crc32c/" ":(exclude)src/secp256k1/" ":(exclude)src/univalue/" ":(exclude)doc/release-notes/"; then
|
|
echo "Failed to get a diff"
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
showcodediff() {
|
|
if ! git diff -U0 "${COMMIT_RANGE}" -- *.cpp *.h *.md *.py *.sh ":(exclude)src/dashbls/" ":(exclude)src/util/expected.h" ":(exclude)src/immer/" ":(exclude)src/leveldb/" ":(exclude)src/crc32c/" ":(exclude)src/secp256k1/" ":(exclude)src/univalue/" ":(exclude)doc/release-notes/"; then
|
|
echo "Failed to get a diff"
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
RET=0
|
|
|
|
# Check if trailing whitespace was found in the diff.
|
|
if showdiff | grep -E -q '^\+.*\s+$'; then
|
|
echo "This diff appears to have added new lines with trailing whitespace."
|
|
echo "The following changes were suspected:"
|
|
FILENAME=""
|
|
SEEN=0
|
|
SEENLN=0
|
|
while read -r line; do
|
|
if [[ "$line" =~ ^diff ]]; then
|
|
FILENAME="$line"
|
|
SEEN=0
|
|
elif [[ "$line" =~ ^@@ ]]; then
|
|
LINENUMBER="$line"
|
|
SEENLN=0
|
|
else
|
|
if [ "$SEEN" -eq 0 ]; then
|
|
# The first time a file is seen with trailing whitespace, we print the
|
|
# filename (preceded by a newline).
|
|
echo
|
|
echo "$FILENAME"
|
|
SEEN=1
|
|
fi
|
|
if [ "$SEENLN" -eq 0 ]; then
|
|
echo "$LINENUMBER"
|
|
SEENLN=1
|
|
fi
|
|
echo "$line"
|
|
fi
|
|
done < <(showdiff | grep -E '^(diff --git |@@|\+.*\s+$)')
|
|
RET=1
|
|
fi
|
|
|
|
# Check if tab characters were found in the diff.
|
|
if showcodediff | perl -nle '$MATCH++ if m{^\+.*\t}; END{exit 1 unless $MATCH>0}' > /dev/null; then
|
|
echo "This diff appears to have added new lines with tab characters instead of spaces."
|
|
echo "The following changes were suspected:"
|
|
FILENAME=""
|
|
SEEN=0
|
|
SEENLN=0
|
|
while read -r line; do
|
|
if [[ "$line" =~ ^diff ]]; then
|
|
FILENAME="$line"
|
|
SEEN=0
|
|
elif [[ "$line" =~ ^@@ ]]; then
|
|
LINENUMBER="$line"
|
|
SEENLN=0
|
|
else
|
|
if [ "$SEEN" -eq 0 ]; then
|
|
# The first time a file is seen with a tab character, we print the
|
|
# filename (preceded by a newline).
|
|
echo
|
|
echo "$FILENAME"
|
|
SEEN=1
|
|
fi
|
|
if [ "$SEENLN" -eq 0 ]; then
|
|
echo "$LINENUMBER"
|
|
SEENLN=1
|
|
fi
|
|
echo "$line"
|
|
fi
|
|
done < <(showcodediff | perl -nle 'print if m{^(diff --git |@@|\+.*\t)}')
|
|
RET=1
|
|
fi
|
|
|
|
exit $RET
|