Git::Hooks::CheckFile - Git::Hooks plugin for checking files
version 1.11.1
This Git::Hooks plugin hooks itself to the hooks below to check if the contents of files added to or modified in the repository meet specified constraints. If they don't, the commit/push is aborted.
pre-commit
update
pre-receive
ref-update
patchset-created
draft-published
To enable it you should add it to the githooks.plugin configuration option:
git config --add githooks.plugin CheckFile
CheckFile - Git::Hooks plugin for checking files
The plugin is configured by the following git options.
This directive tells which COMMAND should be used to check files matching PATTERN.
Only the file's basename is matched against PATTERN.
PATTERN is usually expressed with globbing to match files based on their extensions, for example:
git config githooks.checkfile.name *.pl perlcritic --stern
If you need more power than globs can provide you can match using regular expressions, using the qr// operator, for example:
qr//
git config githooks.checkfile.name qr/xpto-\\d+.pl/ perlcritic --stern
COMMAND is everything that comes after the PATTERN. It is invoked once for each file matching PATTERN with the name of a temporary file containing the contents of the matching file passed to it as a last argument. If the command exits with any code different than 0 it is considered a violation and the hook complains, rejecting the commit or the push.
If the filename can't be the last argument to COMMAND you must tell where in the command-line it should go using the placeholder {} (like the argument to the find command's -exec option). For example:
{}
find
-exec
git config githooks.checkfile.name *.xpto cmd1 --file {} | cmd2
COMMAND is invoked as a single string passed to system, which means it can use shell operators such as pipes and redirections.
system
Some real examples:
git config --add githooks.checkfile.name *.p[lm] perlcritic --stern --verbose 5 git config --add githooks.checkfile.name *.pp puppet parser validate --verbose --debug git config --add githooks.checkfile.name *.pp puppet-lint --no-variable_scope-check git config --add githooks.checkfile.name *.sh bash -n git config --add githooks.checkfile.name *.sh shellcheck --exclude=SC2046,SC2053,SC2086 git config --add githooks.checkfile.name *.erb erb -P -x -T - {} | ruby -c
This directive specifies a size limit (in bytes) for any file in the repository. If set explicitly to 0 (zero), no limit is imposed, which is the same as not specifying it. But it can be useful to override a global specification in a particular repository.
This directive denies files which basenames match REGEXP.
This directive allows files which basenames match REGEXP. Since by default all basenames are allowed this directive is useful only to prevent a githooks.checkfile.basename.deny directive to deny the same basename.
The basename checks are evaluated so that a file is denied only if it's basename matches any basename.deny directive and none of the basename.allow directives. So, for instance, you would apply it like this to allow the versioning of .gitignore file while denying any other file with a name beginning with a dot.
[githooks "checkfile"] basename.allow ^\\.gitignore basename.deny ^\\.
This directive denies files which full paths match REGEXP.
This directive allows files which full paths match REGEXP. It's useful in the same way that githooks.checkfile.basename.deny is.
Gustavo L. de M. Chaves <gnustavo@cpan.org>
This software is copyright (c) 2015 by CPqD <www.cpqd.com.br>.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Git::Hooks, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Git::Hooks
CPAN shell
perl -MCPAN -e shell install Git::Hooks
For more information on module installation, please visit the detailed CPAN module installation guide.