VERSION
version 0.32SYNOPSIS
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();
DESCRIPTION
This module implements a Subversion pre-commit hook <http://svnbook.red-bean.com/en/1.7/svn.ref.reposhooks.pre-commit.html> that checks if all files are tidied and valid according to tidyall, and rejects the commit if not.METHODS
- 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 ("tidyall.ini" or ".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.
Key/value parameters:
-
- conf_name
- Conf file name to search for instead of the defaults.
- emergency_comment_prefix
-
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.
- extra_conf_files
-
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.
- reject_on_error
- If the configuration file cannot be found for some/all the files, or if a runtime error occurs, reject the commit.
- repos
- Repository path being committed; defaults to $ARGV[0]
- tidyall_class
- Subclass to use instead of Code::TidyAll
- tidyall_options
- Hashref of options to pass to the Code::TidyAll constructor
- txn
- Commit transaction; defaults to $ARGV[1]
-
LOGGING
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.
ACKNOWLEDGMENTS
Thanks to Alexander Simakov, author of perlcritic-checker <http://search.cpan.org/~xdr/perlcritic-checker-1.2.6/>, for some of the ideas here such as emergency_comment_prefix.AUTHORS
- Jonathan Swartz <[email protected]>
- Dave Rolsky <[email protected]>
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.