Moose is installed by Dist::Zilla so safe to use
[p5sagit/Oyster.git] / lib / Oyster / Deploy / Git.pm
CommitLineData
40056462 1package Oyster::Deploy::Git;
73e49568 2use strict;
3use warnings;
40056462 4
680e65b6 5#use Git::Wrapper; # sorry fails tests!
b4e1bb56 6use Moose;
40056462 7
73e49568 8our $post_receive = q{
9#!/bin/sh
10cd ..
c86a7c77 11/usr/bin/git reset --hard HEAD
73e49568 12dzil listdeps | xargs cpanm --local-lib=~/perl5
13};
14
15our $post_update = q{
16#!/bin/sh
17# This rather relies on being an account with permission to do this.
18# Who does the script run as? Presumably the owner of the repo as git will
19# use ssh-keys to get onto the server.
20#
21# Realistically that user needs to be put in /etc/sudoers
22#
23# user ALL=NOPASSWD: /etc/init.d/lighttpd
24#
25# Restart server
26sudo /etc/init.d/lighttpd restart
27};
40056462 28
29sub create {
30 my $self = shift;
31 my $location = shift;
c0ce95cc 32
40056462 33 if( -f $location || -d $location ) {
73e49568 34 die("$location already exists");
40056462 35 }
c0ce95cc 36
40056462 37 mkdir($location);
680e65b6 38 #my $git = Git::Wrapper->new($location);
39 #$git->init();
40 qx{cd $location ; git init};
c0ce95cc 41
680e65b6 42 open my $fh_post_receive, '>', "$location/.git/hooks/post-receive"
43 or die "Cannot write to " . "$location/.git/hooks/post-receive: $!";
73e49568 44 print $fh_post_receive $post_receive;
45 close $fh_post_receive
680e65b6 46 or die "Cannot close " . "$location/.git/hooks/post-receive: $!";
73e49568 47
680e65b6 48 open my $fh_post_update, '>', "$location/.git/hooks/post-update"
49 or die "Cannot write to " . "$location/.git/hooks/post-update: $!";
73e49568 50 print $fh_post_update $post_update;
51 close $fh_post_update
680e65b6 52 or die "Cannot close " . "$location/.git/hooks/post-update: $!";
c0ce95cc 53
680e65b6 54 chmod(0x755, ("$location/.git/hooks/post-receive", "$location/.git/hooks/post-update"));
c0ce95cc 55
40056462 56 return 1;
57}
58
59
47863b26 601;