In hooks/pre-commit in your svn repo: #!/usr/bin/perl use Code::TidyAll::SVN::Precommit; use Log::Any::Adapter (File => "/path/to/hooks/logs/tidyall.log"); use strict; use warnings; Code::TidyAll::SVN::Precommit->check();
- check (key/value params...)
Class method. Check that all files being added or modified in this commit are tidied and valid according to tidyall. If not, then the entire commit is rejected and the reason(s) are output to the client. e.g.
% svn commit -m "fixups" CHI.pm CHI/Driver.pm Sending CHI/Driver.pm Sending CHI.pm Transmitting file data ..svn: Commit failed (details follow): svn: Commit blocked by pre-commit hook (exit code 255) with output: 2 files did not pass tidyall check lib/CHI.pm: *** 'PerlTidy': needs tidying lib/CHI/Driver.pm: *** 'PerlCritic': Code before strictures are enabled at /tmp/Code-TidyAll-0e6K/Driver.pm line 2 [TestingAndDebugging::RequireUseStrict]
In an emergency the hook can be bypassed by prefixing the comment with "NO TIDYALL", e.g.
% svn commit -m "NO TIDYALL - this is an emergency!" CHI.pm CHI/Driver.pm Sending CHI/Driver.pm Sending CHI.pm Transmitting file data . Committed revision 7562.
The configuration file (
.tidyallrc) must be checked into svn. For each file, the hook will look upwards from the file's repo location and use the first configuration file it finds.
By default, if the configuration file cannot be found, or if a runtime error occurs, a warning is logged (see "LOGGING" below) but the commit is allowed to proceed. This is so that unexpected problems do not prevent valid commits.
Passes mode = "commit" by default; see modes.
Conf file name to search for instead of the defaults.
Commit prefix that will cause this hook to be bypassed. Defaults to "NO TIDYALL". e.g.
svn commit -m "NO TIDYALL - must get fix to production!"
Set to a false value (e.g. blank or undefined) to disable bypassing.
A listref of other configuration files referred to from the main configuration file, e.g.
extra_conf_files => ['perlcriticrc', 'perltidyrc']
If you don't list them here then you'll get errors like 'cannot find perlcriticrc' when the hook runs.
If the configuration file cannot be found for some/all the files, or if a runtime error occurs, reject the commit.
Repository path being committed; defaults to
Subclass to use instead of Code::TidyAll
Hashref of options to pass to the Code::TidyAll constructor
Commit transaction; defaults to
This module uses Log::Any to log its activity, including all files that were checked, an inability to find the configuration file, and any runtime errors that occur. You can create a simple date-stamped log file with
use Log::Any::Adapter (File => "/path/to/hooks/logs/tidyall.log");
or do something fancier with one of the other Log::Any adapters.
Having a log file is especially useful with pre-commit hooks since there is no way for the hook to send back output on a successful commit.
Thanks to Alexander Simakov, author of perlcritic-checker, for some of the ideas here such as emergency_comment_prefix.
Jonathan Swartz <firstname.lastname@example.org>
Dave Rolsky <email@example.com>
COPYRIGHT AND LICENSE
This software is copyright (c) 2011 - 2015 by Jonathan Swartz.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.