From 851802b927ccfcb061a2774fdc5de12141426b5c Mon Sep 17 00:00:00 2001 From: Neels Hofmeyr Date: Fri, 23 Jun 2017 03:52:26 +0200 Subject: [PATCH] jenkins-build-common.sh: fix being stuck on branch It's hard to allow both branch names and git hashes. For a branch, we want to prepend 'origin' to use the upstream branch. For a git hash, we don't. We so far prepend 'origin/' if the current branch name doesn't resolve, but that's not enough. If a local 'master' branch exists, we would stay on that branch instead of origin/master. Rather, prepend 'origin/' if 'origin/$branch' exists. Git hashes should not exist as 'origin/123abc...' and used as-is, where branches from origin should be updated to upstream by prepending 'origin/'. Also create a local branch to build. Always force-remove the branch and re-create from the origin/name or git hash. Keep the reset --hard for paranoia. Change-Id: I2e610b357f8559c6b6ffb544eb0a952f04dd9f70 --- contrib/jenkins-build-common.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/contrib/jenkins-build-common.sh b/contrib/jenkins-build-common.sh index 921434d9..63e0ba8e 100644 --- a/contrib/jenkins-build-common.sh +++ b/contrib/jenkins-build-common.sh @@ -81,10 +81,12 @@ have_repo() { git fetch origin # Figure out whether we need to prepend origin/ to find branches in upstream - if ! git rev-parse "$branch"; then + if git rev-parse "origin/$branch"; then branch="origin/$branch" fi + git branch -D build_branch || true + git checkout -b build_branch "$branch" git reset --hard "$branch" git rev-parse HEAD