Handle branch divergences in git cache more appropriately
@@ -207,7 +207,7 @@ def clone_development(git_repo, version, verbose=False, alias=False):
out = subprocess.call(['git', 'fetch', 'origin'], cwd=target_dir, stdout=lf, stderr=lf)
assert out == 0, "Could not do a git fetch"
status = subprocess.Popen(['git', 'status', '-sb'], cwd=target_dir, stdout=subprocess.PIPE, stderr=lf).communicate()[0]
- if str(status).find('[behind') > -1:
+ if str(status).find('[behind') > -1: # If `status` looks like '## cassandra-2.2...origin/cassandra-2.2 [behind 9]\n'
common.info("Branch is behind, recompiling")
out = subprocess.call(['git', 'pull'], cwd=target_dir, stdout=lf, stderr=lf)
assert out == 0, "Could not do a git pull"
@@ -216,6 +216,12 @@ def clone_development(git_repo, version, verbose=False, alias=False):
# now compile
compile_version(git_branch, target_dir, verbose)
+ elif re.search('\[.*?(ahead|behind).*?\]', status) is not None: # status looks like '## trunk...origin/trunk [ahead 1, behind 29]\n'
+ # If we have diverged in a way that fast-forward merging cannot solve, raise an exception so the cache is wiped
+ common.error("Could not ascertain branch status, please resolve manually.")
+ raise Exception
+ else: # status looks like '## cassandra-2.2...origin/cassandra-2.2\n'
+ common.debug("Branch up to date, not pulling.")
except Exception as e:
# wipe out the directory if anything goes wrong. Otherwise we will assume it has been compiled the next time it runs.
try:
