From 48470221f015bf1d0fbf47b6ea2fa99d34014497 Mon Sep 17 00:00:00 2001 From: ZyX Date: Thu, 14 Mar 2013 20:02:02 +0400 Subject: [PATCH] Make git.Repository.status() also return None Fixes #326 --- powerline/lib/vcs/git.py | 5 +++-- powerline/segments/common.py | 2 +- powerline/segments/vim.py | 2 +- tests/test_lib.py | 3 ++- tests/test_segments.py | 2 +- 5 files changed, 8 insertions(+), 6 deletions(-) diff --git a/powerline/lib/vcs/git.py b/powerline/lib/vcs/git.py index ec99f0c6..f7ea2e83 100644 --- a/powerline/lib/vcs/git.py +++ b/powerline/lib/vcs/git.py @@ -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'): diff --git a/powerline/segments/common.py b/powerline/segments/common.py index 106df1dd..63142a8b 100644 --- a/powerline/segments/common.py +++ b/powerline/segments/common.py @@ -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 diff --git a/powerline/segments/vim.py b/powerline/segments/vim.py index 54dbad92..52d30cc5 100644 --- a/powerline/segments/vim.py +++ b/powerline/segments/vim.py @@ -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 diff --git a/tests/test_lib.py b/tests/test_lib.py index e48730d1..23f7d53c 100644 --- a/tests/test_lib.py +++ b/tests/test_lib.py @@ -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() diff --git a/tests/test_segments.py b/tests/test_segments.py index 5211fe01..491e4a3a 100644 --- a/tests/test_segments.py +++ b/tests/test_segments.py @@ -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']}])