- USING AND (NOT) ENFORCING THIS HOOK
- COPYRIGHT AND LICENSE
Code::TidyAll::Git::Precommit - Git pre-commit hook that requires files to be tidyall'd
In .git/hooks/pre-commit: #!/usr/bin/env perl use strict; use warnings; use Code::TidyAll::Git::Precommit; Code::TidyAll::Git::Precommit->check();
See also Code::TidyAll::Git::Prereceive, which validates pushes to a shared repo.
- 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-commitout of the way temporarily.
The configuration file (
.tidyallrc) 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 the configuration file has uncommitted changes that are not in the index, they will not affect the tidyall run.
Passes mode = "commit" by default; see modes.
Conf file name to search for instead of the defaults.
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.
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.
Subclass to use instead of Code::TidyAll
Hashref of options to pass to the Code::TidyAll constructor
USING AND (NOT) ENFORCING THIS HOOK
This hook must be placed manually in each copy of the repo - there is no way to automatically distribute or enforce it. However, you can make things easier on yourself or your developers as follows:
Create a directory called
git/hooksat the top of your repo (note no dot prefix).
mkdir -p git/hooks
Commit your pre-commit script in
#!/usr/bin/env perl use strict; use warnings; use Code::TidyAll::Git::Precommit; Code::TidyAll::Git::Precommit->check();
Add a setup script in
#!/bin/bash chmod +x git/hooks/pre-commit cd .git/hooks ln -s ../../git/hooks/pre-commit
git/setup.sh(or tell your developers to run it) once for each new clone of the repo
More information on pre-commit hooks and the impossibility of enforcing them here.
See also Code::TidyAll::Git::Prereceive, which enforces tidyall on pushes to a remote shared repository.
Bugs may be submitted through https://github.com/houseabsolute/perl-code-tidyall/issues.
I am also usually active on IRC as 'drolsky' on
Jonathan Swartz <firstname.lastname@example.org>
Dave Rolsky <email@example.com>
COPYRIGHT AND LICENSE
This software is copyright (c) 2011 - 2016 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.