.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Code::TidyAll::Git::Precommit 3pm" .TH Code::TidyAll::Git::Precommit 3pm "2022-12-31" "perl v5.36.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Code::TidyAll::Git::Precommit \- Git pre\-commit hook that requires files to be tidyall'd .SH "VERSION" .IX Header "VERSION" version 0.83 .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& In .git/hooks/pre\-commit: \& \& #!/usr/bin/env perl \& use strict; \& use warnings; \& \& use Code::TidyAll::Git::Precommit; \& Code::TidyAll::Git::Precommit\->check(); .Ve .SH "DESCRIPTION" .IX Header "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/commits are never modified by this hook. .PP See also Code::TidyAll::Git::Prereceive, which validates pushes to a shared repo. .PP The tidyall configuration file (\fItidyall.ini\fR or \fI.tidyallrc\fR) must be checked into git in the repo root directory i.e. next to the .git directory. .PP By default, the hook will stash any changes not in the index beforehand, and restore them afterwards, via .PP .Vb 3 \& git stash save \-\-keep\-index \-\-include\-untracked \& .... \& git stash pop .Ve .PP This means that if the configuration file has uncommitted changes that are not in the index, they will not affect the tidyall run. .SH "METHODS" .IX Header "METHODS" This class provides one method: .SS "Code::TidyAll::Git::Precommit\->check(%params)" .IX Subsection "Code::TidyAll::Git::Precommit->check(%params)" Checks 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. .PP .Vb 6 \& % git commit \-m "fixups" CHI.pm CHI/Driver.pm \& 2 files did not pass tidyall check \& lib/CHI.pm: *** \*(AqPerlTidy\*(Aq: needs tidying \& lib/CHI/Driver.pm: *** \*(AqPerlCritic\*(Aq: Code before strictures are enabled \& at /tmp/Code\-TidyAll\-0e6K/Driver.pm line 2 \& [TestingAndDebugging::RequireUseStrict] .Ve .PP In an emergency the hook can be bypassed by passing \-\-no\-verify to commit: .PP .Vb 1 \& % git commit \-\-no\-verify ... .Ve .PP or you can just move \fI.git/hooks/pre\-commit\fR out of the way temporarily. .PP This class passes mode = \*(L"commit\*(R" by default to tidyall; see modes. .PP Key/value parameters: .IP "\(bu" 4 conf_name .Sp A conf file name to search for instead of the defaults. .IP "\(bu" 4 git_path .Sp Path to git to use in commands, e.g. '/usr/bin/git' or '/usr/local/bin/git'. By default, it just uses 'git', which will search the user's \f(CW\*(C`PATH\*(C'\fR. .IP "\(bu" 4 no_stash .Sp Don't attempt to stash changes not in the index. This means the hook will process files that are not going to be committed. .IP "\(bu" 4 tidyall_class .Sp Subclass to use instead of Code::TidyAll. .IP "\(bu" 4 tidyall_options .Sp A hashref of options to pass to the Code::TidyAll constructor. .SH "USING AND (NOT) ENFORCING THIS HOOK" .IX Header "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: .IP "\(bu" 4 Create a directory called \fIgit/hooks\fR at the top of your repo (note no dot prefix). .Sp .Vb 1 \& mkdir \-p git/hooks .Ve .IP "\(bu" 4 Commit your pre-commit script in \fIgit/hooks/pre\-commit\fR containing: .Sp .Vb 1 \& #!/usr/bin/env perl \& \& use strict; \& use warnings; \& \& use Code::TidyAll::Git::Precommit; \& Code::TidyAll::Git::Precommit\->check(); .Ve .IP "\(bu" 4 Add a setup script in \fIgit/setup.sh\fR containing .Sp .Vb 4 \& #!/bin/bash \& chmod +x git/hooks/pre\-commit \& cd .git/hooks \& ln \-s ../../git/hooks/pre\-commit .Ve .IP "\(bu" 4 Run \f(CW\*(C`git/setup.sh\*(C'\fR (or tell your developers to run it) once for each new clone of the repo .PP See this Stack Overflow question for more information on pre-commit hooks and the impossibility of enforcing their use. .PP See also Code::TidyAll::Git::Prereceive, which enforces tidyall on pushes to a remote shared repository. .SH "SUPPORT" .IX Header "SUPPORT" Bugs may be submitted at . .SH "SOURCE" .IX Header "SOURCE" The source code repository for Code-TidyAll can be found at . .SH "AUTHORS" .IX Header "AUTHORS" .IP "\(bu" 4 Jonathan Swartz .IP "\(bu" 4 Dave Rolsky .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" This software is copyright (c) 2011 \- 2022 by Jonathan Swartz. .PP This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. .PP The full text of the license can be found in the \&\fI\s-1LICENSE\s0\fR file included with this distribution.