Handle non-valid HEAD

Repo might have HEAD that points on master branch while
in reality it doesn't exists.

This fix will choose first reference in case origin/HEAD
doesn't exist.

Change-Id: I22fec070af4445c1cb3dd34e9c3b7f10e349bd0f
This commit is contained in:
Arie 2016-08-29 14:53:25 +03:00
parent cbc7f627ca
commit b8a7792977
1 changed files with 6 additions and 2 deletions

View File

@ -95,8 +95,12 @@ class Repo(object):
continue
repo.create_head(ref.remote_head, ref, force=True)
# Reset to remote HEAD (usually origin/master)
repo.head.reference = origin.refs['HEAD']
# try reset to remote HEAD (usually origin/master)
# If it fails, pick the first reference
try:
repo.head.reference = origin.refs['HEAD']
except IndexError:
repo.head.reference = origin.refs[0]
reset_repo_to_head(repo)
repo.git.clean('-x', '-f', '-d')