From 752fe1f7f06106360b0b4c5dcf81c2e2389abe5d Mon Sep 17 00:00:00 2001 From: laerus Date: Tue, 13 Sep 2016 21:24:21 +0300 Subject: [PATCH] fix for no branch in pwd --- xonsh/prompt/base.py | 28 ++++++++++++++-------------- xonsh/prompt/vc_branch.py | 11 ++++++++--- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/xonsh/prompt/base.py b/xonsh/prompt/base.py index 06d7027f5..aeb758948 100644 --- a/xonsh/prompt/base.py +++ b/xonsh/prompt/base.py @@ -23,18 +23,18 @@ from xonsh.prompt.gitstatus import gitstatus_prompt @xl.lazyobject def FORMATTER_DICT(): return dict( - user=os.environ.get('USERNAME' if xp.ON_WINDOWS else 'USER', ''), - prompt_end='#' if xt.is_superuser() else '$', - hostname=socket.gethostname().split('.', 1)[0], - cwd=_dynamically_collapsed_pwd, - cwd_dir=lambda: os.path.dirname(_replace_home_cwd()), - cwd_base=lambda: os.path.basename(_replace_home_cwd()), - short_cwd=_collapsed_pwd, - curr_branch=current_branch, - branch_color=branch_color, - branch_bg_color=branch_bg_color, - current_job=_current_job, - env_name=env_name, - vte_new_tab_cwd=vte_new_tab_cwd, - gitstatus=gitstatus_prompt, + user=os.environ.get('USERNAME' if xp.ON_WINDOWS else 'USER', ''), + prompt_end='#' if xt.is_superuser() else '$', + hostname=socket.gethostname().split('.', 1)[0], + cwd=_dynamically_collapsed_pwd, + cwd_dir=lambda: os.path.dirname(_replace_home_cwd()), + cwd_base=lambda: os.path.basename(_replace_home_cwd()), + short_cwd=_collapsed_pwd, + curr_branch=current_branch, + branch_color=branch_color, + branch_bg_color=branch_bg_color, + current_job=_current_job, + env_name=env_name, + vte_new_tab_cwd=vte_new_tab_cwd, + gitstatus=gitstatus_prompt, ) diff --git a/xonsh/prompt/vc_branch.py b/xonsh/prompt/vc_branch.py index 23459e4b1..ea6edfd3b 100644 --- a/xonsh/prompt/vc_branch.py +++ b/xonsh/prompt/vc_branch.py @@ -85,12 +85,17 @@ def current_branch(pad=NotImplemented): branch = None cmds = builtins.__xonsh_commands_cache__ if cmds.lazy_locate_binary('git') or cmds.is_empty(): - branch = xonsh.prompt.gitstatus.gitstatus().branch - if (cmds.lazy_locate_binary('hg') or cmds.is_empty()) and not branch: + try: + status = xonsh.prompt.gitstatus.gitstatus() + except subprocess.CalledProcessError: + branch = None + else: + branch = status.branch + elif (cmds.lazy_locate_binary('hg') or cmds.is_empty()) and not branch: branch = get_hg_branch() if isinstance(branch, subprocess.TimeoutExpired): branch = '' - _first_branch_timeout_message() + # _first_branch_timeout_message() return branch or None