Skip to content
This repository
branch: version-range
Fetching contributors…

Cannot retrieve contributors at this time

file 39 lines (32 sloc) 1.212 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
name 'git_site_perl';
description 'Hooks to keep site_perl in git';
author 'Tatsuhiko Miyagawa';

use Config;
use Cwd;

my $site_perl = ($ENV{PERL_MM_OPT} =~ /INSTALL_BASE=(\S+)/)[0] || $Config{installsitelib};

hook init => sub {
    my $args = shift;

    my $git_dir = File::Spec->catfile($site_perl, ".git");

    unless (-e $git_dir && -w $site_perl) {
        $args->{app}->diag("Initializing git repository for $site_perl\n");
        my $cwd = Cwd::cwd();
        if (chdir $site_perl) {
            $args->{app}->run("git init") &&
            $args->{app}->run("git add .") &&
            $args->{app}->run("git commit -m " . $args->{app}->shell_quote("initial commit"));
            chdir $cwd;
        }
    }
};

hook install_success => sub {
    my $args = shift;

    if (-e $site_perl && -w _) {
        my $cwd = Cwd::cwd();
        chdir $site_perl or die $!;
        my $message = "$args->{meta}->{name} $args->{meta}->{version} ($args->{module})";
        $args->{app}->diag("Committing updates in $site_perl to git...\n");
        $args->{app}->run("git add .") &&
        $args->{app}->run("git commit -m " . $args->{app}->shell_quote($message));
        chdir $cwd;
    }
};
Something went wrong with that request. Please try again.