3c698743fa4265ab2b70b880e12f957792669438

Author
Marc Cornellà <marc.cornella@live.com>
Committer
Marc Cornellà <marc.cornella@live.com>
Date

Message

Clean up gitstatus.py

Diff

 1diff --git a/plugins/git-prompt/gitstatus.py b/plugins/git-prompt/gitstatus.py
 2index 59feadc39ca9b04e412c952399ac760456c54b8a..1beae541a770ef6267cc63dba1a92230a41012e3 100644
 3--- a/plugins/git-prompt/gitstatus.py
 4+++ b/plugins/git-prompt/gitstatus.py
 5@@ -1,18 +1,14 @@
 6 #!/usr/bin/env python
 7 from __future__ import print_function
 8 
 9-# change this symbol to whatever you prefer
10-prehash = ':'
11-
12 import sys
13 import re
14-import subprocess
15-from subprocess import Popen, PIPE
16+from subprocess import Popen, PIPE, check_output
17 
18 
19-# `git status --porcelain -b` can collect all information
20+# `git status --porcelain --branch` can collect all information
21 # branch, remote_branch, untracked, staged, changed, conflicts, ahead, behind
22-po = Popen(['git', 'status', '--porcelain', '-b'], stdout=PIPE, stderr=PIPE)
23+po = Popen(['git', 'status', '--porcelain', '--branch'], stdout=PIPE, stderr=PIPE)
24 stdout, sterr = po.communicate()
25 if po.returncode != 0:
26     sys.exit(0)  # Not a git repository
27@@ -25,11 +21,10 @@ for st in status:
28     if st[0] == '#' and st[1] == '#':
29         if re.search('Initial commit on', st[2]):
30             branch = st[2].split(' ')[-1]
31+        elif re.search('no branch', st[2]):
32+            branch = check_output(['git', 'rev-parse', '--short', 'HEAD']).decode('utf-8').strip()
33         elif len(st[2].strip().split('...')) == 1:
34             branch = st[2].strip()
35-            if branch == 'HEAD (no branch)':
36-                cmd = ['git', 'log', '-1', '--format="%h"']
37-                branch = subprocess.check_output(cmd).strip().strip('"')
38         else:
39             # current and remote branch info
40             branch, rest = st[2].strip().split('...')