mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-05 17:00:58 +01:00
get_hg_branch runs 'hg status' first
This commit is contained in:
parent
cc5abb5c68
commit
945185aa2f
2 changed files with 15 additions and 9 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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):
|
||||
|
|
Loading…
Add table
Reference in a new issue