From 17bd83be04e1a03cf3b62550308e598118efcf7e Mon Sep 17 00:00:00 2001
From: Joakim Bech <joakim.bech@linaro.org>
Date: Thu, 1 Jun 2017 12:18:45 +0200
Subject: [PATCH] travis: Always use the branch from the committer

Regardless if it is a push or a pull request, Travis will use the
committers repository and branch. For developers this means his own
branch will be used when pushing to his own gits and when making a pull
request. When the pull request is merged, which is seen as normal push
to the upstream repository, Travis will once more build according to the
definition, but this time use the upstream repository and the tip branch
instead.

Signed-off-by: Joakim Bech <joakim.bech@linaro.org>
Reviewed-by: Igor Opaniuk <igor.opaniuk@linaro.org>
---
 .travis.yml | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index b802ab4..9a0ce16 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -57,6 +57,14 @@ script:
   - if [ $REPO_PROJ == "qemu_v8" ]; then cd $HOME/$REPO_PROJ/qemu && git submodule update --init dtc; fi
   # Here we are using Travis environment variables to select the correct branch
   # based on either a pull request or a normal push.
-  - cd $HOME/$REPO_PROJ/build && git remote add github https://github.com/$TRAVIS_REPO_SLUG && git remote update
-  - cd $HOME/$REPO_PROJ/build && git checkout github/$TRAVIS_BRANCH
+  - |
+        if [ "$TRAVIS_EVENT_TYPE" == "pull_request" ]; then
+                slug=$TRAVIS_PULL_REQUEST_SLUG
+                branch=$TRAVIS_PULL_REQUEST_BRANCH
+        else
+                slug=$TRAVIS_REPO_SLUG
+                branch=$TRAVIS_BRANCH
+        fi
+  - cd $HOME/$REPO_PROJ/build && git remote add github https://github.com/$slug && git remote update
+  - cd $HOME/$REPO_PROJ/build && git checkout github/$branch
   - cd $HOME/$REPO_PROJ/build && make -f toolchain.mk toolchains -j3 && make all -j`nproc`
-- 
GitLab