travis: fix Could not parse object TRAVIS_COMMIT

If a PR is edited(e.g. force pushed) during the build.
TRAVIS_COMMIT will be lost. Refetching the merge ref wouldn't
help this situation as well. Since Travis already have reset
$TRAVIS_BUILD_DIR to the commit we need to test, let's use it to
determine TRAVIS_COMMIT directly.

Ref: https://github.com/travis-ci/travis-ci/issues/2666
This commit is contained in:
Xu Cheng 2015-09-27 19:45:26 +08:00
parent 1b33c70d46
commit 79f71ca2ef

View File

@ -16,14 +16,14 @@ matrix:
rvm: system
before_install:
- export TRAVIS_COMMIT=$(git rev-parse --verify -q HEAD)
- cd /usr/local
- sudo rm -rf /usr/local/.git/refs /usr/local/.git/packed-refs
- sudo rsync -az "$TRAVIS_BUILD_DIR/" /usr/local/
- export TRAVIS_BUILD_DIR="/usr/local"
- sudo chown -R $USER /usr/local
- cd /usr/local
- env | grep TRAVIS_
- if [ -f ".git/shallow" ]; then travis_retry git fetch --unshallow; fi
- if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then git reset --hard $TRAVIS_COMMIT || travis_retry git fetch origin +refs/pull/$TRAVIS_PULL_REQUEST/merge:; fi
- git reset --hard $TRAVIS_COMMIT
- git clean -qxdff