Skip to content

Commit

Permalink
Clean up gitstatus.py
Browse files Browse the repository at this point in the history
  • Loading branch information
mcornella authored and wkentaro committed Aug 11, 2015
1 parent 50658a1 commit 825f8ad
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions gitstatus.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -25,11 +21,10 @@
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']).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('...')
Expand Down

0 comments on commit 825f8ad

Please sign in to comment.