##// END OF EJS Templates
fix: ignore fixer tool configurations that are missing patterns...
Danny Hooper -
r42882:2987d015 default
parent child Browse files
Show More
@@ -705,6 +705,14 b' def getfixers(ui):'
705 setattr(fixers[name], pycompat.sysstr('_' + key),
705 setattr(fixers[name], pycompat.sysstr('_' + key),
706 attrs.get(key, default))
706 attrs.get(key, default))
707 fixers[name]._priority = int(fixers[name]._priority)
707 fixers[name]._priority = int(fixers[name]._priority)
708 # Don't use a fixer if it has no pattern configured. It would be
709 # dangerous to let it affect all files. It would be pointless to let it
710 # affect no files. There is no reasonable subset of files to use as the
711 # default.
712 if fixers[name]._pattern is None:
713 ui.warn(
714 _('fixer tool has no pattern configuration: %s\n') % (name,))
715 del fixers[name]
708 return collections.OrderedDict(
716 return collections.OrderedDict(
709 sorted(fixers.items(), key=lambda item: item[1]._priority,
717 sorted(fixers.items(), key=lambda item: item[1]._priority,
710 reverse=True))
718 reverse=True))
@@ -722,7 +730,8 b' class Fixer(object):'
722
730
723 def affects(self, opts, fixctx, path):
731 def affects(self, opts, fixctx, path):
724 """Should this fixer run on the file at the given path and context?"""
732 """Should this fixer run on the file at the given path and context?"""
725 return scmutil.match(fixctx, [self._pattern], opts)(path)
733 return (self._pattern is not None and
734 scmutil.match(fixctx, [self._pattern], opts)(path))
726
735
727 def shouldoutputmetadata(self):
736 def shouldoutputmetadata(self):
728 """Should the stdout of this fixer start with JSON and a null byte?"""
737 """Should the stdout of this fixer start with JSON and a null byte?"""
@@ -1242,6 +1242,26 b' three revisions instead of two.'
1242
1242
1243 $ cd ..
1243 $ cd ..
1244
1244
1245 Tools configured without a pattern are ignored. It would be too dangerous to
1246 run them on all files, because this might happen while testing a configuration
1247 that also deletes all of the file content. There is no reasonable subset of the
1248 files to use as a default. Users should be explicit about what files are
1249 affected by a tool. This test also confirms that we don't crash when the
1250 pattern config is missing, and that we only warn about it once.
1251
1252 $ hg init nopatternconfigured
1253 $ cd nopatternconfigured
1254
1255 $ printf "foo" > foo
1256 $ printf "bar" > bar
1257 $ hg add -q
1258 $ hg fix --debug --working-dir --config "fix.nopattern:command=echo fixed"
1259 fixer tool has no pattern configuration: nopattern
1260 $ cat foo bar
1261 foobar (no-eol)
1262
1263 $ cd ..
1264
1245 Test that we can configure a fixer to affect all files regardless of the cwd.
1265 Test that we can configure a fixer to affect all files regardless of the cwd.
1246 The way we invoke matching must not prohibit this.
1266 The way we invoke matching must not prohibit this.
1247
1267
General Comments 0
You need to be logged in to leave comments. Login now