Make git.Repository.status() also return None

Fixes #326
This commit is contained in:
ZyX 2013-03-14 20:02:02 +04:00
parent d015d517ac
commit 48470221f0
5 changed files with 8 additions and 6 deletions

View File

@ -73,7 +73,8 @@ try:
| git.GIT_STATUS_INDEX_MODIFIED
| git.GIT_STATUS_INDEX_DELETED):
index_column = 'I'
return wt_column + index_column + untracked_column
r = wt_column + index_column + untracked_column
return r if r != ' ' else None
def branch(self):
try:
@ -132,7 +133,7 @@ except ImportError:
wt_column = 'D'
r = wt_column + index_column + untracked_column
return r
return r if r != ' ' else None
def branch(self):
for line in self._gitcmd('branch', '-l'):

View File

@ -55,7 +55,7 @@ def branch(status_colors=True):
if status_colors:
return [{
'contents': branch,
'highlight_group': ['branch_dirty' if repo.status().strip() else 'branch_clean', 'branch'],
'highlight_group': ['branch_dirty' if repo.status() else 'branch_clean', 'branch'],
}]
else:
return branch

View File

@ -320,7 +320,7 @@ def branch(segment_info, status_colors=True):
if repo:
return [{
'contents': repo.branch(),
'highlight_group': (['branch_dirty' if repo.status().strip() else 'branch_clean'] if status_colors else []) + ['branch'],
'highlight_group': (['branch_dirty' if repo.status() else 'branch_clean'] if status_colors else []) + ['branch'],
'divider_highlight_group': 'branch:divider',
}]
return None

View File

@ -48,7 +48,7 @@ class TestVCS(TestCase):
repo = guess(path=GIT_REPO)
self.assertNotEqual(repo, None)
self.assertEqual(repo.branch(), 'master')
self.assertEqual(repo.status(), ' ')
self.assertEqual(repo.status(), None)
self.assertEqual(repo.status('file'), None)
with open(os.path.join(GIT_REPO, 'file'), 'w') as f:
f.write('abc')
@ -69,6 +69,7 @@ class TestVCS(TestCase):
repo = guess(path=HG_REPO)
self.assertNotEqual(repo, None)
self.assertEqual(repo.branch(), 'default')
self.assertEqual(repo.status(), None)
with open(os.path.join(HG_REPO, 'file'), 'w') as f:
f.write('abc')
f.flush()

View File

@ -46,7 +46,7 @@ class TestCommon(TestCase):
self.assertEqual(common.user(), [{'contents': 'def', 'highlight_group': ['superuser', 'user']}])
def test_branch(self):
with replace_module_attr(common, 'guess', lambda path: Args(branch=lambda: os.path.basename(path), status=lambda: ' ')):
with replace_module_attr(common, 'guess', lambda path: Args(branch=lambda: os.path.basename(path), status=lambda: None)):
self.assertEqual(common.branch(status_colors=False), 'tests')
self.assertEqual(common.branch(status_colors=True),
[{'contents': 'tests', 'highlight_group': ['branch_clean', 'branch']}])