Skip to content

Commit c11dc99

Browse files
committed
lint: Don't use TRAVIS_COMMIT_RANGE in whitespace linter
1 parent 1b41ce8 commit c11dc99

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

test/lint/lint-whitespace.sh

+16-7
Original file line numberDiff line numberDiff line change
@@ -13,32 +13,41 @@ while getopts "?" opt; do
1313
case $opt in
1414
?)
1515
echo "Usage: $0 [N]"
16-
echo " TRAVIS_COMMIT_RANGE='<commit range>' $0"
16+
echo " COMMIT_RANGE='<commit range>' $0"
1717
echo " $0 -?"
1818
echo "Checks unstaged changes, the previous N commits, or a commit range."
19-
echo "TRAVIS_COMMIT_RANGE='47ba2c3...ee50c9e' $0"
19+
echo "COMMIT_RANGE='47ba2c3...ee50c9e' $0"
2020
exit 0
2121
;;
2222
esac
2323
done
2424

25-
if [ -z "${TRAVIS_COMMIT_RANGE}" ]; then
25+
# TRAVIS_BRANCH will be present in a Travis environment. For builds triggered
26+
# by a pull request this is the name of the branch targeted by the pull request.
27+
# https://docs.travis-ci.com/user/environment-variables/
28+
if [ -n "${TRAVIS_BRANCH}" ]; then
29+
COMMIT_RANGE="$TRAVIS_BRANCH..HEAD"
30+
fi
31+
32+
if [ -z "${COMMIT_RANGE}" ]; then
2633
if [ -n "$1" ]; then
27-
TRAVIS_COMMIT_RANGE="HEAD~$1...HEAD"
34+
COMMIT_RANGE="HEAD~$1...HEAD"
2835
else
29-
TRAVIS_COMMIT_RANGE="HEAD"
36+
# This assumes that the target branch of the pull request will be master.
37+
MERGE_BASE=$(git merge-base HEAD master)
38+
COMMIT_RANGE="$MERGE_BASE..HEAD"
3039
fi
3140
fi
3241

3342
showdiff() {
34-
if ! git diff -U0 "${TRAVIS_COMMIT_RANGE}" -- "." ":(exclude)depends/patches/" ":(exclude)src/leveldb/" ":(exclude)src/crc32c/" ":(exclude)src/secp256k1/" ":(exclude)src/univalue/" ":(exclude)doc/release-notes/" ":(exclude)src/qt/locale/"; then
43+
if ! git diff -U0 "${COMMIT_RANGE}" -- "." ":(exclude)depends/patches/" ":(exclude)src/leveldb/" ":(exclude)src/crc32c/" ":(exclude)src/secp256k1/" ":(exclude)src/univalue/" ":(exclude)doc/release-notes/" ":(exclude)src/qt/locale/"; then
3544
echo "Failed to get a diff"
3645
exit 1
3746
fi
3847
}
3948

4049
showcodediff() {
41-
if ! git diff -U0 "${TRAVIS_COMMIT_RANGE}" -- *.cpp *.h *.md *.py *.sh ":(exclude)src/leveldb/" ":(exclude)src/crc32c/" ":(exclude)src/secp256k1/" ":(exclude)src/univalue/" ":(exclude)doc/release-notes/" ":(exclude)src/qt/locale/"; then
50+
if ! git diff -U0 "${COMMIT_RANGE}" -- *.cpp *.h *.md *.py *.sh ":(exclude)src/leveldb/" ":(exclude)src/crc32c/" ":(exclude)src/secp256k1/" ":(exclude)src/univalue/" ":(exclude)doc/release-notes/" ":(exclude)src/qt/locale/"; then
4251
echo "Failed to get a diff"
4352
exit 1
4453
fi

0 commit comments

Comments
 (0)