128 clang-format:linerange=--lines={first}:{last} |
128 clang-format:linerange=--lines={first}:{last} |
129 clang-format:fileset=set:**.cpp or **.hpp |
129 clang-format:fileset=set:**.cpp or **.hpp |
130 |
130 |
131 The :command suboption forms the first part of the shell command that will be |
131 The :command suboption forms the first part of the shell command that will be |
132 used to fix a file. The content of the file is passed on standard input, and |
132 used to fix a file. The content of the file is passed on standard input, and |
133 the fixed file content is expected on standard output. If there is any output |
133 the fixed file content is expected on standard output. Any output on standard |
134 on standard error, the file will not be affected. Some values may be |
134 error will be displayed as a warning. If the exit status is not zero, the file |
135 substituted into the command: |
135 will not be affected. A placeholder warning is displayed if there is a non- |
|
136 zero exit status but no standard error output. Some values may be substituted |
|
137 into the command: |
136 |
138 |
137 {rootpath} The path of the file being fixed, relative to the repo root |
139 {rootpath} The path of the file being fixed, relative to the repo root |
138 {basename} The name of the file being fixed, without the directory path |
140 {basename} The name of the file being fixed, without the directory path |
139 |
141 |
140 If the :linerange suboption is set, the tool will only be run if there are |
142 If the :linerange suboption is set, the tool will only be run if there are |
506 error messages to the user, and we still let the fixer affect the file it was |
516 error messages to the user, and we still let the fixer affect the file it was |
507 fixing if its exit code is zero. Some code formatters might emit error messages |
517 fixing if its exit code is zero. Some code formatters might emit error messages |
508 on stderr and nothing on stdout, which would cause us the clear the file, |
518 on stderr and nothing on stdout, which would cause us the clear the file, |
509 except that they also exit with a non-zero code. We show the user which fixer |
519 except that they also exit with a non-zero code. We show the user which fixer |
510 emitted the stderr, and which revision, but we assume that the fixer will print |
520 emitted the stderr, and which revision, but we assume that the fixer will print |
511 the filename if it is relevant (since the issue may be non-specific). |
521 the filename if it is relevant (since the issue may be non-specific). There is |
|
522 also a config to abort (without affecting any files whatsoever) if we see any |
|
523 tool with a non-zero exit status. |
512 |
524 |
513 $ hg init showstderr |
525 $ hg init showstderr |
514 $ cd showstderr |
526 $ cd showstderr |
515 |
527 |
516 $ printf "hello\n" > hello.txt |
528 $ printf "hello\n" > hello.txt |
517 $ hg add |
529 $ hg add |
518 adding hello.txt |
530 adding hello.txt |
519 $ cat > $TESTTMP/fail.sh <<'EOF' |
531 $ cat > $TESTTMP/work.sh <<'EOF' |
520 > printf 'HELLO\n' |
532 > printf 'HELLO\n' |
521 > printf "$@: some\nerror" >&2 |
533 > printf "$@: some\nerror that didn't stop the tool" >&2 |
522 > exit 0 # success despite the stderr output |
534 > exit 0 # success despite the stderr output |
523 > EOF |
535 > EOF |
|
536 $ hg --config "fix.work:command=sh $TESTTMP/work.sh {rootpath}" \ |
|
537 > --config "fix.work:fileset=hello.txt" \ |
|
538 > fix --working-dir |
|
539 [wdir] work: hello.txt: some |
|
540 [wdir] work: error that didn't stop the tool |
|
541 $ cat hello.txt |
|
542 HELLO |
|
543 |
|
544 $ printf "goodbye\n" > hello.txt |
|
545 $ printf "foo\n" > foo.whole |
|
546 $ hg add |
|
547 adding foo.whole |
|
548 $ cat > $TESTTMP/fail.sh <<'EOF' |
|
549 > printf 'GOODBYE\n' |
|
550 > printf "$@: some\nerror that did stop the tool\n" >&2 |
|
551 > exit 42 # success despite the stdout output |
|
552 > EOF |
|
553 $ hg --config "fix.fail:command=sh $TESTTMP/fail.sh {rootpath}" \ |
|
554 > --config "fix.fail:fileset=hello.txt" \ |
|
555 > --config "fix.failure=abort" \ |
|
556 > fix --working-dir |
|
557 [wdir] fail: hello.txt: some |
|
558 [wdir] fail: error that did stop the tool |
|
559 abort: no fixes will be applied |
|
560 (use --config fix.failure=continue to apply any successful fixes anyway) |
|
561 [255] |
|
562 $ cat hello.txt |
|
563 goodbye |
|
564 $ cat foo.whole |
|
565 foo |
|
566 |
524 $ hg --config "fix.fail:command=sh $TESTTMP/fail.sh {rootpath}" \ |
567 $ hg --config "fix.fail:command=sh $TESTTMP/fail.sh {rootpath}" \ |
525 > --config "fix.fail:fileset=hello.txt" \ |
568 > --config "fix.fail:fileset=hello.txt" \ |
526 > fix --working-dir |
569 > fix --working-dir |
527 [wdir] fail: hello.txt: some |
570 [wdir] fail: hello.txt: some |
528 [wdir] fail: error |
571 [wdir] fail: error that did stop the tool |
529 $ cat hello.txt |
|
530 HELLO |
|
531 |
|
532 $ printf "goodbye\n" > hello.txt |
|
533 $ cat > $TESTTMP/work.sh <<'EOF' |
|
534 > printf 'GOODBYE\n' |
|
535 > printf "$@: some\nerror\n" >&2 |
|
536 > exit 42 # success despite the stdout output |
|
537 > EOF |
|
538 $ hg --config "fix.fail:command=sh $TESTTMP/work.sh {rootpath}" \ |
|
539 > --config "fix.fail:fileset=hello.txt" \ |
|
540 > fix --working-dir |
|
541 [wdir] fail: hello.txt: some |
|
542 [wdir] fail: error |
|
543 $ cat hello.txt |
572 $ cat hello.txt |
544 goodbye |
573 goodbye |
|
574 $ cat foo.whole |
|
575 FOO |
545 |
576 |
546 $ hg --config "fix.fail:command=exit 42" \ |
577 $ hg --config "fix.fail:command=exit 42" \ |
547 > --config "fix.fail:fileset=hello.txt" \ |
578 > --config "fix.fail:fileset=hello.txt" \ |
548 > fix --working-dir |
579 > fix --working-dir |
549 [wdir] fail: exited with status 42 |
580 [wdir] fail: exited with status 42 |