summaryrefslogtreecommitdiff
path: root/plugins/git-prompt
diff options
context:
space:
mode:
authorMarc Cornellà <marc.cornella@live.com>2015-08-11 11:29:05 +0200
committerMarc Cornellà <marc.cornella@live.com>2015-08-16 23:21:48 +0200
commit3c698743fa4265ab2b70b880e12f957792669438 (patch)
treeb2d505a50df0d1e49f2ccc467ea11d0df09fcb7d /plugins/git-prompt
parent45473c3a81410735dac7fe0a1df33ad95fd3f2e5 (diff)
downloadzsh-3c698743fa4265ab2b70b880e12f957792669438.tar.gz
zsh-3c698743fa4265ab2b70b880e12f957792669438.tar.bz2
zsh-3c698743fa4265ab2b70b880e12f957792669438.zip
Clean up gitstatus.py
Diffstat (limited to 'plugins/git-prompt')
-rw-r--r--plugins/git-prompt/gitstatus.py15
1 files changed, 5 insertions, 10 deletions
diff --git a/plugins/git-prompt/gitstatus.py b/plugins/git-prompt/gitstatus.py
index 59feadc39..1beae541a 100644
--- a/plugins/git-prompt/gitstatus.py
+++ b/plugins/git-prompt/gitstatus.py
@@ -1,18 +1,14 @@
#!/usr/bin/env python
from __future__ import print_function
-# change this symbol to whatever you prefer
-prehash = ':'
-
import sys
import re
-import subprocess
-from subprocess import Popen, PIPE
+from subprocess import Popen, PIPE, check_output
-# `git status --porcelain -b` can collect all information
+# `git status --porcelain --branch` can collect all information
# branch, remote_branch, untracked, staged, changed, conflicts, ahead, behind
-po = Popen(['git', 'status', '--porcelain', '-b'], stdout=PIPE, stderr=PIPE)
+po = Popen(['git', 'status', '--porcelain', '--branch'], stdout=PIPE, stderr=PIPE)
stdout, sterr = po.communicate()
if po.returncode != 0:
sys.exit(0) # Not a git repository
@@ -25,11 +21,10 @@ for st in status:
if st[0] == '#' and st[1] == '#':
if re.search('Initial commit on', st[2]):
branch = st[2].split(' ')[-1]
+ elif re.search('no branch', st[2]):
+ branch = check_output(['git', 'rev-parse', '--short', 'HEAD']).decode('utf-8').strip()
elif len(st[2].strip().split('...')) == 1:
branch = st[2].strip()
- if branch == 'HEAD (no branch)':
- cmd = ['git', 'log', '-1', '--format="%h"']
- branch = subprocess.check_output(cmd).strip().strip('"')
else:
# current and remote branch info
branch, rest = st[2].strip().split('...')