NAME

Code::TidyAll::Git::Precommit - Git precommit hook that requires files to be tidyall'd

VERSION

version 0.06

SYNOPSIS

In .git/hooks/pre-commit:

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

DESCRIPTION

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

Files are not modified by this hook. If you want to actually tidy files before commit,

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.

% git commit -m "fixups" CHI.pm CHI/Driver.pm 
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 passing --no-verify to commit:

% git commit --no-verify ...

or you can just move .git/hooks/pre-commit out of the way temporarily.

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

The hook will stash any changes not in the index beforehand, and restore them afterwards, via

git stash -q --keep-index
....
git stash pop -q

This means that if tidyall.ini has uncommitted changes that are not in the index, they will not affect the tidyall run.

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

Key/value parameters:

no_stash

Don't attempt to stash changes not in the index. This means the hook will process even files that are not going to be committed.

tidyall_class

Subclass to use instead of Code::TidyAll

tidyall_options

Hashref of options to pass to the Code::TidyAll constructor

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.