Make sure remote branch is available and tracked locally, and merge remote into local branch

This commit is contained in:
Steve Rowe 2018-06-20 09:38:12 -04:00
parent daff67e279
commit bcbcb16b6a
1 changed files with 8 additions and 1 deletions

View File

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