@@ -93,6 +93,20 @@ if [[ ! -t 1 ]]; then
93
93
VERBOSE=true
94
94
fi
95
95
96
+ # When travis clones a repo for building, it uses a shallow clone. After the
97
+ # first commit on a non-master branch, TRAVIS_COMMIT_RANGE is not set, master
98
+ # is not available and we need to compute the START_REVISION from the common
99
+ # ancestor of $TRAVIS_COMMIT and origin/master.
100
+ if [[ -n " ${TRAVIS_COMMIT_RANGE:- } " ]] ; then
101
+ START_REVISION=" $TRAVIS_COMMIT_RANGE "
102
+ elif [[ -n " ${TRAVIS_COMMIT:- } " ]] ; then
103
+ if ! git rev-parse origin/master >& /dev/null; then
104
+ git remote set-branches --add origin master
105
+ git fetch origin
106
+ fi
107
+ START_REVISION=$( git merge-base origin/master " ${TRAVIS_COMMIT} " )
108
+ fi
109
+
96
110
while [[ $# -gt 0 ]]; do
97
111
case " $1 " in
98
112
--)
@@ -163,19 +177,23 @@ if [[ "${VERBOSE}" == true ]]; then
163
177
env | egrep ' ^TRAVIS_(BRANCH|COMMIT|PULL|REPO)' | sort || true
164
178
fi
165
179
166
- # When travis clones a repo for building, it uses a shallow clone. After the
167
- # first commit on a non-master branch, TRAVIS_COMMIT_RANGE is not set and
168
- # START_REVISION is "master" instead of a range.
180
+ if [[ " ${START_REVISION} " == * .. * ]] ; then
181
+ RANGE_START= " ${START_REVISION / .. */ } "
182
+ RANGE_END= " ${START_REVISION /* .. / } "
169
183
170
- # If needed, check if we have access to master and add it to the repo.
171
- if [[ " ${START_REVISION} " == " origin/master" ]]; then
184
+ # Figure out if we have access to master. If not add it to the repo.
172
185
if ! git rev-parse origin/master >& /dev/null; then
173
186
git remote set-branches --add origin master
174
187
git fetch origin
175
188
fi
176
- fi
177
189
178
- START_SHA=$( git rev-parse " ${START_REVISION} " )
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} "
193
+
194
+ else
195
+ START_SHA=$( git rev-parse " ${START_REVISION} " )
196
+ fi
179
197
180
198
if [[ " ${VERBOSE} " == true ]]; then
181
199
echo " START_REVISION=$START_REVISION "
0 commit comments