The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Code::TidyAll::Git::Prereceive - Git pre-receive hook that requires files to be tidyall'd

VERSION

version 0.11

SYNOPSIS

  In .git/hooks/pre-receive:

    #!/usr/bin/perl
    use Code::TidyAll::Git::Prereceive;
    use strict;
    use warnings;
    
    Code::TidyAll::Git::Prereceive->check();

DESCRIPTION

This module implements a Git pre-receive hook that checks if all pushed files are tidied and valid according to tidyall, and rejects the push if not.

This is typically used to validate pushes from multiple developers to a shared repo, possibly on a remote server.

See also Code::TidyAll::Git::Precommit, which operates locally.

METHODS

check (key/value params...)

Class method. Check that all files being added or modified in this push are tidied and valid according to tidyall. If not, then the entire push is rejected and the reason(s) are output to the client. e.g.

    % git push
    Counting objects: 9, done.
    ...
    remote: [checked] lib/CHI/Util.pm        
    remote: Code before strictures are enabled on line 13 [TestingAndDebugging::RequireUseStrict]        
    remote: 
    remote: 1 file did not pass tidyall check        
    To ...
     ! [remote rejected] master -> master (pre-receive hook declined)

The configuration file tidyall.ini must be checked into git in the repo root directory, i.e. next to the .git directory.

Unfortunately there is no easy way to bypass the pre-receive hook in an emergency. It must be disabled in the repo being pushed to, e.g. by renaming .git/hooks/pre-receive.

Passes mode = "commit" by default; see modes.

Key/value parameters:

conf_file

Name of conf file; default is "tidyall.ini".

extra_conf_files

A listref of configuration files referred to from tidyall.ini, e.g.

    extra_conf_files => ['perlcriticrc', 'perltidyrc']

These files will be pulled out of the repo along with tidyall.ini. If you don't list them here then you'll get errors like 'cannot find perlcriticrc' when the hook runs.

git_path

Path to git to use in commands, e.g. '/usr/bin/git' or '/usr/local/bin/git'. By default, just uses 'git', which will search the user's PATH.

tidyall_class

Subclass to use instead of Code::TidyAll

tidyall_options

Hashref of options to pass to the Code::TidyAll constructor. You can use this to override the default options

    mode  => 'commit',
    quiet => 1,

or pass additional options.

SEE ALSO

Code::TidyAll

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.