Skip to content

Commit

Permalink
Fix for initial or detached status branch info
Browse files Browse the repository at this point in the history
  • Loading branch information
wkentaro committed Aug 11, 2015
1 parent ce669f1 commit 50658a1
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion gitstatus.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
prehash = ':'

import sys
import re
import subprocess
from subprocess import Popen, PIPE


Expand All @@ -21,8 +23,13 @@
status = [(line[0], line[1], line[2:]) for line in stdout.decode('utf-8').splitlines()]
for st in status:
if st[0] == '#' and st[1] == '#':
if len(st[2].strip().split('...')) == 1:
if re.search('Initial commit on', st[2]):
branch = st[2].split(' ')[-1]
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('...')
Expand Down

0 comments on commit 50658a1

Please sign in to comment.