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
This commit is contained in:
Neels Hofmeyr 2017-06-23 03:52:26 +02:00
parent de79cb155d
commit 851802b927
1 changed files with 3 additions and 1 deletions

View File

@ -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