Mercurial > hg
diff hgext/fix.py @ 42655:2987d015aba4
fix: ignore fixer tool configurations that are missing patterns
This is to prevent a crash under the same circumstances.
This is also to avoid data loss due to accidental application of a fixer tool
to all files, if the matching logic somehow changed to that effect. Affecting
all files until otherwise configured would be dangerous, and not very useful.
We shouldn't abort because there may be other fixers, and it may still be
useful to run them without having to adjust configuration. A user might not
feel confident in changing configs, for example.
Differential Revision: https://phab.mercurial-scm.org/D6693
author | Danny Hooper <hooper@google.com> |
---|---|
date | Wed, 24 Jul 2019 16:19:00 -0700 |
parents | 9ed63cd0026c |
children | 74b4cd091e0d |
line wrap: on
line diff
--- a/hgext/fix.py Wed Jul 24 16:21:12 2019 -0700 +++ b/hgext/fix.py Wed Jul 24 16:19:00 2019 -0700 @@ -705,6 +705,14 @@ setattr(fixers[name], pycompat.sysstr('_' + key), attrs.get(key, default)) fixers[name]._priority = int(fixers[name]._priority) + # Don't use a fixer if it has no pattern configured. It would be + # dangerous to let it affect all files. It would be pointless to let it + # affect no files. There is no reasonable subset of files to use as the + # default. + if fixers[name]._pattern is None: + ui.warn( + _('fixer tool has no pattern configuration: %s\n') % (name,)) + del fixers[name] return collections.OrderedDict( sorted(fixers.items(), key=lambda item: item[1]._priority, reverse=True)) @@ -722,7 +730,8 @@ def affects(self, opts, fixctx, path): """Should this fixer run on the file at the given path and context?""" - return scmutil.match(fixctx, [self._pattern], opts)(path) + return (self._pattern is not None and + scmutil.match(fixctx, [self._pattern], opts)(path)) def shouldoutputmetadata(self): """Should the stdout of this fixer start with JSON and a null byte?"""