Code-TidyAll

 view release on metacpan or  search on metacpan

lib/Code/TidyAll/Git/Prereceive.pm  view on Meta::CPAN

package Code::TidyAll::Git::Prereceive;

use strict;
use warnings;

use Capture::Tiny       qw(capture);
use Code::TidyAll::Util qw(tempdir_simple);
use Code::TidyAll;
use Digest::SHA         qw(sha1_hex);
use IPC::System::Simple qw(capturex run);
use Path::Tiny          qw(cwd path);
use Specio::Library::Builtins;
use Specio::Library::Numeric;
use Specio::Library::String;
use Try::Tiny;

use Moo;

our $VERSION = '0.85';

has allow_repeated_push => (
    is      => 'ro',
    isa     => t('PositiveInt'),
    default => 3,
);

has conf_name => (
    is  => 'ro',
    isa => t('NonEmptyStr'),
);

has extra_conf_files => (
    is      => 'ro',
    isa     => t( 'ArrayRef', of => t('NonEmptyStr') ),
    default => sub { [] },
);

has git_path => (
    is      => 'ro',
    isa     => t('NonEmptyStr'),
    default => 'git',
);

has tidyall_class => (
    is      => 'ro',
    isa     => t('ClassName'),
    default => 'Code::TidyAll',
);

has tidyall_options => (
    is      => 'ro',
    isa     => t('HashRef'),
    default => sub { {} }
);

sub check {
    my ( $class, %params ) = @_;

    my $fail_msg;
    try {
        my $self = $class->new(%params);

        my $root_dir = cwd();
        local $ENV{GIT_DIR} = $root_dir;

        my $input = do { local $/; <STDIN> };
        $fail_msg = $self->check_input($input);
    }
    catch {
        my $error = $_;
        if ( $params{reject_on_error} ) {
            die $error;
        }
        else {
            print STDERR "*** Error running pre-receive hook (allowing push to proceed):\n$error";



( run in 2.735 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )