Merge pull request #1779 from xonsh/vcbranch

prompt git branch
This commit is contained in:
Anthony Scopatz 2016-09-30 15:52:33 -04:00 committed by GitHub
commit 8958ce3711
3 changed files with 15 additions and 19 deletions

View file

@ -5,7 +5,7 @@
* ``xonsh.prompt.gitstatus.gitstatus`` now returns a namedtuple
* implementation of ``xonsh.prompt.vc_branch.get_git_branch`` and
``xonsh.prompt.vc_branch.git_dirty_working_directory`` to be faster
``xonsh.prompt.vc_branch.git_dirty_working_directory`` to use 'git status --procelain'
**Deprecated:** None

View file

@ -1,17 +1,16 @@
# -*- coding: utf-8 -*-
"""Prompt formatter for simple version control branchs"""
import os
import sys
import time
import builtins
import warnings
import os
import subprocess
import sys
import threading, queue
import time
import warnings
import xonsh.platform as xp
import xonsh.prompt
import threading, queue
import xonsh.tools as xt
def _get_git_branch(q):
@ -21,12 +20,9 @@ def _get_git_branch(q):
except (subprocess.CalledProcessError, OSError):
q.put(None)
else:
status = status.decode().split()
if status[2] == 'at':
q.put(status[3])
else:
q.put(status[2])
info = xt.decode_bytes(status)
branch = info.splitlines()[0].split()[-1]
q.put(branch)
def get_git_branch():
"""Attempts to find the current git branch. If this could not

View file

@ -111,14 +111,14 @@ def expandpath(path):
return path
def decode_bytes(path):
"""Tries to decode a path in bytes using XONSH_ENCODING if available,
def decode_bytes(b):
"""Tries to decode the bytes using XONSH_ENCODING if available,
otherwise using sys.getdefaultencoding().
"""
env = getattr(builtins, '__xonsh_env__', os.environ)
enc = env.get('XONSH_ENCODING', DEFAULT_ENCODING)
return path.decode(encoding=enc,
errors=env.get('XONSH_ENCODING_ERRORS') or 'strict')
enc = env.get('XONSH_ENCODING') or DEFAULT_ENCODING
err = env.get('XONSH_ENCODING_ERRORS') or 'strict'
return b.decode(encoding=enc, errors=err)
class EnvPath(collections.MutableSequence):