Mercurial > hgbook
comparison en/ch09-hook.xml @ 821:88828b784971
Add more complex example hook
author | Bryan O'Sullivan <bos@serpentine.com> |
---|---|
date | Tue, 28 Apr 2009 23:10:43 -0700 |
parents | ef53d025f410 |
children | 477d6a3e5023 |
comparison
equal
deleted
inserted
replaced
820:3edacbff2b43 | 821:88828b784971 |
---|---|
554 transaction will roll back; you'll have to re-enter the commit | 554 transaction will roll back; you'll have to re-enter the commit |
555 message after you fix the trailing whitespace and run <command | 555 message after you fix the trailing whitespace and run <command |
556 role="hg-cmd">hg commit</command> again. | 556 role="hg-cmd">hg commit</command> again. |
557 </para> | 557 </para> |
558 | 558 |
559 &interaction.hook.ws.simple; | 559 &interaction.ch09-hook.ws.simple; |
560 | 560 |
561 <para id="x_235">In this example, we introduce a simple <literal | 561 <para id="x_235">In this example, we introduce a simple <literal |
562 role="hook">pretxncommit</literal> hook that checks for | 562 role="hook">pretxncommit</literal> hook that checks for |
563 trailing whitespace. This hook is short, but not very | 563 trailing whitespace. This hook is short, but not very |
564 helpful. It exits with an error status if a change adds a | 564 helpful. It exits with an error status if a change adds a |
566 any information that might help us to identify the offending | 566 any information that might help us to identify the offending |
567 file or line. It also has the nice property of not paying | 567 file or line. It also has the nice property of not paying |
568 attention to unmodified lines; only lines that introduce new | 568 attention to unmodified lines; only lines that introduce new |
569 trailing whitespace cause problems. | 569 trailing whitespace cause problems. |
570 </para> | 570 </para> |
571 | |
572 &ch09-check_whitespace.py.lst; | |
571 | 573 |
572 <para id="x_236">The above version is much more complex, but also more | 574 <para id="x_236">The above version is much more complex, but also more |
573 useful. It parses a unified diff to see if any lines add | 575 useful. It parses a unified diff to see if any lines add |
574 trailing whitespace, and prints the name of the file and the | 576 trailing whitespace, and prints the name of the file and the |
575 line number of each such occurrence. Even better, if the | 577 line number of each such occurrence. Even better, if the |
579 use the <option role="hg-opt-commit">-l filename</option> | 581 use the <option role="hg-opt-commit">-l filename</option> |
580 option to <command role="hg-cmd">hg commit</command> to reuse | 582 option to <command role="hg-cmd">hg commit</command> to reuse |
581 the saved commit message once you've corrected the problem. | 583 the saved commit message once you've corrected the problem. |
582 </para> | 584 </para> |
583 | 585 |
584 &interaction.hook.ws.better; | 586 &interaction.ch09-hook.ws.better; |
585 | 587 |
586 <para id="x_237">As a final aside, note in the example above the use of | 588 <para id="x_237">As a final aside, note in the example above the use of |
587 <command>perl</command>'s in-place editing feature to get rid | 589 <command>perl</command>'s in-place editing feature to get rid |
588 of trailing whitespace from a file. This is concise and | 590 of trailing whitespace from a file. This is concise and |
589 useful enough that I will reproduce it here. | 591 useful enough that I will reproduce it here. |