CONTENTS

NAME

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

VERSION

version 0.84

SYNOPSIS

In .git/hooks/pre-commit:

  #!/usr/bin/env perl
  use strict;
  use warnings;

  use Code::TidyAll::Git::Precommit;
  Code::TidyAll::Git::Precommit->check();

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.

See also Code::TidyAll::Git::Prereceive, which validates pushes to a shared repo.

The tidyall configuration file (tidyall.ini or .tidyallrc) must be checked into git in the repo root directory i.e. next to the .git directory.

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

This means that if the configuration file has uncommitted changes that are not in the index, they will not affect the tidyall run.

METHODS

This class provides one method:

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.

% 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-commit out of the way temporarily.

This class passes mode = "commit" by default to tidyall; see modes.

Key/value parameters:

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:

See this Stack Overflow question for more information on pre-commit hooks and the impossibility of enforcing their use.

See also Code::TidyAll::Git::Prereceive, which enforces tidyall on pushes to a remote shared repository.

SUPPORT

Bugs may be submitted at https://github.com/houseabsolute/perl-code-tidyall/issues.

SOURCE

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

AUTHORS

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.