@@ -84,6 +84,7 @@ cd "${top_dir}"
84
84
85
85
ALLOW_DIRTY=false
86
86
COMMIT_METHOD=" none"
87
+ CHECK_DIFF=false
87
88
START_REVISION=" origin/master"
88
89
TEST_ONLY=false
89
90
VERBOSE=false
98
99
# is not available and we need to compute the START_REVISION from the common
99
100
# ancestor of $TRAVIS_COMMIT and origin/master.
100
101
if [[ -n " ${TRAVIS_COMMIT_RANGE:- } " ]] ; then
102
+ CHECK_DIFF=true
101
103
START_REVISION=" $TRAVIS_COMMIT_RANGE "
102
104
elif [[ -n " ${TRAVIS_COMMIT:- } " ]] ; then
103
105
if ! git rev-parse origin/master >& /dev/null; then
104
106
git remote set-branches --add origin master
105
107
git fetch origin
106
108
fi
109
+ CHECK_DIFF=true
107
110
START_REVISION=$( git merge-base origin/master " ${TRAVIS_COMMIT} " )
108
111
fi
109
112
@@ -146,6 +149,7 @@ while [[ $# -gt 0 ]]; do
146
149
;;
147
150
148
151
* )
152
+ CHECK_DIFF=true
149
153
START_REVISION=" $1 "
150
154
shift
151
155
break
@@ -187,9 +191,24 @@ if [[ "${START_REVISION}" == *..* ]]; then
187
191
git fetch origin
188
192
fi
189
193
190
- NEW_RANGE_START=$( git merge-base origin/master " ${RANGE_END} " )
191
- START_REVISION=" ${START_REVISION/ $RANGE_START / $NEW_RANGE_START } "
192
- START_SHA=" ${START_REVISION} "
194
+ # Try to come up with a more accurate representation of the merge, so that
195
+ # checks will operate on just the differences the PR would merge into master.
196
+ # The start of the revision range that Travis supplies can sometimes be a
197
+ # seemingly random value.
198
+ NEW_RANGE_START=$( git merge-base origin/master " ${RANGE_END} " || echo " " )
199
+ if [[ -n " $NEW_RANGE_START " ]]; then
200
+ START_REVISION=" ${NEW_RANGE_START} ..${RANGE_END} "
201
+ START_SHA=" ${START_REVISION} "
202
+ else
203
+ # In the shallow clone that Travis has created there's no merge base
204
+ # between the PR and master. In this case just fall back on checking
205
+ # everything.
206
+ echo " Unable to detect base commit for change detection."
207
+ echo " Failling back on just checking everything."
208
+ CHECK_DIFF=false
209
+ START_REVISION=" origin/master"
210
+ START_SHA=" origin/master"
211
+ fi
193
212
194
213
else
195
214
START_SHA=$( git rev-parse " ${START_REVISION} " )
@@ -236,7 +255,9 @@ style_cmd=("${top_dir}/scripts/style.sh")
236
255
if [[ " ${TEST_ONLY} " == true ]]; then
237
256
style_cmd+=(test-only)
238
257
fi
239
- style_cmd+=(" ${START_SHA} " )
258
+ if [[ " $CHECK_DIFF " == true ]]; then
259
+ style_cmd+=(" ${START_SHA} " )
260
+ fi
240
261
241
262
# Restyle and commit any changes
242
263
" ${style_cmd[@]} "
247
268
# If there are changes to the Firestore project, ensure they're ordered
248
269
# correctly to minimize conflicts.
249
270
if [ -z " ${GITHUB_WORKFLOW-} " ]; then
250
- if ! git diff --quiet " ${START_SHA} " -- Firestore; then
271
+ if [[ " $CHECK_DIFF " == " false" ]] || \
272
+ ! git diff --quiet " ${START_SHA} " -- Firestore; then
273
+
251
274
sync_project_cmd=(" ${top_dir} /scripts/sync_project.rb" )
252
275
if [[ " ${TEST_ONLY} " == true ]]; then
253
276
sync_project_cmd+=(--test-only)
268
291
" ${top_dir} /scripts/check_cmake_files.py"
269
292
270
293
# Google C++ style
271
- " ${top_dir} /scripts/check_lint.py" " ${START_SHA} "
294
+ lint_cmd=(" ${top_dir} /scripts/check_lint.py" )
295
+ if [[ " $CHECK_DIFF " == true ]]; then
296
+ lint_cmd+=(" ${START_SHA} " )
297
+ fi
298
+ " ${lint_cmd[@]} "
0 commit comments