get_hg_branch runs 'hg status' first

This commit is contained in:
laerus 2016-11-06 18:33:09 +02:00
parent cc5abb5c68
commit 945185aa2f
2 changed files with 15 additions and 9 deletions

View file

@ -2,7 +2,9 @@
* The ``$VC_HG_SHOW_BRANCH`` environement variable to control whether to hide the hg branch in the prompt.
**Changed:** None
**Changed:**
* ``get_hg_branch`` runs ``hg status`` first to check if we are in a repo
**Deprecated:** None

View file

@ -69,15 +69,19 @@ def _get_parent_dir_for(path, dir_name, timeout):
def get_hg_branch(cwd=None, root=None):
env = builtins.__xonsh_env__
cwd = env['PWD']
root = _get_parent_dir_for(cwd, '.hg', env['VC_BRANCH_TIMEOUT'])
if not isinstance(root, str):
# Bail if we are not in a repo or we timed out
if root:
timeout = env['VC_BRANCH_TIMEOUT']
# Bail if we are not in a repo or we timed out
try:
status = subprocess.call(['hg', 'status'], timeout=timeout,
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL)
except subprocess.TimeoutExpired:
return subprocess.TimeoutExpired(['hg'], env['VC_BRANCH_TIMEOUT'])
else:
if status == 255:
return None
else:
return subprocess.TimeoutExpired(['hg'], env['VC_BRANCH_TIMEOUT'])
if env.get('VC_HG_SHOW_BRANCH') is True:
root = _get_parent_dir_for(cwd or env['PWD'], '.hg', timeout)
if env.get('VC_HG_SHOW_BRANCH'):
# get branch name
branch_path = os.path.sep.join([root, '.hg', 'branch'])
if os.path.exists(branch_path):