Take me over?
NAME
Code::TidyAll::SVN::Precommit - Subversion precommit hook that requires files to be tidyall'd
VERSION
version 0.03
SYNOPSIS
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 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]
The configuration file (
tidyall.ini
by default) 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
tidyall.ini
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 a team from committing code.Passes mode = "commit" by default; see modes.
Key/value parameters:
- conf_file
-
Name of configuration file, defaults to
tidyall.ini
- extra_conf_files
-
A listref of configuration files referred to from
tidyall.ini
, e.g.extra_conf_files => ['perlcriticrc', 'perltidyrc']
- reject_on_error
-
If
tidyall.ini
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
-
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 tidyall.ini
, and any runtime errors that occur. You can create a simple datestamped 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 precommit hooks since there is no way for the hook to send back output on a successful commit.
SEE ALSO
AUTHOR
Jonathan Swartz <swartz@pobox.com>
COPYRIGHT AND LICENSE
This software is copyright (c) 2011 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.