Handle the case of checking out a remote branch that has never been checked out locally before

This commit is contained in:
Steve Rowe 2018-06-19 22:21:26 -04:00
parent d04acc95f0
commit 74bd5d5658
1 changed files with 5 additions and 1 deletions

View File

@ -158,7 +158,11 @@ def prepareWorkspace(useGit, gitRef):
checkoutCmd = 'git checkout %s' % gitRef checkoutCmd = 'git checkout %s' % gitRef
code = run(checkoutCmd) code = run(checkoutCmd)
if 0 != code: if 0 != code:
raise RuntimeError('ERROR: "%s" failed. See above.' % checkoutCmd) checkoutBranchCmd = 'git checkout -t -b %s origin/%s' % (gitRef, gitRef) # Checkout remote branch as new local branch
print('"%s" failed. Trying "%s".' % (checkoutCmd, checkoutBranchCmd))
code = run(checkoutBranchCmd)
if 0 != code:
raise RuntimeError('ERROR: "%s" failed. See above.' % checkoutBranchCmd)
gitCheckoutSucceeded = True gitCheckoutSucceeded = True
run('git merge --ff-only', rememberFailure=False) # Ignore failure on non-branch ref run('git merge --ff-only', rememberFailure=False) # Ignore failure on non-branch ref