@@ -13,32 +13,41 @@ while getopts "?" opt; do
13
13
case $opt in
14
14
? )
15
15
echo " Usage: $0 [N]"
16
- echo " TRAVIS_COMMIT_RANGE ='<commit range>' $0 "
16
+ echo " COMMIT_RANGE ='<commit range>' $0 "
17
17
echo " $0 -?"
18
18
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 "
20
20
exit 0
21
21
;;
22
22
esac
23
23
done
24
24
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
26
33
if [ -n " $1 " ]; then
27
- TRAVIS_COMMIT_RANGE =" HEAD~$1 ...HEAD"
34
+ COMMIT_RANGE =" HEAD~$1 ...HEAD"
28
35
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"
30
39
fi
31
40
fi
32
41
33
42
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
35
44
echo " Failed to get a diff"
36
45
exit 1
37
46
fi
38
47
}
39
48
40
49
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
42
51
echo " Failed to get a diff"
43
52
exit 1
44
53
fi
0 commit comments