mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-05 17:00:58 +01:00
shows commit SHA as curr_branch if HEAD detached
This behaviour was broken in fixing getting git branch name for short statuses by using rev-parse instead. This commit changes the method again, to use `git branch` which shows detached HEADs in the same format as `git status --long`, but is faster as discussed in #1823.
This commit is contained in:
parent
3159d41fa7
commit
8d99128b98
1 changed files with 14 additions and 6 deletions
|
@ -15,17 +15,25 @@ import xonsh.tools as xt
|
|||
|
||||
def _get_git_branch(q):
|
||||
try:
|
||||
branch = subprocess.check_output(
|
||||
['git', 'rev-parse', '--abbrev-ref', 'HEAD'],
|
||||
branches = xt.decode_bytes(subprocess.check_output(
|
||||
['git', 'branch'],
|
||||
stderr=subprocess.DEVNULL
|
||||
)
|
||||
)).splitlines()
|
||||
except (subprocess.CalledProcessError, OSError):
|
||||
q.put(None)
|
||||
else:
|
||||
info = xt.decode_bytes(branch)
|
||||
branch = info.splitlines()[0].split()[-1]
|
||||
q.put(branch)
|
||||
for branch in branches:
|
||||
if not branch.startswith('* '):
|
||||
continue
|
||||
elif branch.endswith(')'):
|
||||
branch = branch.split()[-1][:-1]
|
||||
else:
|
||||
branch = branch.split()[-1]
|
||||
|
||||
q.put(branch)
|
||||
break
|
||||
else:
|
||||
q.put(None)
|
||||
|
||||
def get_git_branch():
|
||||
"""Attempts to find the current git branch. If this could not
|
||||
|
|
Loading…
Add table
Reference in a new issue