Skip to content

Commit

Permalink
Fixed issue #1: segment not showing with daemon
Browse files Browse the repository at this point in the history
  • Loading branch information
jaspernbrouwer committed May 3, 2015
1 parent ae8c2b7 commit 60c9a25
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
5 changes: 3 additions & 2 deletions .gitignore
@@ -1,4 +1,5 @@
*.egg-info
*.pyc
build/
dist/
build/*
dist/*
build_howto.md
21 changes: 15 additions & 6 deletions powerline_gitstatus/segments.py
Expand Up @@ -3,6 +3,7 @@
from powerline.segments import Segment, with_docstring
from powerline.theme import requires_segment_info
from subprocess import PIPE, Popen
import os
import re


Expand All @@ -11,11 +12,17 @@ class GitStatusSegment(Segment):

@staticmethod
def get_directory(segment_info):
return segment_info['getcwd']()
cwd = segment_info['getcwd']()

if not os.path.isdir('%s/.git' % cwd):
return None

return cwd

def execute(self, command):
proc = Popen(command, stdout=PIPE, stderr=PIPE)
out, err = proc.communicate()

return (out.decode('utf-8').splitlines(), err.decode('utf-8').splitlines())

def parse_branch(self, line):
Expand Down Expand Up @@ -89,11 +96,13 @@ def build_segments(self, branch, detached, behind, ahead, staged, unmerged, chan
return segments

def __call__(self, pl, segment_info):
name = self.get_directory(segment_info)
if not name:
cwd = self.get_directory(segment_info)
if not cwd:
return

status, err = self.execute(['git', 'status', '--branch', '--porcelain'])
base_command = ['git', '--git-dir=%s/.git' % cwd, '--work-tree=%s' % cwd]

status, err = self.execute(base_command + ['status', '--branch', '--porcelain'])

if err and ('error' in err[0] or 'fatal' in err[0]):
return
Expand All @@ -104,11 +113,11 @@ def __call__(self, pl, segment_info):
return

if branch == 'HEAD':
branch = self.execute(['git', 'rev-parse', '--short', 'HEAD'])[0][0]
branch = self.execute(base_command + ['rev-parse', '--short', 'HEAD'])[0][0]

staged, unmerged, changed, untracked = self.parse_status(status)

stashed = len(self.execute(['git', 'stash', 'list', '--no-decorate'])[0])
stashed = len(self.execute(base_command + ['stash', 'list', '--no-decorate'])[0])

return self.build_segments(branch, detached, behind, ahead, staged, unmerged, changed, untracked, stashed)

Expand Down

0 comments on commit 60c9a25

Please sign in to comment.