parent
3f2aabb77b
commit
8b1a502f0d
|
@ -15,7 +15,7 @@ class BranchSegment(Segment):
|
|||
def get_directory(segment_info):
|
||||
return segment_info['getcwd']()
|
||||
|
||||
def __call__(self, pl, segment_info, create_watcher, status_colors=False):
|
||||
def __call__(self, pl, segment_info, create_watcher, status_colors=False, ignore_statuses=()):
|
||||
name = self.get_directory(segment_info)
|
||||
if name:
|
||||
repo = guess(path=name, create_watcher=create_watcher)
|
||||
|
@ -28,7 +28,11 @@ class BranchSegment(Segment):
|
|||
except Exception as e:
|
||||
pl.exception('Failed to compute tree status: {0}', str(e))
|
||||
status = '?'
|
||||
scol.insert(0, 'branch_dirty' if status and status.strip() else 'branch_clean')
|
||||
else:
|
||||
status = status and status.strip()
|
||||
if status in ignore_statuses:
|
||||
status = None
|
||||
scol.insert(0, 'branch_dirty' if status else 'branch_clean')
|
||||
return [{
|
||||
'contents': branch,
|
||||
'highlight_group': scol,
|
||||
|
@ -40,7 +44,15 @@ branch = with_docstring(BranchSegment(),
|
|||
'''Return the current VCS branch.
|
||||
|
||||
:param bool status_colors:
|
||||
determines whether repository status will be used to determine highlighting. Default: False.
|
||||
Determines whether repository status will be used to determine highlighting.
|
||||
Default: False.
|
||||
:param bool ignore_statuses:
|
||||
List of statuses which will not result in repo being marked as dirty. Most
|
||||
useful is setting this option to ``["U"]``: this will ignore repository
|
||||
which has just untracked files (i.e. repository with modified, deleted or
|
||||
removed files will be marked as dirty, while just untracked files will make
|
||||
segment show clean repository). Only applicable if ``status_colors`` option
|
||||
is True.
|
||||
|
||||
Highlight groups used: ``branch_clean``, ``branch_dirty``, ``branch``.
|
||||
''')
|
||||
|
|
|
@ -496,7 +496,15 @@ branch = with_docstring(VimBranchSegment(),
|
|||
'''Return the current working branch.
|
||||
|
||||
:param bool status_colors:
|
||||
determines whether repository status will be used to determine highlighting. Default: False.
|
||||
Determines whether repository status will be used to determine highlighting.
|
||||
Default: False.
|
||||
:param bool ignore_statuses:
|
||||
List of statuses which will not result in repo being marked as dirty. Most
|
||||
useful is setting this option to ``["U"]``: this will ignore repository
|
||||
which has just untracked files (i.e. repository with modified, deleted or
|
||||
removed files will be marked as dirty, while just untracked files will make
|
||||
segment show clean repository). Only applicable if ``status_colors`` option
|
||||
is True.
|
||||
|
||||
Highlight groups used: ``branch_clean``, ``branch_dirty``, ``branch``.
|
||||
|
||||
|
|
|
@ -629,6 +629,28 @@ class TestVcs(TestCommon):
|
|||
}])
|
||||
with replace_attr(self.module, 'guess', lambda path, create_watcher: None):
|
||||
self.assertEqual(branch(segment_info=segment_info, status_colors=False), None)
|
||||
with replace_attr(self.module, 'guess', get_dummy_guess(status=lambda: 'U')):
|
||||
with replace_attr(self.module, 'tree_status', lambda repo, pl: 'U'):
|
||||
self.assertEqual(branch(segment_info=segment_info, status_colors=False, ignore_statuses=['U']), [{
|
||||
'highlight_group': ['branch'],
|
||||
'contents': 'tests',
|
||||
'divider_highlight_group': None
|
||||
}])
|
||||
self.assertEqual(branch(segment_info=segment_info, status_colors=True, ignore_statuses=['DU']), [{
|
||||
'highlight_group': ['branch_dirty', 'branch'],
|
||||
'contents': 'tests',
|
||||
'divider_highlight_group': None
|
||||
}])
|
||||
self.assertEqual(branch(segment_info=segment_info, status_colors=True), [{
|
||||
'highlight_group': ['branch_dirty', 'branch'],
|
||||
'contents': 'tests',
|
||||
'divider_highlight_group': None
|
||||
}])
|
||||
self.assertEqual(branch(segment_info=segment_info, status_colors=True, ignore_statuses=['U']), [{
|
||||
'highlight_group': ['branch_clean', 'branch'],
|
||||
'contents': 'tests',
|
||||
'divider_highlight_group': None
|
||||
}])
|
||||
|
||||
|
||||
class TestTime(TestCommon):
|
||||
|
@ -1083,6 +1105,20 @@ class TestVim(TestCase):
|
|||
self.assertEqual(branch(segment_info=segment_info, status_colors=True), [
|
||||
{'divider_highlight_group': 'branch:divider', 'highlight_group': ['branch_dirty', 'branch'], 'contents': 'foo'}
|
||||
])
|
||||
with replace_attr(self.vcs, 'guess', get_dummy_guess(status=lambda: 'U')):
|
||||
with replace_attr(self.vcs, 'tree_status', lambda repo, pl: 'U'):
|
||||
self.assertEqual(branch(segment_info=segment_info, status_colors=False, ignore_statuses=['U']), [
|
||||
{'divider_highlight_group': 'branch:divider', 'highlight_group': ['branch'], 'contents': 'foo'}
|
||||
])
|
||||
self.assertEqual(branch(segment_info=segment_info, status_colors=True, ignore_statuses=['DU']), [
|
||||
{'divider_highlight_group': 'branch:divider', 'highlight_group': ['branch_dirty', 'branch'], 'contents': 'foo'}
|
||||
])
|
||||
self.assertEqual(branch(segment_info=segment_info, status_colors=True), [
|
||||
{'divider_highlight_group': 'branch:divider', 'highlight_group': ['branch_dirty', 'branch'], 'contents': 'foo'}
|
||||
])
|
||||
self.assertEqual(branch(segment_info=segment_info, status_colors=True, ignore_statuses=['U']), [
|
||||
{'divider_highlight_group': 'branch:divider', 'highlight_group': ['branch_clean', 'branch'], 'contents': 'foo'}
|
||||
])
|
||||
|
||||
def test_file_vcs_status(self):
|
||||
pl = Pl()
|
||||
|
|
Loading…
Reference in New Issue