1Code::TidyAll::Git::PreUcsoemrmiCto(n3t)ributed Perl DocCuomdeen:t:aTtiidoynAll::Git::Precommit(3)
2
3
4

NAME

6       Code::TidyAll::Git::Precommit - Git pre-commit hook that requires files
7       to be tidyall'd
8

VERSION

10       version 0.82
11

SYNOPSIS

13         In .git/hooks/pre-commit:
14
15           #!/usr/bin/env perl
16           use strict;
17           use warnings;
18
19           use Code::TidyAll::Git::Precommit;
20           Code::TidyAll::Git::Precommit->check();
21

DESCRIPTION

23       This module implements a Git pre-commit hook <http://git-
24       scm.com/book/en/Customizing-Git-Git-Hooks> that checks if all files are
25       tidied and valid according to tidyall, and rejects the commit if not.
26       Files/commits are never modified by this hook.
27
28       See also Code::TidyAll::Git::Prereceive, which validates pushes to a
29       shared repo.
30
31       The tidyall configuration file (tidyall.ini or .tidyallrc) must be
32       checked into git in the repo root directory i.e. next to the .git
33       directory.
34
35       By default, the hook will stash any changes not in the index
36       beforehand, and restore them afterwards, via
37
38           git stash save --keep-index --include-untracked
39           ....
40           git stash pop
41
42       This means that if the configuration file has uncommitted changes that
43       are not in the index, they will not affect the tidyall run.
44

METHODS

46       This class provides one method:
47
48   Code::TidyAll::Git::Precommit->check(%params)
49       Checks that all files being added or modified in this commit are tidied
50       and valid according to tidyall. If not, then the entire commit is
51       rejected and the reason(s) are output to the client. e.g.
52
53           % git commit -m "fixups" CHI.pm CHI/Driver.pm
54           2 files did not pass tidyall check
55           lib/CHI.pm: *** 'PerlTidy': needs tidying
56           lib/CHI/Driver.pm: *** 'PerlCritic': Code before strictures are enabled
57             at /tmp/Code-TidyAll-0e6K/Driver.pm line 2
58             [TestingAndDebugging::RequireUseStrict]
59
60       In an emergency the hook can be bypassed by passing --no-verify to
61       commit:
62
63           % git commit --no-verify ...
64
65       or you can just move .git/hooks/pre-commit out of the way temporarily.
66
67       This class passes mode = "commit" by default to tidyall; see modes.
68
69       Key/value parameters:
70
71       •   conf_name
72
73           A conf file name to search for instead of the defaults.
74
75       •   git_path
76
77           Path to git to use in commands, e.g. '/usr/bin/git' or
78           '/usr/local/bin/git'. By default, it just uses 'git', which will
79           search the user's "PATH".
80
81       •   no_stash
82
83           Don't attempt to stash changes not in the index. This means the
84           hook will process files that are not going to be committed.
85
86       •   tidyall_class
87
88           Subclass to use instead of Code::TidyAll.
89
90       •   tidyall_options
91
92           A hashref of options to pass to the Code::TidyAll constructor.
93

USING AND (NOT) ENFORCING THIS HOOK

95       This hook must be placed manually in each copy of the repo - there is
96       no way to automatically distribute or enforce it. However, you can make
97       things easier on yourself or your developers as follows:
98
99       •   Create a directory called git/hooks at the top of your repo (note
100           no dot prefix).
101
102               mkdir -p git/hooks
103
104       •   Commit your pre-commit script in git/hooks/pre-commit containing:
105
106               #!/usr/bin/env perl
107
108               use strict;
109               use warnings;
110
111               use Code::TidyAll::Git::Precommit;
112               Code::TidyAll::Git::Precommit->check();
113
114       •   Add a setup script in git/setup.sh containing
115
116               #!/bin/bash
117               chmod +x git/hooks/pre-commit
118               cd .git/hooks
119               ln -s ../../git/hooks/pre-commit
120
121       •   Run "git/setup.sh" (or tell your developers to run it) once for
122           each new clone of the repo
123
124       See this Stack Overflow question for more information on pre-commit
125       hooks and the impossibility of enforcing their use.
126
127       See also Code::TidyAll::Git::Prereceive, which enforces tidyall on
128       pushes to a remote shared repository.
129

SUPPORT

131       Bugs may be submitted at
132       <https://github.com/houseabsolute/perl-code-tidyall/issues>.
133

SOURCE

135       The source code repository for Code-TidyAll can be found at
136       <https://github.com/houseabsolute/perl-code-tidyall>.
137

AUTHORS

139       •   Jonathan Swartz <swartz@pobox.com>
140
141       •   Dave Rolsky <autarch@urth.org>
142
144       This software is copyright (c) 2011 - 2022 by Jonathan Swartz.
145
146       This is free software; you can redistribute it and/or modify it under
147       the same terms as the Perl 5 programming language system itself.
148
149       The full text of the license can be found in the LICENSE file included
150       with this distribution.
151
152
153
154perl v5.36.0                      2022-07-22  Code::TidyAll::Git::Precommit(3)
Impressum