blob: 2f5afa6b6b487f9fbd926189995c0d9abb474b73 [file] [log] [blame]
import subprocess
from dtest import CASSANDRA_DIR, debug
def cassandra_git_branch(cdir=None):
'''Get the name of the git branch at CASSANDRA_DIR.
'''
cdir = CASSANDRA_DIR if cdir is None else cdir
try:
p = subprocess.Popen(['git', 'branch'], cwd=cdir,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
except OSError as e: # e.g. if git isn't available, just give up and return None
debug('shelling out to git failed: {}'.format(e))
return
out, err = p.communicate()
# fail if git failed
if p.returncode != 0:
raise RuntimeError('Git printed error: {err}'.format(err=err))
[current_branch_line] = [line for line in out.splitlines() if line.startswith('*')]
return current_branch_line[1:].strip()