45473c3a81410735dac7fe0a1df33ad95fd3f2e5

Author
Kentaro Wada <www.kentaro.wada@gmail.com>
Committer
Marc Cornellà <marc.cornella@live.com>
Date

Message

Fix for initial or detached status branch info

Diff

 1diff --git a/plugins/git-prompt/gitstatus.py b/plugins/git-prompt/gitstatus.py
 2index 8790f3a3c4856ab6d5d63cdd4fd78961d1f097a2..59feadc39ca9b04e412c952399ac760456c54b8a 100644
 3--- a/plugins/git-prompt/gitstatus.py
 4+++ b/plugins/git-prompt/gitstatus.py
 5@@ -5,6 +5,8 @@ from __future__ import print_function
 6 prehash = ':'
 7 
 8 import sys
 9+import re
10+import subprocess
11 from subprocess import Popen, PIPE
12 
13 
14@@ -21,8 +23,13 @@ ahead, behind = 0, 0
15 status = [(line[0], line[1], line[2:]) for line in stdout.decode('utf-8').splitlines()]
16 for st in status:
17     if st[0] == '#' and st[1] == '#':
18-        if len(st[2].strip().split('...')) == 1:
19+        if re.search('Initial commit on', st[2]):
20+            branch = st[2].split(' ')[-1]
21+        elif len(st[2].strip().split('...')) == 1:
22             branch = st[2].strip()
23+            if branch == 'HEAD (no branch)':
24+                cmd = ['git', 'log', '-1', '--format="%h"']
25+                branch = subprocess.check_output(cmd).strip().strip('"')
26         else:
27             # current and remote branch info
28             branch, rest = st[2].strip().split('...')