From fdb121864934b031b5ff83105f984ce9d2f787a7 Mon Sep 17 00:00:00 2001 From: Nathan Goldbaum Date: Sun, 17 May 2015 00:25:46 -0700 Subject: [PATCH] Fix corner case in hg branch checking. Newly created repositories don't have a branch file, so we infer by calling the hg binary. This is slower but should still be pretty quick since it should only happen in new repositories. --- xonsh/environ.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/xonsh/environ.py b/xonsh/environ.py index 1c6a0a24b..5f3a1a6a6 100644 --- a/xonsh/environ.py +++ b/xonsh/environ.py @@ -297,20 +297,24 @@ def get_hg_branch(cwd=None, root=None): active_bookmark = None if root is not None: - root = root.strip(os.linesep) branch_path = os.path.sep.join([root, '.hg', 'branch']) bookmark_path = os.path.sep.join([root, '.hg', 'bookmarks.current']) + if os.path.exists(branch_path): with open(branch_path, 'r') as branch_file: - branch = branch_file.read().strip(os.linesep) + branch = branch_file.read() + else: + branch = call_hg_command(['branch'], cwd) + if os.path.exists(bookmark_path): with open(bookmark_path, 'r') as bookmark_file: - active_bookmark = bookmark_file.read().strip(os.linesep) + active_bookmark = bookmark_file.read() if active_bookmark is not None: - return "{0}, {1}".format(branch, active_bookmark) + return "{0}, {1}".format( + *(b.strip(os.linesep) for b in (branch, active_bookmark))) - return branch + return branch.strip(os.linesep) def current_branch(pad=True):