##// END OF EJS Templates
tests: update divergence test for `hg fix` to actually result in divergence...
Martin von Zweigbergk -
r47594:d083c120 default
parent child Browse files
Show More
@@ -1,1693 +1,1692 b''
1 1 A script that implements uppercasing of specific lines in a file. This
2 2 approximates the behavior of code formatters well enough for our tests.
3 3
4 4 $ UPPERCASEPY="$TESTTMP/uppercase.py"
5 5 $ cat > $UPPERCASEPY <<EOF
6 6 > import sys
7 7 > from mercurial.utils.procutil import setbinary
8 8 > setbinary(sys.stdin)
9 9 > setbinary(sys.stdout)
10 10 > lines = set()
11 11 > for arg in sys.argv[1:]:
12 12 > if arg == 'all':
13 13 > sys.stdout.write(sys.stdin.read().upper())
14 14 > sys.exit(0)
15 15 > else:
16 16 > first, last = arg.split('-')
17 17 > lines.update(range(int(first), int(last) + 1))
18 18 > for i, line in enumerate(sys.stdin.readlines()):
19 19 > if i + 1 in lines:
20 20 > sys.stdout.write(line.upper())
21 21 > else:
22 22 > sys.stdout.write(line)
23 23 > EOF
24 24 $ TESTLINES="foo\nbar\nbaz\nqux\n"
25 25 $ printf $TESTLINES | "$PYTHON" $UPPERCASEPY
26 26 foo
27 27 bar
28 28 baz
29 29 qux
30 30 $ printf $TESTLINES | "$PYTHON" $UPPERCASEPY all
31 31 FOO
32 32 BAR
33 33 BAZ
34 34 QUX
35 35 $ printf $TESTLINES | "$PYTHON" $UPPERCASEPY 1-1
36 36 FOO
37 37 bar
38 38 baz
39 39 qux
40 40 $ printf $TESTLINES | "$PYTHON" $UPPERCASEPY 1-2
41 41 FOO
42 42 BAR
43 43 baz
44 44 qux
45 45 $ printf $TESTLINES | "$PYTHON" $UPPERCASEPY 2-3
46 46 foo
47 47 BAR
48 48 BAZ
49 49 qux
50 50 $ printf $TESTLINES | "$PYTHON" $UPPERCASEPY 2-2 4-4
51 51 foo
52 52 BAR
53 53 baz
54 54 QUX
55 55
56 56 Set up the config with two simple fixers: one that fixes specific line ranges,
57 57 and one that always fixes the whole file. They both "fix" files by converting
58 58 letters to uppercase. They use different file extensions, so each test case can
59 59 choose which behavior to use by naming files.
60 60
61 61 $ cat >> $HGRCPATH <<EOF
62 62 > [extensions]
63 63 > fix =
64 64 > [experimental]
65 65 > evolution.createmarkers=True
66 66 > evolution.allowunstable=True
67 67 > [fix]
68 68 > uppercase-whole-file:command="$PYTHON" $UPPERCASEPY all
69 69 > uppercase-whole-file:pattern=set:**.whole
70 70 > uppercase-changed-lines:command="$PYTHON" $UPPERCASEPY
71 71 > uppercase-changed-lines:linerange={first}-{last}
72 72 > uppercase-changed-lines:pattern=set:**.changed
73 73 > EOF
74 74
75 75 Help text for fix.
76 76
77 77 $ hg help fix
78 78 hg fix [OPTION]... [FILE]...
79 79
80 80 rewrite file content in changesets or working directory
81 81
82 82 Runs any configured tools to fix the content of files. Only affects files
83 83 with changes, unless file arguments are provided. Only affects changed
84 84 lines of files, unless the --whole flag is used. Some tools may always
85 85 affect the whole file regardless of --whole.
86 86
87 87 If --working-dir is used, files with uncommitted changes in the working
88 88 copy will be fixed. Note that no backup are made.
89 89
90 90 If revisions are specified with --source, those revisions and their
91 91 descendants will be checked, and they may be replaced with new revisions
92 92 that have fixed file content. By automatically including the descendants,
93 93 no merging, rebasing, or evolution will be required. If an ancestor of the
94 94 working copy is included, then the working copy itself will also be fixed,
95 95 and the working copy will be updated to the fixed parent.
96 96
97 97 When determining what lines of each file to fix at each revision, the
98 98 whole set of revisions being fixed is considered, so that fixes to earlier
99 99 revisions are not forgotten in later ones. The --base flag can be used to
100 100 override this default behavior, though it is not usually desirable to do
101 101 so.
102 102
103 103 (use 'hg help -e fix' to show help for the fix extension)
104 104
105 105 options ([+] can be repeated):
106 106
107 107 --all fix all non-public non-obsolete revisions
108 108 --base REV [+] revisions to diff against (overrides automatic selection,
109 109 and applies to every revision being fixed)
110 110 -s --source REV [+] fix the specified revisions and their descendants
111 111 -w --working-dir fix the working directory
112 112 --whole always fix every line of a file
113 113
114 114 (some details hidden, use --verbose to show complete help)
115 115
116 116 $ hg help -e fix
117 117 fix extension - rewrite file content in changesets or working copy
118 118 (EXPERIMENTAL)
119 119
120 120 Provides a command that runs configured tools on the contents of modified
121 121 files, writing back any fixes to the working copy or replacing changesets.
122 122
123 123 Here is an example configuration that causes 'hg fix' to apply automatic
124 124 formatting fixes to modified lines in C++ code:
125 125
126 126 [fix]
127 127 clang-format:command=clang-format --assume-filename={rootpath}
128 128 clang-format:linerange=--lines={first}:{last}
129 129 clang-format:pattern=set:**.cpp or **.hpp
130 130
131 131 The :command suboption forms the first part of the shell command that will be
132 132 used to fix a file. The content of the file is passed on standard input, and
133 133 the fixed file content is expected on standard output. Any output on standard
134 134 error will be displayed as a warning. If the exit status is not zero, the file
135 135 will not be affected. A placeholder warning is displayed if there is a non-
136 136 zero exit status but no standard error output. Some values may be substituted
137 137 into the command:
138 138
139 139 {rootpath} The path of the file being fixed, relative to the repo root
140 140 {basename} The name of the file being fixed, without the directory path
141 141
142 142 If the :linerange suboption is set, the tool will only be run if there are
143 143 changed lines in a file. The value of this suboption is appended to the shell
144 144 command once for every range of changed lines in the file. Some values may be
145 145 substituted into the command:
146 146
147 147 {first} The 1-based line number of the first line in the modified range
148 148 {last} The 1-based line number of the last line in the modified range
149 149
150 150 Deleted sections of a file will be ignored by :linerange, because there is no
151 151 corresponding line range in the version being fixed.
152 152
153 153 By default, tools that set :linerange will only be executed if there is at
154 154 least one changed line range. This is meant to prevent accidents like running
155 155 a code formatter in such a way that it unexpectedly reformats the whole file.
156 156 If such a tool needs to operate on unchanged files, it should set the
157 157 :skipclean suboption to false.
158 158
159 159 The :pattern suboption determines which files will be passed through each
160 160 configured tool. See 'hg help patterns' for possible values. However, all
161 161 patterns are relative to the repo root, even if that text says they are
162 162 relative to the current working directory. If there are file arguments to 'hg
163 163 fix', the intersection of these patterns is used.
164 164
165 165 There is also a configurable limit for the maximum size of file that will be
166 166 processed by 'hg fix':
167 167
168 168 [fix]
169 169 maxfilesize = 2MB
170 170
171 171 Normally, execution of configured tools will continue after a failure
172 172 (indicated by a non-zero exit status). It can also be configured to abort
173 173 after the first such failure, so that no files will be affected if any tool
174 174 fails. This abort will also cause 'hg fix' to exit with a non-zero status:
175 175
176 176 [fix]
177 177 failure = abort
178 178
179 179 When multiple tools are configured to affect a file, they execute in an order
180 180 defined by the :priority suboption. The priority suboption has a default value
181 181 of zero for each tool. Tools are executed in order of descending priority. The
182 182 execution order of tools with equal priority is unspecified. For example, you
183 183 could use the 'sort' and 'head' utilities to keep only the 10 smallest numbers
184 184 in a text file by ensuring that 'sort' runs before 'head':
185 185
186 186 [fix]
187 187 sort:command = sort -n
188 188 head:command = head -n 10
189 189 sort:pattern = numbers.txt
190 190 head:pattern = numbers.txt
191 191 sort:priority = 2
192 192 head:priority = 1
193 193
194 194 To account for changes made by each tool, the line numbers used for
195 195 incremental formatting are recomputed before executing the next tool. So, each
196 196 tool may see different values for the arguments added by the :linerange
197 197 suboption.
198 198
199 199 Each fixer tool is allowed to return some metadata in addition to the fixed
200 200 file content. The metadata must be placed before the file content on stdout,
201 201 separated from the file content by a zero byte. The metadata is parsed as a
202 202 JSON value (so, it should be UTF-8 encoded and contain no zero bytes). A fixer
203 203 tool is expected to produce this metadata encoding if and only if the
204 204 :metadata suboption is true:
205 205
206 206 [fix]
207 207 tool:command = tool --prepend-json-metadata
208 208 tool:metadata = true
209 209
210 210 The metadata values are passed to hooks, which can be used to print summaries
211 211 or perform other post-fixing work. The supported hooks are:
212 212
213 213 "postfixfile"
214 214 Run once for each file in each revision where any fixer tools made changes
215 215 to the file content. Provides "$HG_REV" and "$HG_PATH" to identify the file,
216 216 and "$HG_METADATA" with a map of fixer names to metadata values from fixer
217 217 tools that affected the file. Fixer tools that didn't affect the file have a
218 218 value of None. Only fixer tools that executed are present in the metadata.
219 219
220 220 "postfix"
221 221 Run once after all files and revisions have been handled. Provides
222 222 "$HG_REPLACEMENTS" with information about what revisions were created and
223 223 made obsolete. Provides a boolean "$HG_WDIRWRITTEN" to indicate whether any
224 224 files in the working copy were updated. Provides a list "$HG_METADATA"
225 225 mapping fixer tool names to lists of metadata values returned from
226 226 executions that modified a file. This aggregates the same metadata
227 227 previously passed to the "postfixfile" hook.
228 228
229 229 Fixer tools are run in the repository's root directory. This allows them to
230 230 read configuration files from the working copy, or even write to the working
231 231 copy. The working copy is not updated to match the revision being fixed. In
232 232 fact, several revisions may be fixed in parallel. Writes to the working copy
233 233 are not amended into the revision being fixed; fixer tools should always write
234 234 fixed file content back to stdout as documented above.
235 235
236 236 list of commands:
237 237
238 238 fix rewrite file content in changesets or working directory
239 239
240 240 (use 'hg help -v -e fix' to show built-in aliases and global options)
241 241
242 242 There is no default behavior in the absence of --rev and --working-dir.
243 243
244 244 $ hg init badusage
245 245 $ cd badusage
246 246
247 247 $ hg fix
248 248 abort: no changesets specified
249 249 (use --source or --working-dir)
250 250 [255]
251 251 $ hg fix --whole
252 252 abort: no changesets specified
253 253 (use --source or --working-dir)
254 254 [255]
255 255 $ hg fix --base 0
256 256 abort: no changesets specified
257 257 (use --source or --working-dir)
258 258 [255]
259 259
260 260 Fixing a public revision isn't allowed. It should abort early enough that
261 261 nothing happens, even to the working directory.
262 262
263 263 $ printf "hello\n" > hello.whole
264 264 $ hg commit -Aqm "hello"
265 265 $ hg phase -r 0 --public
266 266 $ hg fix -r 0
267 267 abort: cannot fix public changesets
268 268 (see 'hg help phases' for details)
269 269 [10]
270 270 $ hg fix -r 0 --working-dir
271 271 abort: cannot fix public changesets
272 272 (see 'hg help phases' for details)
273 273 [10]
274 274 $ hg cat -r tip hello.whole
275 275 hello
276 276 $ cat hello.whole
277 277 hello
278 278
279 279 $ cd ..
280 280
281 281 Fixing a clean working directory should do nothing. Even the --whole flag
282 282 shouldn't cause any clean files to be fixed. Specifying a clean file explicitly
283 283 should only fix it if the fixer always fixes the whole file. The combination of
284 284 an explicit filename and --whole should format the entire file regardless.
285 285
286 286 $ hg init fixcleanwdir
287 287 $ cd fixcleanwdir
288 288
289 289 $ printf "hello\n" > hello.changed
290 290 $ printf "world\n" > hello.whole
291 291 $ hg commit -Aqm "foo"
292 292 $ hg fix --working-dir
293 293 $ hg diff
294 294 $ hg fix --working-dir --whole
295 295 $ hg diff
296 296 $ hg fix --working-dir *
297 297 $ cat *
298 298 hello
299 299 WORLD
300 300 $ hg revert --all --no-backup
301 301 reverting hello.whole
302 302 $ hg fix --working-dir * --whole
303 303 $ cat *
304 304 HELLO
305 305 WORLD
306 306
307 307 The same ideas apply to fixing a revision, so we create a revision that doesn't
308 308 modify either of the files in question and try fixing it. This also tests that
309 309 we ignore a file that doesn't match any configured fixer.
310 310
311 311 $ hg revert --all --no-backup
312 312 reverting hello.changed
313 313 reverting hello.whole
314 314 $ printf "unimportant\n" > some.file
315 315 $ hg commit -Aqm "some other file"
316 316
317 317 $ hg fix -r .
318 318 $ hg cat -r tip *
319 319 hello
320 320 world
321 321 unimportant
322 322 $ hg fix -r . --whole
323 323 $ hg cat -r tip *
324 324 hello
325 325 world
326 326 unimportant
327 327 $ hg fix -r . *
328 328 $ hg cat -r tip *
329 329 hello
330 330 WORLD
331 331 unimportant
332 332 $ hg fix -r . * --whole --config experimental.evolution.allowdivergence=true
333 333 2 new content-divergent changesets
334 334 $ hg cat -r tip *
335 335 HELLO
336 336 WORLD
337 337 unimportant
338 338
339 339 $ cd ..
340 340
341 341 Fixing the working directory should still work if there are no revisions.
342 342
343 343 $ hg init norevisions
344 344 $ cd norevisions
345 345
346 346 $ printf "something\n" > something.whole
347 347 $ hg add
348 348 adding something.whole
349 349 $ hg fix --working-dir
350 350 $ cat something.whole
351 351 SOMETHING
352 352
353 353 $ cd ..
354 354
355 355 Test the effect of fixing the working directory for each possible status, with
356 356 and without providing explicit file arguments.
357 357
358 358 $ hg init implicitlyfixstatus
359 359 $ cd implicitlyfixstatus
360 360
361 361 $ printf "modified\n" > modified.whole
362 362 $ printf "removed\n" > removed.whole
363 363 $ printf "deleted\n" > deleted.whole
364 364 $ printf "clean\n" > clean.whole
365 365 $ printf "ignored.whole" > .hgignore
366 366 $ hg commit -Aqm "stuff"
367 367
368 368 $ printf "modified!!!\n" > modified.whole
369 369 $ printf "unknown\n" > unknown.whole
370 370 $ printf "ignored\n" > ignored.whole
371 371 $ printf "added\n" > added.whole
372 372 $ hg add added.whole
373 373 $ hg remove removed.whole
374 374 $ rm deleted.whole
375 375
376 376 $ hg status --all
377 377 M modified.whole
378 378 A added.whole
379 379 R removed.whole
380 380 ! deleted.whole
381 381 ? unknown.whole
382 382 I ignored.whole
383 383 C .hgignore
384 384 C clean.whole
385 385
386 386 $ hg fix --working-dir
387 387
388 388 $ hg status --all
389 389 M modified.whole
390 390 A added.whole
391 391 R removed.whole
392 392 ! deleted.whole
393 393 ? unknown.whole
394 394 I ignored.whole
395 395 C .hgignore
396 396 C clean.whole
397 397
398 398 $ cat *.whole
399 399 ADDED
400 400 clean
401 401 ignored
402 402 MODIFIED!!!
403 403 unknown
404 404
405 405 $ printf "modified!!!\n" > modified.whole
406 406 $ printf "added\n" > added.whole
407 407
408 408 Listing the files explicitly causes untracked files to also be fixed, but
409 409 ignored files are still unaffected.
410 410
411 411 $ hg fix --working-dir *.whole
412 412
413 413 $ hg status --all
414 414 M clean.whole
415 415 M modified.whole
416 416 A added.whole
417 417 R removed.whole
418 418 ! deleted.whole
419 419 ? unknown.whole
420 420 I ignored.whole
421 421 C .hgignore
422 422
423 423 $ cat *.whole
424 424 ADDED
425 425 CLEAN
426 426 ignored
427 427 MODIFIED!!!
428 428 UNKNOWN
429 429
430 430 $ cd ..
431 431
432 432 Test that incremental fixing works on files with additions, deletions, and
433 433 changes in multiple line ranges. Note that deletions do not generally cause
434 434 neighboring lines to be fixed, so we don't return a line range for purely
435 435 deleted sections. In the future we should support a :deletion config that
436 436 allows fixers to know where deletions are located.
437 437
438 438 $ hg init incrementalfixedlines
439 439 $ cd incrementalfixedlines
440 440
441 441 $ printf "a\nb\nc\nd\ne\nf\ng\n" > foo.txt
442 442 $ hg commit -Aqm "foo"
443 443 $ printf "zz\na\nc\ndd\nee\nff\nf\ngg\n" > foo.txt
444 444
445 445 $ hg --config "fix.fail:command=echo" \
446 446 > --config "fix.fail:linerange={first}:{last}" \
447 447 > --config "fix.fail:pattern=foo.txt" \
448 448 > fix --working-dir
449 449 $ cat foo.txt
450 450 1:1 4:6 8:8
451 451
452 452 $ cd ..
453 453
454 454 Test that --whole fixes all lines regardless of the diffs present.
455 455
456 456 $ hg init wholeignoresdiffs
457 457 $ cd wholeignoresdiffs
458 458
459 459 $ printf "a\nb\nc\nd\ne\nf\ng\n" > foo.changed
460 460 $ hg commit -Aqm "foo"
461 461 $ printf "zz\na\nc\ndd\nee\nff\nf\ngg\n" > foo.changed
462 462
463 463 $ hg fix --working-dir
464 464 $ cat foo.changed
465 465 ZZ
466 466 a
467 467 c
468 468 DD
469 469 EE
470 470 FF
471 471 f
472 472 GG
473 473
474 474 $ hg fix --working-dir --whole
475 475 $ cat foo.changed
476 476 ZZ
477 477 A
478 478 C
479 479 DD
480 480 EE
481 481 FF
482 482 F
483 483 GG
484 484
485 485 $ cd ..
486 486
487 487 We should do nothing with symlinks, and their targets should be unaffected. Any
488 488 other behavior would be more complicated to implement and harder to document.
489 489
490 490 #if symlink
491 491 $ hg init dontmesswithsymlinks
492 492 $ cd dontmesswithsymlinks
493 493
494 494 $ printf "hello\n" > hello.whole
495 495 $ ln -s hello.whole hellolink
496 496 $ hg add
497 497 adding hello.whole
498 498 adding hellolink
499 499 $ hg fix --working-dir hellolink
500 500 $ hg status
501 501 A hello.whole
502 502 A hellolink
503 503
504 504 $ cd ..
505 505 #endif
506 506
507 507 We should allow fixers to run on binary files, even though this doesn't sound
508 508 like a common use case. There's not much benefit to disallowing it, and users
509 509 can add "and not binary()" to their filesets if needed. The Mercurial
510 510 philosophy is generally to not handle binary files specially anyway.
511 511
512 512 $ hg init cantouchbinaryfiles
513 513 $ cd cantouchbinaryfiles
514 514
515 515 $ printf "hello\0\n" > hello.whole
516 516 $ hg add
517 517 adding hello.whole
518 518 $ hg fix --working-dir 'set:binary()'
519 519 $ cat hello.whole
520 520 HELLO\x00 (esc)
521 521
522 522 $ cd ..
523 523
524 524 We have a config for the maximum size of file we will attempt to fix. This can
525 525 be helpful to avoid running unsuspecting fixer tools on huge inputs, which
526 526 could happen by accident without a well considered configuration. A more
527 527 precise configuration could use the size() fileset function if one global limit
528 528 is undesired.
529 529
530 530 $ hg init maxfilesize
531 531 $ cd maxfilesize
532 532
533 533 $ printf "this file is huge\n" > hello.whole
534 534 $ hg add
535 535 adding hello.whole
536 536 $ hg --config fix.maxfilesize=10 fix --working-dir
537 537 ignoring file larger than 10 bytes: hello.whole
538 538 $ cat hello.whole
539 539 this file is huge
540 540
541 541 $ cd ..
542 542
543 543 If we specify a file to fix, other files should be left alone, even if they
544 544 have changes.
545 545
546 546 $ hg init fixonlywhatitellyouto
547 547 $ cd fixonlywhatitellyouto
548 548
549 549 $ printf "fix me!\n" > fixme.whole
550 550 $ printf "not me.\n" > notme.whole
551 551 $ hg add
552 552 adding fixme.whole
553 553 adding notme.whole
554 554 $ hg fix --working-dir fixme.whole
555 555 $ cat *.whole
556 556 FIX ME!
557 557 not me.
558 558
559 559 $ cd ..
560 560
561 561 If we try to fix a missing file, we still fix other files.
562 562
563 563 $ hg init fixmissingfile
564 564 $ cd fixmissingfile
565 565
566 566 $ printf "fix me!\n" > foo.whole
567 567 $ hg add
568 568 adding foo.whole
569 569 $ hg fix --working-dir foo.whole bar.whole
570 570 bar.whole: $ENOENT$
571 571 $ cat *.whole
572 572 FIX ME!
573 573
574 574 $ cd ..
575 575
576 576 Specifying a directory name should fix all its files and subdirectories.
577 577
578 578 $ hg init fixdirectory
579 579 $ cd fixdirectory
580 580
581 581 $ mkdir -p dir1/dir2
582 582 $ printf "foo\n" > foo.whole
583 583 $ printf "bar\n" > dir1/bar.whole
584 584 $ printf "baz\n" > dir1/dir2/baz.whole
585 585 $ hg add
586 586 adding dir1/bar.whole
587 587 adding dir1/dir2/baz.whole
588 588 adding foo.whole
589 589 $ hg fix --working-dir dir1
590 590 $ cat foo.whole dir1/bar.whole dir1/dir2/baz.whole
591 591 foo
592 592 BAR
593 593 BAZ
594 594
595 595 $ cd ..
596 596
597 597 Fixing a file in the working directory that needs no fixes should not actually
598 598 write back to the file, so for example the mtime shouldn't change.
599 599
600 600 $ hg init donttouchunfixedfiles
601 601 $ cd donttouchunfixedfiles
602 602
603 603 $ printf "NO FIX NEEDED\n" > foo.whole
604 604 $ hg add
605 605 adding foo.whole
606 606 $ cp -p foo.whole foo.whole.orig
607 607 $ cp -p foo.whole.orig foo.whole
608 608 $ sleep 2 # mtime has a resolution of one or two seconds.
609 609 $ hg fix --working-dir
610 610 $ f foo.whole.orig --newer foo.whole
611 611 foo.whole.orig: newer than foo.whole
612 612
613 613 $ cd ..
614 614
615 615 When a fixer prints to stderr, we don't assume that it has failed. We show the
616 616 error messages to the user, and we still let the fixer affect the file it was
617 617 fixing if its exit code is zero. Some code formatters might emit error messages
618 618 on stderr and nothing on stdout, which would cause us the clear the file,
619 619 except that they also exit with a non-zero code. We show the user which fixer
620 620 emitted the stderr, and which revision, but we assume that the fixer will print
621 621 the filename if it is relevant (since the issue may be non-specific). There is
622 622 also a config to abort (without affecting any files whatsoever) if we see any
623 623 tool with a non-zero exit status.
624 624
625 625 $ hg init showstderr
626 626 $ cd showstderr
627 627
628 628 $ printf "hello\n" > hello.txt
629 629 $ hg add
630 630 adding hello.txt
631 631 $ cat > $TESTTMP/work.sh <<'EOF'
632 632 > printf 'HELLO\n'
633 633 > printf "$@: some\nerror that didn't stop the tool" >&2
634 634 > exit 0 # success despite the stderr output
635 635 > EOF
636 636 $ hg --config "fix.work:command=sh $TESTTMP/work.sh {rootpath}" \
637 637 > --config "fix.work:pattern=hello.txt" \
638 638 > fix --working-dir
639 639 [wdir] work: hello.txt: some
640 640 [wdir] work: error that didn't stop the tool
641 641 $ cat hello.txt
642 642 HELLO
643 643
644 644 $ printf "goodbye\n" > hello.txt
645 645 $ printf "foo\n" > foo.whole
646 646 $ hg add
647 647 adding foo.whole
648 648 $ cat > $TESTTMP/fail.sh <<'EOF'
649 649 > printf 'GOODBYE\n'
650 650 > printf "$@: some\nerror that did stop the tool\n" >&2
651 651 > exit 42 # success despite the stdout output
652 652 > EOF
653 653 $ hg --config "fix.fail:command=sh $TESTTMP/fail.sh {rootpath}" \
654 654 > --config "fix.fail:pattern=hello.txt" \
655 655 > --config "fix.failure=abort" \
656 656 > fix --working-dir
657 657 [wdir] fail: hello.txt: some
658 658 [wdir] fail: error that did stop the tool
659 659 abort: no fixes will be applied
660 660 (use --config fix.failure=continue to apply any successful fixes anyway)
661 661 [255]
662 662 $ cat hello.txt
663 663 goodbye
664 664 $ cat foo.whole
665 665 foo
666 666
667 667 $ hg --config "fix.fail:command=sh $TESTTMP/fail.sh {rootpath}" \
668 668 > --config "fix.fail:pattern=hello.txt" \
669 669 > fix --working-dir
670 670 [wdir] fail: hello.txt: some
671 671 [wdir] fail: error that did stop the tool
672 672 $ cat hello.txt
673 673 goodbye
674 674 $ cat foo.whole
675 675 FOO
676 676
677 677 $ hg --config "fix.fail:command=exit 42" \
678 678 > --config "fix.fail:pattern=hello.txt" \
679 679 > fix --working-dir
680 680 [wdir] fail: exited with status 42
681 681
682 682 $ cd ..
683 683
684 684 Fixing the working directory and its parent revision at the same time should
685 685 check out the replacement revision for the parent. This prevents any new
686 686 uncommitted changes from appearing. We test this for a clean working directory
687 687 and a dirty one. In both cases, all lines/files changed since the grandparent
688 688 will be fixed. The grandparent is the "baserev" for both the parent and the
689 689 working copy.
690 690
691 691 $ hg init fixdotandcleanwdir
692 692 $ cd fixdotandcleanwdir
693 693
694 694 $ printf "hello\n" > hello.whole
695 695 $ printf "world\n" > world.whole
696 696 $ hg commit -Aqm "the parent commit"
697 697
698 698 $ hg parents --template '{rev} {desc}\n'
699 699 0 the parent commit
700 700 $ hg fix --working-dir -r .
701 701 $ hg parents --template '{rev} {desc}\n'
702 702 1 the parent commit
703 703 $ hg cat -r . *.whole
704 704 HELLO
705 705 WORLD
706 706 $ cat *.whole
707 707 HELLO
708 708 WORLD
709 709 $ hg status
710 710
711 711 $ cd ..
712 712
713 713 Same test with a dirty working copy.
714 714
715 715 $ hg init fixdotanddirtywdir
716 716 $ cd fixdotanddirtywdir
717 717
718 718 $ printf "hello\n" > hello.whole
719 719 $ printf "world\n" > world.whole
720 720 $ hg commit -Aqm "the parent commit"
721 721
722 722 $ printf "hello,\n" > hello.whole
723 723 $ printf "world!\n" > world.whole
724 724
725 725 $ hg parents --template '{rev} {desc}\n'
726 726 0 the parent commit
727 727 $ hg fix --working-dir -r .
728 728 $ hg parents --template '{rev} {desc}\n'
729 729 1 the parent commit
730 730 $ hg cat -r . *.whole
731 731 HELLO
732 732 WORLD
733 733 $ cat *.whole
734 734 HELLO,
735 735 WORLD!
736 736 $ hg status
737 737 M hello.whole
738 738 M world.whole
739 739
740 740 $ cd ..
741 741
742 742 When we have a chain of commits that change mutually exclusive lines of code,
743 743 we should be able to do incremental fixing that causes each commit in the chain
744 744 to include fixes made to the previous commits. This prevents children from
745 745 backing out the fixes made in their parents. A dirty working directory is
746 746 conceptually similar to another commit in the chain.
747 747
748 748 $ hg init incrementallyfixchain
749 749 $ cd incrementallyfixchain
750 750
751 751 $ cat > file.changed <<EOF
752 752 > first
753 753 > second
754 754 > third
755 755 > fourth
756 756 > fifth
757 757 > EOF
758 758 $ hg commit -Aqm "the common ancestor (the baserev)"
759 759 $ cat > file.changed <<EOF
760 760 > first (changed)
761 761 > second
762 762 > third
763 763 > fourth
764 764 > fifth
765 765 > EOF
766 766 $ hg commit -Aqm "the first commit to fix"
767 767 $ cat > file.changed <<EOF
768 768 > first (changed)
769 769 > second
770 770 > third (changed)
771 771 > fourth
772 772 > fifth
773 773 > EOF
774 774 $ hg commit -Aqm "the second commit to fix"
775 775 $ cat > file.changed <<EOF
776 776 > first (changed)
777 777 > second
778 778 > third (changed)
779 779 > fourth
780 780 > fifth (changed)
781 781 > EOF
782 782
783 783 $ hg fix -r . -r '.^' --working-dir
784 784
785 785 $ hg parents --template '{rev}\n'
786 786 4
787 787 $ hg cat -r '.^^' file.changed
788 788 first
789 789 second
790 790 third
791 791 fourth
792 792 fifth
793 793 $ hg cat -r '.^' file.changed
794 794 FIRST (CHANGED)
795 795 second
796 796 third
797 797 fourth
798 798 fifth
799 799 $ hg cat -r . file.changed
800 800 FIRST (CHANGED)
801 801 second
802 802 THIRD (CHANGED)
803 803 fourth
804 804 fifth
805 805 $ cat file.changed
806 806 FIRST (CHANGED)
807 807 second
808 808 THIRD (CHANGED)
809 809 fourth
810 810 FIFTH (CHANGED)
811 811
812 812 $ cd ..
813 813
814 814 If we incrementally fix a merge commit, we should fix any lines that changed
815 815 versus either parent. You could imagine only fixing the intersection or some
816 816 other subset, but this is necessary if either parent is being fixed. It
817 817 prevents us from forgetting fixes made in either parent.
818 818
819 819 $ hg init incrementallyfixmergecommit
820 820 $ cd incrementallyfixmergecommit
821 821
822 822 $ printf "a\nb\nc\n" > file.changed
823 823 $ hg commit -Aqm "ancestor"
824 824
825 825 $ printf "aa\nb\nc\n" > file.changed
826 826 $ hg commit -m "change a"
827 827
828 828 $ hg checkout '.^'
829 829 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
830 830 $ printf "a\nb\ncc\n" > file.changed
831 831 $ hg commit -m "change c"
832 832 created new head
833 833
834 834 $ hg merge
835 835 merging file.changed
836 836 0 files updated, 1 files merged, 0 files removed, 0 files unresolved
837 837 (branch merge, don't forget to commit)
838 838 $ hg commit -m "merge"
839 839 $ hg cat -r . file.changed
840 840 aa
841 841 b
842 842 cc
843 843
844 844 $ hg fix -r . --working-dir
845 845 $ hg cat -r . file.changed
846 846 AA
847 847 b
848 848 CC
849 849
850 850 $ cd ..
851 851
852 852 Abort fixing revisions if there is an unfinished operation. We don't want to
853 853 make things worse by editing files or stripping/obsoleting things. Also abort
854 854 fixing the working directory if there are unresolved merge conflicts.
855 855
856 856 $ hg init abortunresolved
857 857 $ cd abortunresolved
858 858
859 859 $ echo "foo1" > foo.whole
860 860 $ hg commit -Aqm "foo 1"
861 861
862 862 $ hg update null
863 863 0 files updated, 0 files merged, 1 files removed, 0 files unresolved
864 864 $ echo "foo2" > foo.whole
865 865 $ hg commit -Aqm "foo 2"
866 866
867 867 $ hg --config extensions.rebase= rebase -r 1 -d 0
868 868 rebasing 1:c3b6dc0e177a tip "foo 2"
869 869 merging foo.whole
870 870 warning: conflicts while merging foo.whole! (edit, then use 'hg resolve --mark')
871 871 unresolved conflicts (see 'hg resolve', then 'hg rebase --continue')
872 872 [240]
873 873
874 874 $ hg --config extensions.rebase= fix --working-dir
875 875 abort: unresolved conflicts
876 876 (use 'hg resolve')
877 877 [255]
878 878
879 879 $ hg --config extensions.rebase= fix -r .
880 880 abort: rebase in progress
881 881 (use 'hg rebase --continue', 'hg rebase --abort', or 'hg rebase --stop')
882 882 [20]
883 883
884 884 $ cd ..
885 885
886 886 When fixing a file that was renamed, we should diff against the source of the
887 887 rename for incremental fixing and we should correctly reproduce the rename in
888 888 the replacement revision.
889 889
890 890 $ hg init fixrenamecommit
891 891 $ cd fixrenamecommit
892 892
893 893 $ printf "a\nb\nc\n" > source.changed
894 894 $ hg commit -Aqm "source revision"
895 895 $ hg move source.changed dest.changed
896 896 $ printf "a\nb\ncc\n" > dest.changed
897 897 $ hg commit -m "dest revision"
898 898
899 899 $ hg fix -r .
900 900 $ hg log -r tip --copies --template "{file_copies}\n"
901 901 dest.changed (source.changed)
902 902 $ hg cat -r tip dest.changed
903 903 a
904 904 b
905 905 CC
906 906
907 907 $ cd ..
908 908
909 909 When fixing revisions that remove files we must ensure that the replacement
910 910 actually removes the file, whereas it could accidentally leave it unchanged or
911 911 write an empty string to it.
912 912
913 913 $ hg init fixremovedfile
914 914 $ cd fixremovedfile
915 915
916 916 $ printf "foo\n" > foo.whole
917 917 $ printf "bar\n" > bar.whole
918 918 $ hg commit -Aqm "add files"
919 919 $ hg remove bar.whole
920 920 $ hg commit -m "remove file"
921 921 $ hg status --change .
922 922 R bar.whole
923 923 $ hg fix -r . foo.whole
924 924 $ hg status --change tip
925 925 M foo.whole
926 926 R bar.whole
927 927
928 928 $ cd ..
929 929
930 930 If fixing a revision finds no fixes to make, no replacement revision should be
931 931 created.
932 932
933 933 $ hg init nofixesneeded
934 934 $ cd nofixesneeded
935 935
936 936 $ printf "FOO\n" > foo.whole
937 937 $ hg commit -Aqm "add file"
938 938 $ hg log --template '{rev}\n'
939 939 0
940 940 $ hg fix -r .
941 941 $ hg log --template '{rev}\n'
942 942 0
943 943
944 944 $ cd ..
945 945
946 946 If fixing a commit reverts all the changes in the commit, we replace it with a
947 947 commit that changes no files.
948 948
949 949 $ hg init nochangesleft
950 950 $ cd nochangesleft
951 951
952 952 $ printf "FOO\n" > foo.whole
953 953 $ hg commit -Aqm "add file"
954 954 $ printf "foo\n" > foo.whole
955 955 $ hg commit -m "edit file"
956 956 $ hg status --change .
957 957 M foo.whole
958 958 $ hg fix -r .
959 959 $ hg status --change tip
960 960
961 961 $ cd ..
962 962
963 963 If we fix a parent and child revision together, the child revision must be
964 964 replaced if the parent is replaced, even if the diffs of the child needed no
965 965 fixes. However, we're free to not replace revisions that need no fixes and have
966 966 no ancestors that are replaced.
967 967
968 968 $ hg init mustreplacechild
969 969 $ cd mustreplacechild
970 970
971 971 $ printf "FOO\n" > foo.whole
972 972 $ hg commit -Aqm "add foo"
973 973 $ printf "foo\n" > foo.whole
974 974 $ hg commit -m "edit foo"
975 975 $ printf "BAR\n" > bar.whole
976 976 $ hg commit -Aqm "add bar"
977 977
978 978 $ hg log --graph --template '{rev} {files}'
979 979 @ 2 bar.whole
980 980 |
981 981 o 1 foo.whole
982 982 |
983 983 o 0 foo.whole
984 984
985 985 $ hg fix -r 0:2
986 986 $ hg log --graph --template '{rev} {files}'
987 987 o 4 bar.whole
988 988 |
989 989 o 3
990 990 |
991 991 | @ 2 bar.whole
992 992 | |
993 993 | x 1 foo.whole
994 994 |/
995 995 o 0 foo.whole
996 996
997 997
998 998 $ cd ..
999 999
1000 1000 It's also possible that the child needs absolutely no changes, but we still
1001 1001 need to replace it to update its parent. If we skipped replacing the child
1002 1002 because it had no file content changes, it would become an orphan for no good
1003 1003 reason.
1004 1004
1005 1005 $ hg init mustreplacechildevenifnop
1006 1006 $ cd mustreplacechildevenifnop
1007 1007
1008 1008 $ printf "Foo\n" > foo.whole
1009 1009 $ hg commit -Aqm "add a bad foo"
1010 1010 $ printf "FOO\n" > foo.whole
1011 1011 $ hg commit -m "add a good foo"
1012 1012 $ hg fix -r . -r '.^'
1013 1013 $ hg log --graph --template '{rev} {desc}'
1014 1014 o 3 add a good foo
1015 1015 |
1016 1016 o 2 add a bad foo
1017 1017
1018 1018 @ 1 add a good foo
1019 1019 |
1020 1020 x 0 add a bad foo
1021 1021
1022 1022
1023 1023 $ cd ..
1024 1024
1025 1025 Similar to the case above, the child revision may become empty as a result of
1026 1026 fixing its parent. We should still create an empty replacement child.
1027 1027 TODO: determine how this should interact with ui.allowemptycommit given that
1028 1028 the empty replacement could have children.
1029 1029
1030 1030 $ hg init mustreplacechildevenifempty
1031 1031 $ cd mustreplacechildevenifempty
1032 1032
1033 1033 $ printf "foo\n" > foo.whole
1034 1034 $ hg commit -Aqm "add foo"
1035 1035 $ printf "Foo\n" > foo.whole
1036 1036 $ hg commit -m "edit foo"
1037 1037 $ hg fix -r . -r '.^'
1038 1038 $ hg log --graph --template '{rev} {desc}\n' --stat
1039 1039 o 3 edit foo
1040 1040 |
1041 1041 o 2 add foo
1042 1042 foo.whole | 1 +
1043 1043 1 files changed, 1 insertions(+), 0 deletions(-)
1044 1044
1045 1045 @ 1 edit foo
1046 1046 | foo.whole | 2 +-
1047 1047 | 1 files changed, 1 insertions(+), 1 deletions(-)
1048 1048 |
1049 1049 x 0 add foo
1050 1050 foo.whole | 1 +
1051 1051 1 files changed, 1 insertions(+), 0 deletions(-)
1052 1052
1053 1053
1054 1054 $ cd ..
1055 1055
1056 1056 Fixing a secret commit should replace it with another secret commit.
1057 1057
1058 1058 $ hg init fixsecretcommit
1059 1059 $ cd fixsecretcommit
1060 1060
1061 1061 $ printf "foo\n" > foo.whole
1062 1062 $ hg commit -Aqm "add foo" --secret
1063 1063 $ hg fix -r .
1064 1064 $ hg log --template '{rev} {phase}\n'
1065 1065 1 secret
1066 1066 0 secret
1067 1067
1068 1068 $ cd ..
1069 1069
1070 1070 We should also preserve phase when fixing a draft commit while the user has
1071 1071 their default set to secret.
1072 1072
1073 1073 $ hg init respectphasesnewcommit
1074 1074 $ cd respectphasesnewcommit
1075 1075
1076 1076 $ printf "foo\n" > foo.whole
1077 1077 $ hg commit -Aqm "add foo"
1078 1078 $ hg --config phases.newcommit=secret fix -r .
1079 1079 $ hg log --template '{rev} {phase}\n'
1080 1080 1 draft
1081 1081 0 draft
1082 1082
1083 1083 $ cd ..
1084 1084
1085 1085 Debug output should show what fixer commands are being subprocessed, which is
1086 1086 useful for anyone trying to set up a new config.
1087 1087
1088 1088 $ hg init debugoutput
1089 1089 $ cd debugoutput
1090 1090
1091 1091 $ printf "foo\nbar\nbaz\n" > foo.changed
1092 1092 $ hg commit -Aqm "foo"
1093 1093 $ printf "Foo\nbar\nBaz\n" > foo.changed
1094 1094 $ hg --debug fix --working-dir
1095 1095 subprocess: * $TESTTMP/uppercase.py 1-1 3-3 (glob)
1096 1096
1097 1097 $ cd ..
1098 1098
1099 1099 Fixing an obsolete revision can cause divergence, so we abort unless the user
1100 1100 configures to allow it. This is not yet smart enough to know whether there is a
1101 1101 successor, but even then it is not likely intentional or idiomatic to fix an
1102 1102 obsolete revision.
1103 1103
1104 1104 $ hg init abortobsoleterev
1105 1105 $ cd abortobsoleterev
1106 1106
1107 1107 $ printf "foo\n" > foo.changed
1108 1108 $ hg commit -Aqm "foo"
1109 $ hg debugobsolete `hg parents --template '{node}'`
1110 1 new obsolescence markers
1111 obsoleted 1 changesets
1109 $ hg ci --amend -m rewritten
1112 1110 $ hg --hidden fix -r 0
1113 1111 abort: fixing obsolete revision could cause divergence
1114 1112 [255]
1115 1113
1116 1114 $ hg --hidden fix -r 0 --config experimental.evolution.allowdivergence=true
1115 2 new content-divergent changesets
1117 1116 $ hg cat -r tip foo.changed
1118 1117 FOO
1119 1118
1120 1119 $ cd ..
1121 1120
1122 1121 Test all of the available substitution values for fixer commands.
1123 1122
1124 1123 $ hg init substitution
1125 1124 $ cd substitution
1126 1125
1127 1126 $ mkdir foo
1128 1127 $ printf "hello\ngoodbye\n" > foo/bar
1129 1128 $ hg add
1130 1129 adding foo/bar
1131 1130 $ hg --config "fix.fail:command=printf '%s\n' '{rootpath}' '{basename}'" \
1132 1131 > --config "fix.fail:linerange='{first}' '{last}'" \
1133 1132 > --config "fix.fail:pattern=foo/bar" \
1134 1133 > fix --working-dir
1135 1134 $ cat foo/bar
1136 1135 foo/bar
1137 1136 bar
1138 1137 1
1139 1138 2
1140 1139
1141 1140 $ cd ..
1142 1141
1143 1142 The --base flag should allow picking the revisions to diff against for changed
1144 1143 files and incremental line formatting.
1145 1144
1146 1145 $ hg init baseflag
1147 1146 $ cd baseflag
1148 1147
1149 1148 $ printf "one\ntwo\n" > foo.changed
1150 1149 $ printf "bar\n" > bar.changed
1151 1150 $ hg commit -Aqm "first"
1152 1151 $ printf "one\nTwo\n" > foo.changed
1153 1152 $ hg commit -m "second"
1154 1153 $ hg fix -w --base .
1155 1154 $ hg status
1156 1155 $ hg fix -w --base null
1157 1156 $ cat foo.changed
1158 1157 ONE
1159 1158 TWO
1160 1159 $ cat bar.changed
1161 1160 BAR
1162 1161
1163 1162 $ cd ..
1164 1163
1165 1164 If the user asks to fix the parent of another commit, they are asking to create
1166 1165 an orphan. We must respect experimental.evolution.allowunstable.
1167 1166
1168 1167 $ hg init allowunstable
1169 1168 $ cd allowunstable
1170 1169
1171 1170 $ printf "one\n" > foo.whole
1172 1171 $ hg commit -Aqm "first"
1173 1172 $ printf "two\n" > foo.whole
1174 1173 $ hg commit -m "second"
1175 1174 $ hg --config experimental.evolution.allowunstable=False fix -r '.^'
1176 1175 abort: cannot fix changeset with children
1177 1176 [10]
1178 1177 $ hg fix -r '.^'
1179 1178 1 new orphan changesets
1180 1179 $ hg cat -r 2 foo.whole
1181 1180 ONE
1182 1181
1183 1182 $ cd ..
1184 1183
1185 1184 The --base flag affects the set of files being fixed. So while the --whole flag
1186 1185 makes the base irrelevant for changed line ranges, it still changes the
1187 1186 meaning and effect of the command. In this example, no files or lines are fixed
1188 1187 until we specify the base, but then we do fix unchanged lines.
1189 1188
1190 1189 $ hg init basewhole
1191 1190 $ cd basewhole
1192 1191 $ printf "foo1\n" > foo.changed
1193 1192 $ hg commit -Aqm "first"
1194 1193 $ printf "foo2\n" >> foo.changed
1195 1194 $ printf "bar\n" > bar.changed
1196 1195 $ hg commit -Aqm "second"
1197 1196
1198 1197 $ hg fix --working-dir --whole
1199 1198 $ cat *.changed
1200 1199 bar
1201 1200 foo1
1202 1201 foo2
1203 1202
1204 1203 $ hg fix --working-dir --base 0 --whole
1205 1204 $ cat *.changed
1206 1205 BAR
1207 1206 FOO1
1208 1207 FOO2
1209 1208
1210 1209 $ cd ..
1211 1210
1212 1211 The execution order of tools can be controlled. This example doesn't work if
1213 1212 you sort after truncating, but the config defines the correct order while the
1214 1213 definitions are out of order (which might imply the incorrect order given the
1215 1214 implementation of fix). The goal is to use multiple tools to select the lowest
1216 1215 5 numbers in the file.
1217 1216
1218 1217 $ hg init priorityexample
1219 1218 $ cd priorityexample
1220 1219
1221 1220 $ cat >> .hg/hgrc <<EOF
1222 1221 > [fix]
1223 1222 > head:command = head -n 5
1224 1223 > head:pattern = numbers.txt
1225 1224 > head:priority = 1
1226 1225 > sort:command = sort -n
1227 1226 > sort:pattern = numbers.txt
1228 1227 > sort:priority = 2
1229 1228 > EOF
1230 1229
1231 1230 $ printf "8\n2\n3\n6\n7\n4\n9\n5\n1\n0\n" > numbers.txt
1232 1231 $ hg add -q
1233 1232 $ hg fix -w
1234 1233 $ cat numbers.txt
1235 1234 0
1236 1235 1
1237 1236 2
1238 1237 3
1239 1238 4
1240 1239
1241 1240 And of course we should be able to break this by reversing the execution order.
1242 1241 Test negative priorities while we're at it.
1243 1242
1244 1243 $ cat >> .hg/hgrc <<EOF
1245 1244 > [fix]
1246 1245 > head:priority = -1
1247 1246 > sort:priority = -2
1248 1247 > EOF
1249 1248 $ printf "8\n2\n3\n6\n7\n4\n9\n5\n1\n0\n" > numbers.txt
1250 1249 $ hg fix -w
1251 1250 $ cat numbers.txt
1252 1251 2
1253 1252 3
1254 1253 6
1255 1254 7
1256 1255 8
1257 1256
1258 1257 $ cd ..
1259 1258
1260 1259 It's possible for repeated applications of a fixer tool to create cycles in the
1261 1260 generated content of a file. For example, two users with different versions of
1262 1261 a code formatter might fight over the formatting when they run hg fix. In the
1263 1262 absence of other changes, this means we could produce commits with the same
1264 1263 hash in subsequent runs of hg fix. This is a problem unless we support
1265 1264 obsolescence cycles well. We avoid this by adding an extra field to the
1266 1265 successor which forces it to have a new hash. That's why this test creates
1267 1266 three revisions instead of two.
1268 1267
1269 1268 $ hg init cyclictool
1270 1269 $ cd cyclictool
1271 1270
1272 1271 $ cat >> .hg/hgrc <<EOF
1273 1272 > [fix]
1274 1273 > swapletters:command = tr ab ba
1275 1274 > swapletters:pattern = foo
1276 1275 > EOF
1277 1276
1278 1277 $ echo ab > foo
1279 1278 $ hg commit -Aqm foo
1280 1279
1281 1280 $ hg fix -r 0
1282 1281 $ hg fix -r 1
1283 1282
1284 1283 $ hg cat -r 0 foo --hidden
1285 1284 ab
1286 1285 $ hg cat -r 1 foo --hidden
1287 1286 ba
1288 1287 $ hg cat -r 2 foo
1289 1288 ab
1290 1289
1291 1290 $ cd ..
1292 1291
1293 1292 We run fixer tools in the repo root so they can look for config files or other
1294 1293 important things in the working directory. This does NOT mean we are
1295 1294 reconstructing a working copy of every revision being fixed; we're just giving
1296 1295 the tool knowledge of the repo's location in case it can do something
1297 1296 reasonable with that.
1298 1297
1299 1298 $ hg init subprocesscwd
1300 1299 $ cd subprocesscwd
1301 1300
1302 1301 $ cat >> .hg/hgrc <<EOF
1303 1302 > [fix]
1304 1303 > printcwd:command = "$PYTHON" -c "import os; print(os.getcwd())"
1305 1304 > printcwd:pattern = relpath:foo/bar
1306 1305 > filesetpwd:command = "$PYTHON" -c "import os; print('fs: ' + os.getcwd())"
1307 1306 > filesetpwd:pattern = set:**quux
1308 1307 > EOF
1309 1308
1310 1309 $ mkdir foo
1311 1310 $ printf "bar\n" > foo/bar
1312 1311 $ printf "quux\n" > quux
1313 1312 $ hg commit -Aqm blah
1314 1313
1315 1314 $ hg fix -w -r . foo/bar
1316 1315 $ hg cat -r tip foo/bar
1317 1316 $TESTTMP/subprocesscwd
1318 1317 $ cat foo/bar
1319 1318 $TESTTMP/subprocesscwd
1320 1319
1321 1320 $ cd foo
1322 1321
1323 1322 $ hg fix -w -r . bar
1324 1323 $ hg cat -r tip bar ../quux
1325 1324 $TESTTMP/subprocesscwd
1326 1325 quux
1327 1326 $ cat bar ../quux
1328 1327 $TESTTMP/subprocesscwd
1329 1328 quux
1330 1329 $ echo modified > bar
1331 1330 $ hg fix -w bar
1332 1331 $ cat bar
1333 1332 $TESTTMP/subprocesscwd
1334 1333
1335 1334 Apparently fixing p1() and its descendants doesn't include wdir() unless
1336 1335 explicitly stated.
1337 1336
1338 1337 $ hg fix -r '.::'
1339 1338 $ hg cat -r . ../quux
1340 1339 quux
1341 1340 $ hg cat -r tip ../quux
1342 1341 fs: $TESTTMP/subprocesscwd
1343 1342 $ cat ../quux
1344 1343 quux
1345 1344
1346 1345 Clean files are not fixed unless explicitly named
1347 1346 $ echo 'dirty' > ../quux
1348 1347
1349 1348 $ hg fix --working-dir
1350 1349 $ cat ../quux
1351 1350 fs: $TESTTMP/subprocesscwd
1352 1351
1353 1352 $ cd ../..
1354 1353
1355 1354 Tools configured without a pattern are ignored. It would be too dangerous to
1356 1355 run them on all files, because this might happen while testing a configuration
1357 1356 that also deletes all of the file content. There is no reasonable subset of the
1358 1357 files to use as a default. Users should be explicit about what files are
1359 1358 affected by a tool. This test also confirms that we don't crash when the
1360 1359 pattern config is missing, and that we only warn about it once.
1361 1360
1362 1361 $ hg init nopatternconfigured
1363 1362 $ cd nopatternconfigured
1364 1363
1365 1364 $ printf "foo" > foo
1366 1365 $ printf "bar" > bar
1367 1366 $ hg add -q
1368 1367 $ hg fix --debug --working-dir --config "fix.nopattern:command=echo fixed"
1369 1368 fixer tool has no pattern configuration: nopattern
1370 1369 $ cat foo bar
1371 1370 foobar (no-eol)
1372 1371 $ hg fix --debug --working-dir --config "fix.nocommand:pattern=foo.bar"
1373 1372 fixer tool has no command configuration: nocommand
1374 1373
1375 1374 $ cd ..
1376 1375
1377 1376 Tools can be disabled. Disabled tools do nothing but print a debug message.
1378 1377
1379 1378 $ hg init disabled
1380 1379 $ cd disabled
1381 1380
1382 1381 $ printf "foo\n" > foo
1383 1382 $ hg add -q
1384 1383 $ hg fix --debug --working-dir --config "fix.disabled:command=echo fixed" \
1385 1384 > --config "fix.disabled:pattern=foo" \
1386 1385 > --config "fix.disabled:enabled=false"
1387 1386 ignoring disabled fixer tool: disabled
1388 1387 $ cat foo
1389 1388 foo
1390 1389
1391 1390 $ cd ..
1392 1391
1393 1392 Test that we can configure a fixer to affect all files regardless of the cwd.
1394 1393 The way we invoke matching must not prohibit this.
1395 1394
1396 1395 $ hg init affectallfiles
1397 1396 $ cd affectallfiles
1398 1397
1399 1398 $ mkdir foo bar
1400 1399 $ printf "foo" > foo/file
1401 1400 $ printf "bar" > bar/file
1402 1401 $ printf "baz" > baz_file
1403 1402 $ hg add -q
1404 1403
1405 1404 $ cd bar
1406 1405 $ hg fix --working-dir --config "fix.cooltool:command=echo fixed" \
1407 1406 > --config "fix.cooltool:pattern=glob:**"
1408 1407 $ cd ..
1409 1408
1410 1409 $ cat foo/file
1411 1410 fixed
1412 1411 $ cat bar/file
1413 1412 fixed
1414 1413 $ cat baz_file
1415 1414 fixed
1416 1415
1417 1416 $ cd ..
1418 1417
1419 1418 Tools should be able to run on unchanged files, even if they set :linerange.
1420 1419 This includes a corner case where deleted chunks of a file are not considered
1421 1420 changes.
1422 1421
1423 1422 $ hg init skipclean
1424 1423 $ cd skipclean
1425 1424
1426 1425 $ printf "a\nb\nc\n" > foo
1427 1426 $ printf "a\nb\nc\n" > bar
1428 1427 $ printf "a\nb\nc\n" > baz
1429 1428 $ hg commit -Aqm "base"
1430 1429
1431 1430 $ printf "a\nc\n" > foo
1432 1431 $ printf "a\nx\nc\n" > baz
1433 1432
1434 1433 $ cat >> print.py <<EOF
1435 1434 > import sys
1436 1435 > for a in sys.argv[1:]:
1437 1436 > print(a)
1438 1437 > EOF
1439 1438
1440 1439 $ hg fix --working-dir foo bar baz \
1441 1440 > --config "fix.changedlines:command=\"$PYTHON\" print.py \"Line ranges:\"" \
1442 1441 > --config 'fix.changedlines:linerange="{first} through {last}"' \
1443 1442 > --config 'fix.changedlines:pattern=glob:**' \
1444 1443 > --config 'fix.changedlines:skipclean=false'
1445 1444
1446 1445 $ cat foo
1447 1446 Line ranges:
1448 1447 $ cat bar
1449 1448 Line ranges:
1450 1449 $ cat baz
1451 1450 Line ranges:
1452 1451 2 through 2
1453 1452
1454 1453 $ cd ..
1455 1454
1456 1455 Test various cases around merges. We were previously dropping files if they were
1457 1456 created on only the p2 side of the merge, so let's test permutations of:
1458 1457 * added, was fixed
1459 1458 * added, considered for fixing but was already good
1460 1459 * added, not considered for fixing
1461 1460 * modified, was fixed
1462 1461 * modified, considered for fixing but was already good
1463 1462 * modified, not considered for fixing
1464 1463
1465 1464 Before the bug was fixed where we would drop files, this test demonstrated the
1466 1465 following issues:
1467 1466 * new_in_r1.ignored, new_in_r1_already_good.changed, and
1468 1467 > mod_in_r1_already_good.changed were NOT in the manifest for the merge commit
1469 1468 * mod_in_r1.ignored had its contents from r0, NOT r1.
1470 1469
1471 1470 We're also setting a named branch for every commit to demonstrate that the
1472 1471 branch is kept intact and there aren't issues updating to another branch in the
1473 1472 middle of fix.
1474 1473
1475 1474 $ hg init merge_keeps_files
1476 1475 $ cd merge_keeps_files
1477 1476 $ for f in r0 mod_in_r1 mod_in_r2 mod_in_merge mod_in_child; do
1478 1477 > for c in changed whole ignored; do
1479 1478 > printf "hello\n" > $f.$c
1480 1479 > done
1481 1480 > printf "HELLO\n" > "mod_in_${f}_already_good.changed"
1482 1481 > done
1483 1482 $ hg branch -q r0
1484 1483 $ hg ci -Aqm 'r0'
1485 1484 $ hg phase -p
1486 1485 $ make_test_files() {
1487 1486 > printf "world\n" >> "mod_in_$1.changed"
1488 1487 > printf "world\n" >> "mod_in_$1.whole"
1489 1488 > printf "world\n" >> "mod_in_$1.ignored"
1490 1489 > printf "WORLD\n" >> "mod_in_$1_already_good.changed"
1491 1490 > printf "new in $1\n" > "new_in_$1.changed"
1492 1491 > printf "new in $1\n" > "new_in_$1.whole"
1493 1492 > printf "new in $1\n" > "new_in_$1.ignored"
1494 1493 > printf "ALREADY GOOD, NEW IN THIS REV\n" > "new_in_$1_already_good.changed"
1495 1494 > }
1496 1495 $ make_test_commit() {
1497 1496 > make_test_files "$1"
1498 1497 > hg branch -q "$1"
1499 1498 > hg ci -Aqm "$2"
1500 1499 > }
1501 1500 $ make_test_commit r1 "merge me, pt1"
1502 1501 $ hg co -q ".^"
1503 1502 $ make_test_commit r2 "merge me, pt2"
1504 1503 $ hg merge -qr 1
1505 1504 $ make_test_commit merge "evil merge"
1506 1505 $ make_test_commit child "child of merge"
1507 1506 $ make_test_files wdir
1508 1507 $ hg fix -r 'not public()' -w
1509 1508 $ hg log -G -T'{rev}:{shortest(node,8)}: branch:{branch} desc:{desc}'
1510 1509 @ 8:c22ce900: branch:child desc:child of merge
1511 1510 |
1512 1511 o 7:5a30615a: branch:merge desc:evil merge
1513 1512 |\
1514 1513 | o 6:4e5acdc4: branch:r2 desc:merge me, pt2
1515 1514 | |
1516 1515 o | 5:eea01878: branch:r1 desc:merge me, pt1
1517 1516 |/
1518 1517 o 0:0c548d87: branch:r0 desc:r0
1519 1518
1520 1519 $ hg files -r tip
1521 1520 mod_in_child.changed
1522 1521 mod_in_child.ignored
1523 1522 mod_in_child.whole
1524 1523 mod_in_child_already_good.changed
1525 1524 mod_in_merge.changed
1526 1525 mod_in_merge.ignored
1527 1526 mod_in_merge.whole
1528 1527 mod_in_merge_already_good.changed
1529 1528 mod_in_mod_in_child_already_good.changed
1530 1529 mod_in_mod_in_merge_already_good.changed
1531 1530 mod_in_mod_in_r1_already_good.changed
1532 1531 mod_in_mod_in_r2_already_good.changed
1533 1532 mod_in_r0_already_good.changed
1534 1533 mod_in_r1.changed
1535 1534 mod_in_r1.ignored
1536 1535 mod_in_r1.whole
1537 1536 mod_in_r1_already_good.changed
1538 1537 mod_in_r2.changed
1539 1538 mod_in_r2.ignored
1540 1539 mod_in_r2.whole
1541 1540 mod_in_r2_already_good.changed
1542 1541 new_in_child.changed
1543 1542 new_in_child.ignored
1544 1543 new_in_child.whole
1545 1544 new_in_child_already_good.changed
1546 1545 new_in_merge.changed
1547 1546 new_in_merge.ignored
1548 1547 new_in_merge.whole
1549 1548 new_in_merge_already_good.changed
1550 1549 new_in_r1.changed
1551 1550 new_in_r1.ignored
1552 1551 new_in_r1.whole
1553 1552 new_in_r1_already_good.changed
1554 1553 new_in_r2.changed
1555 1554 new_in_r2.ignored
1556 1555 new_in_r2.whole
1557 1556 new_in_r2_already_good.changed
1558 1557 r0.changed
1559 1558 r0.ignored
1560 1559 r0.whole
1561 1560 $ for f in "$(hg files -r tip)"; do hg cat -r tip $f -T'{path}:\n{data}\n'; done
1562 1561 mod_in_child.changed:
1563 1562 hello
1564 1563 WORLD
1565 1564
1566 1565 mod_in_child.ignored:
1567 1566 hello
1568 1567 world
1569 1568
1570 1569 mod_in_child.whole:
1571 1570 HELLO
1572 1571 WORLD
1573 1572
1574 1573 mod_in_child_already_good.changed:
1575 1574 WORLD
1576 1575
1577 1576 mod_in_merge.changed:
1578 1577 hello
1579 1578 WORLD
1580 1579
1581 1580 mod_in_merge.ignored:
1582 1581 hello
1583 1582 world
1584 1583
1585 1584 mod_in_merge.whole:
1586 1585 HELLO
1587 1586 WORLD
1588 1587
1589 1588 mod_in_merge_already_good.changed:
1590 1589 WORLD
1591 1590
1592 1591 mod_in_mod_in_child_already_good.changed:
1593 1592 HELLO
1594 1593
1595 1594 mod_in_mod_in_merge_already_good.changed:
1596 1595 HELLO
1597 1596
1598 1597 mod_in_mod_in_r1_already_good.changed:
1599 1598 HELLO
1600 1599
1601 1600 mod_in_mod_in_r2_already_good.changed:
1602 1601 HELLO
1603 1602
1604 1603 mod_in_r0_already_good.changed:
1605 1604 HELLO
1606 1605
1607 1606 mod_in_r1.changed:
1608 1607 hello
1609 1608 WORLD
1610 1609
1611 1610 mod_in_r1.ignored:
1612 1611 hello
1613 1612 world
1614 1613
1615 1614 mod_in_r1.whole:
1616 1615 HELLO
1617 1616 WORLD
1618 1617
1619 1618 mod_in_r1_already_good.changed:
1620 1619 WORLD
1621 1620
1622 1621 mod_in_r2.changed:
1623 1622 hello
1624 1623 WORLD
1625 1624
1626 1625 mod_in_r2.ignored:
1627 1626 hello
1628 1627 world
1629 1628
1630 1629 mod_in_r2.whole:
1631 1630 HELLO
1632 1631 WORLD
1633 1632
1634 1633 mod_in_r2_already_good.changed:
1635 1634 WORLD
1636 1635
1637 1636 new_in_child.changed:
1638 1637 NEW IN CHILD
1639 1638
1640 1639 new_in_child.ignored:
1641 1640 new in child
1642 1641
1643 1642 new_in_child.whole:
1644 1643 NEW IN CHILD
1645 1644
1646 1645 new_in_child_already_good.changed:
1647 1646 ALREADY GOOD, NEW IN THIS REV
1648 1647
1649 1648 new_in_merge.changed:
1650 1649 NEW IN MERGE
1651 1650
1652 1651 new_in_merge.ignored:
1653 1652 new in merge
1654 1653
1655 1654 new_in_merge.whole:
1656 1655 NEW IN MERGE
1657 1656
1658 1657 new_in_merge_already_good.changed:
1659 1658 ALREADY GOOD, NEW IN THIS REV
1660 1659
1661 1660 new_in_r1.changed:
1662 1661 NEW IN R1
1663 1662
1664 1663 new_in_r1.ignored:
1665 1664 new in r1
1666 1665
1667 1666 new_in_r1.whole:
1668 1667 NEW IN R1
1669 1668
1670 1669 new_in_r1_already_good.changed:
1671 1670 ALREADY GOOD, NEW IN THIS REV
1672 1671
1673 1672 new_in_r2.changed:
1674 1673 NEW IN R2
1675 1674
1676 1675 new_in_r2.ignored:
1677 1676 new in r2
1678 1677
1679 1678 new_in_r2.whole:
1680 1679 NEW IN R2
1681 1680
1682 1681 new_in_r2_already_good.changed:
1683 1682 ALREADY GOOD, NEW IN THIS REV
1684 1683
1685 1684 r0.changed:
1686 1685 hello
1687 1686
1688 1687 r0.ignored:
1689 1688 hello
1690 1689
1691 1690 r0.whole:
1692 1691 hello
1693 1692
General Comments 0
You need to be logged in to leave comments. Login now