comparison tests/test-fix.t @ 42756:ed0da6e0d6ee

fix: allow tools to use :linerange, but also run if a file is unchanged The definition of "unchanged" here is subtle, because pure deletion diff hunks are ignored. That means this is different from using the --whole flag. This change allows you to configure, for example, a code formatter that: 1. Formats specific line ranges if specified via flags 2. Does not format the entire file when there are no line ranges provided 3. Performs some other kind of formatting regardless of provided line ranges This sounds a little far fetched, but it is meant to address a specific corner case encountered in Google's use of the fix extension. The default behavior is kept because it exists to prevent mistakes that could erase uncommitted changes. Differential Revision: https://phab.mercurial-scm.org/D6723
author Danny Hooper <hooper@google.com>
date Mon, 12 Aug 2019 16:39:39 -0700
parents 74b4cd091e0d
children 34a46d48d24e
comparison
equal deleted inserted replaced
42755:749ef8c31187 42756:ed0da6e0d6ee
145 substituted into the command: 145 substituted into the command:
146 146
147 {first} The 1-based line number of the first line in the modified range 147 {first} The 1-based line number of the first line in the modified range
148 {last} The 1-based line number of the last line in the modified range 148 {last} The 1-based line number of the last line in the modified range
149 149
150 Deleted sections of a file will be ignored by :linerange, because there is no
151 corresponding line range in the version being fixed.
152
153 By default, tools that set :linerange will only be executed if there is at
154 least one changed line range. This is meant to prevent accidents like running
155 a code formatter in such a way that it unexpectedly reformats the whole file.
156 If such a tool needs to operate on unchanged files, it should set the
157 :skipclean suboption to false.
158
150 The :pattern suboption determines which files will be passed through each 159 The :pattern suboption determines which files will be passed through each
151 configured tool. See 'hg help patterns' for possible values. If there are file 160 configured tool. See 'hg help patterns' for possible values. If there are file
152 arguments to 'hg fix', the intersection of these patterns is used. 161 arguments to 'hg fix', the intersection of these patterns is used.
153 162
154 There is also a configurable limit for the maximum size of file that will be 163 There is also a configurable limit for the maximum size of file that will be
1354 fixed 1363 fixed
1355 $ cat baz_file 1364 $ cat baz_file
1356 fixed 1365 fixed
1357 1366
1358 $ cd .. 1367 $ cd ..
1368
1369 Tools should be able to run on unchanged files, even if they set :linerange.
1370 This includes a corner case where deleted chunks of a file are not considered
1371 changes.
1372
1373 $ hg init skipclean
1374 $ cd skipclean
1375
1376 $ printf "a\nb\nc\n" > foo
1377 $ printf "a\nb\nc\n" > bar
1378 $ printf "a\nb\nc\n" > baz
1379 $ hg commit -Aqm "base"
1380
1381 $ printf "a\nc\n" > foo
1382 $ printf "a\nx\nc\n" > baz
1383
1384 $ hg fix --working-dir foo bar baz \
1385 > --config 'fix.changedlines:command=printf "Line ranges:\n"; ' \
1386 > --config 'fix.changedlines:linerange=printf "{first} through {last}\n"; ' \
1387 > --config 'fix.changedlines:pattern=rootglob:**' \
1388 > --config 'fix.changedlines:skipclean=false'
1389
1390 $ cat foo
1391 Line ranges:
1392 $ cat bar
1393 Line ranges:
1394 $ cat baz
1395 Line ranges:
1396 2 through 2
1397
1398 $ cd ..