Code::T...recommit(3)
π NAME π
Okay so bestie, welcome to Code::TidyAll::Git::Precommit β it's a Git pre-commit hook that literally will not let you commit unless every file is tidyall'd. No cap. The actual man page title is Code::T...recommit(3) (yes, they truncated it, iconic of them), and this is the User Contributed Perl Documentation version.
β¨ VERSION β¨
version 0.84 π
π¦ SYNOPSIS π¦
So like, in .git/hooks/pre-commit you drop this:
#!/usr/bin/env perl
use strict;
use warnings;
use Code::TidyAll::Git::Precommit;
Code::TidyAll::Git::Precommit->check();
That's it. That's the whole vibe check. π«Ά
πΈ DESCRIPTION πΈ
This module implements a Git pre-commit hook (link in the original: <http://git-scm.com/book/en/Customizing-Git-Git-Hooks>) that checks if all files are tidied and valid according to tidyall, and rejects the commit if not. And listen β files/commits are never modified by this hook. It's a bouncer, not a stylist. π
Also see Code::TidyAll::Git::Prereceive, which validates pushes to a shared repo. Different vibe, same energy.
Your tidyall configuration file (tidyall.ini or .tidyallrc) must be checked into git in the repo root directory β i.e. right next to the .git directory. Like, literally next to it. Don't make it weird. π
By default, the hook will stash any changes not in the index beforehand, and restore them afterwards, via:
git stash save --keep-index --include-untracked
....
git stash pop
Which means: if the configuration file has uncommitted changes that are not in the index, they will not affect the tidyall run. Sneaky little detail but we love a consistent test environment. β¨
π METHODS π
This class provides one method, and honestly one is enough:
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. Like, for example:
% 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]
Read it and weep, then go tidy your files. π
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. Do with that information what you will. π
This class passes mode = "commit" by default to tidyall; see modes.
Key/value parameters, bestie, here we go:
conf_nameβ A conf file name to search for instead of the defaults.git_pathβ 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"PATH".no_stashβ Don't attempt to stash changes not in the index. Heads up though: this means the hook will process files that are not going to be committed. π«£tidyall_classβ Subclass to use instead ofCode::TidyAll.tidyall_optionsβ A hashref of options to pass to theCode::TidyAllconstructor.
π§ USING AND (NOT) ENFORCING THIS HOOK π§
Okay this is the part where I have to be real with you: this hook must be placed manually in each copy of the repo β there is no way to automatically distribute or enforce it. It's giving main character who refuses to be managed. 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, we're being quirky here):
mkdir -p git/hooks
- Commit your pre-commit script in
git/hooks/pre-commitcontaining:
#!/usr/bin/env perl
use strict;
use warnings;
use Code::TidyAll::Git::Precommit;
Code::TidyAll::Git::Precommit->check();
- Add a setup script in
git/setup.shcontaining:
#!/bin/bash
chmod +x git/hooks/pre-commit
cd .git/hooks
ln -s ../../git/hooks/pre-commit
- Run
"git/setup.sh"(or tell your developers to run it) once for each new clone of the repo. Yes, once per clone. I know. I know. π
See this Stack Overflow question for more information on pre-commit hooks and the impossibility of enforcing their use. (The original page references it; can't link it here, but you know the one.) π
See also Code::TidyAll::Git::Prereceive, which enforces tidyall on pushes to a remote shared repository β that's the one that can actually be enforced, slay. π
π SUPPORT π
Bugs may be submitted at <https://github.com/houseabsolute/perl-code-tidyall/issues>. Please be nice to the maintainers, they're doing their best. π
β SOURCE β
The source code repository for Code-TidyAll can be found at <https://github.com/houseabsolute/perl-code-tidyall>.
π AUTHORS π
- Jonathan Swartz <swartz@pobox.com>
- Dave Rolsky <autarch@urth.org>
Legends, both of them. π«Ά
π COPYRIGHT AND LICENSE π
This software is copyright (c) 2011 - 2023 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.
The full text of the license can be found in the LICENSE file included with this distribution.
And that's the whole page, bestie β brought to you by perl v5.42.0, dated 2024-03-08, from the Code::T...recommit(3) manual. Go forth and commit tidy files only. π
β¨π
π¦ where this page comes from
- opensuse-leap 16.0: perl-Code-TidyAll 0.840.0-bp160.1.4 Β· Artistic-1.0 OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms