mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-05 00:41:00 +01:00
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.
This commit is contained in:
parent
4f29bf0ff2
commit
fdb1218649
1 changed files with 9 additions and 5 deletions
|
@ -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):
|
||||
|
|
Loading…
Add table
Reference in a new issue