@@ -21,12 +21,23 @@ shopt -s globstar
2121
2222DIFF_FROM=" "
2323
24- # `--only-diff-master will only run tests on project changes from the master branch.
24+ # `--only-diff-master` will only run tests on project changes on the
25+ # last common commit from the master branch.
2526if [[ $* == * --only-diff-master* ]]; then
26- DIFF_FROM=" origin/master.."
27+ set +e
28+ git diff --quiet " origin/master..." .kokoro/tests .kokoro/docker \
29+ .kokoro/trampoline_v2.sh
30+ CHANGED=$?
31+ set -e
32+ if [[ " ${CHANGED} " -eq 0 ]]; then
33+ DIFF_FROM=" origin/master..."
34+ else
35+ echo " Changes to test driver files detected. Running full tests."
36+ fi
2737fi
2838
29- # `--only-diff-master will only run tests on project changes from the previous commit.
39+ # `--only-diff-head` will only run tests on project changes from the
40+ # previous commit.
3041if [[ $* == * --only-diff-head* ]]; then
3142 DIFF_FROM=" HEAD~.."
3243fi
@@ -83,16 +94,6 @@ set +e
8394RTN=0
8495ROOT=$( pwd)
8596
86- # If some files in .kokoro directory have any changes, we will test everything.
87- test_all=" true"
88- if [[ -n " ${DIFF_FROM:- } " ]]; then
89- git diff --quiet " $DIFF_FROM " .kokoro/docker .kokoro/tests
90- CHANGED=$?
91- if [[ " $CHANGED " -eq 0 ]]; then
92- test_all=" false"
93- fi
94- fi
95-
9697# Find all requirements.txt in the repository (may break on whitespace).
9798for file in ** /requirements.txt; do
9899 cd " $ROOT "
@@ -131,7 +132,7 @@ for file in **/requirements.txt; do
131132 fi
132133 fi
133134 # If $DIFF_FROM is set, use it to check for changes in this directory.
134- if [[ -n " ${DIFF_FROM:- } " ]] && [[ " ${test_all} " == " false " ]] ; then
135+ if [[ -n " ${DIFF_FROM:- } " ]]; then
135136 git diff --quiet " $DIFF_FROM " .
136137 CHANGED=$?
137138 if [[ " $CHANGED " -eq 0 ]]; then
0 commit comments