Skip to content

Commit bad992e

Browse files
authored
Fix check.sh when running a push build with a single commit (#2977)
Travis can send us a revision range that points to commits outside the repo (see comments for details). Adjust the revision range to always use target origin/master.
1 parent b4dceae commit bad992e

File tree

2 files changed

+42
-6
lines changed

2 files changed

+42
-6
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,3 +332,4 @@ jobs:
332332
branches:
333333
only:
334334
- master
335+
- wilhuff/fix-check

scripts/check.sh

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,12 @@ ALLOW_DIRTY=false
8686
COMMIT_METHOD="none"
8787
START_REVISION="master"
8888
TEST_ONLY=false
89+
VERBOSE=false
90+
91+
# Default to verbose operation if this isn't an interactive build.
92+
if [[ ! -t 1 ]]; then
93+
VERBOSE=true
94+
fi
8995

9096
while [[ $# -gt 0 ]]; do
9197
case "$1" in
@@ -114,6 +120,10 @@ while [[ $# -gt 0 ]]; do
114120
COMMIT_METHOD=message
115121
;;
116122

123+
--verbose)
124+
VERBOSE=true
125+
;;
126+
117127
--test-only)
118128
# In test-only mode, no changes are made, so there's no reason to
119129
# require a clean source tree.
@@ -122,10 +132,9 @@ while [[ $# -gt 0 ]]; do
122132
;;
123133

124134
*)
125-
if git rev-parse "$1" >& /dev/null; then
126-
START_REVISION="$1"
127-
break
128-
fi
135+
START_REVISION="$1"
136+
shift
137+
break
129138
;;
130139
esac
131140
shift
@@ -149,14 +158,40 @@ if ! git diff-index --quiet HEAD --; then
149158
fi
150159
fi
151160

152-
# Record actual start, but only if the revision is specified as a single
153-
# commit. Ranges specified with .. or ... are left alone.
161+
# Show Travis-related environment variables, to help with debuging failures.
162+
if [[ "${VERBOSE}" == true ]]; then
163+
env | egrep '^TRAVIS_(BRANCH|COMMIT|PULL)' | sort || true
164+
fi
165+
166+
# When travis clones a repo for building, it uses a shallow clone. When
167+
# building a branch it can sometimes give a revision range that refers to
168+
# commits that don't exist in the shallow clone. This has been observed in a
169+
# branch build where the branch only has a single commit. The cause of this
170+
# behavior is unclear but as a workaround ...
154171
if [[ "${START_REVISION}" == *..* ]]; then
172+
RANGE_START="${START_REVISION/..*/}"
173+
RANGE_END="${START_REVISION/*../}"
174+
175+
# Figure out if we have access to master. If not add it to the repo.
176+
if ! git rev-parse origin/master >& /dev/null; then
177+
git remote set-branches --add origin master
178+
git fetch origin
179+
fi
180+
181+
NEW_RANGE_START=$(git merge-base origin/master "${RANGE_END}")
182+
START_REVISION="${START_REVISION/$RANGE_START/$NEW_RANGE_START}"
183+
155184
START_SHA="${START_REVISION}"
185+
156186
else
157187
START_SHA=$(git rev-parse "${START_REVISION}")
158188
fi
159189

190+
if [[ "${VERBOSE}" == true ]]; then
191+
echo "START_REVISION=$START_REVISION"
192+
echo "START_SHA=$START_SHA"
193+
fi
194+
160195
# If committing --fixup, avoid messages with fixup! fixup! that might come from
161196
# multiple fixup commits.
162197
HEAD_SHA=$(git rev-parse HEAD)

0 commit comments

Comments
 (0)