X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FOyster%2FDeploy%2FGit.pm;h=22098c2f3f65538b6292982e0ed6ef4130a201e1;hb=c86a7c77692e51f6c19ad02b5eee3aeb793880a0;hp=12e4ba0fa9ff6df370522b7c7a49d8734fde287e;hpb=6b832bd6eabfef633627b14a5252110b8653e310;p=p5sagit%2FOyster.git diff --git a/lib/Oyster/Deploy/Git.pm b/lib/Oyster/Deploy/Git.pm index 12e4ba0..22098c2 100644 --- a/lib/Oyster/Deploy/Git.pm +++ b/lib/Oyster/Deploy/Git.pm @@ -1,46 +1,57 @@ package Oyster::Deploy::Git; +use strict; +use warnings; -use Moose; -use Git::Wrapper; -use Error::Simple; +#use Git::Wrapper; # sorry fails tests! -use Data::Dumper; -use File::Copy; -use File::ShareDir ':ALL'; +our $post_receive = q{ +#!/bin/sh +cd .. +/usr/bin/git reset --hard HEAD +dzil listdeps | xargs cpanm --local-lib=~/perl5 +}; + +our $post_update = q{ +#!/bin/sh +# This rather relies on being an account with permission to do this. +# Who does the script run as? Presumably the owner of the repo as git will +# use ssh-keys to get onto the server. +# +# Realistically that user needs to be put in /etc/sudoers +# +# user ALL=NOPASSWD: /etc/init.d/lighttpd +# +# Restart server +sudo /etc/init.d/lighttpd restart +}; sub create { my $self = shift; my $location = shift; - + if( -f $location || -d $location ) { - Error::Simple->throw("$location already exists"); + die("$location already exists"); } - + mkdir($location); - my $git = Git::Wrapper->new($location); - $git->init(); - - my ($postreceive, $postupdate); - - eval { - $postreceive = dist_file( 'Oyster', './deploy/git/post-receive'); - $postupdate = dist_file( 'Oyster', './deploy/git/post-update'); - }; - #Beware there be deamons here - if ($@) { - $postreceive = './share/deploy/git/post-receive'; - $postupdate = './share/deploy/git/post-update'; - } + #my $git = Git::Wrapper->new($location); + #$git->init(); + qx{cd $location ; git init}; + + open my $fh_post_receive, '>', "$location/.git/hooks/post-receive" + or die "Cannot write to " . "$location/.git/hooks/post-receive: $!"; + print $fh_post_receive $post_receive; + close $fh_post_receive + or die "Cannot close " . "$location/.git/hooks/post-receive: $!"; + + open my $fh_post_update, '>', "$location/.git/hooks/post-update" + or die "Cannot write to " . "$location/.git/hooks/post-update: $!"; + print $fh_post_update $post_update; + close $fh_post_update + or die "Cannot close " . "$location/.git/hooks/post-update: $!"; + chmod(0x755, ("$location/.git/hooks/post-receive", "$location/.git/hooks/post-update")); - copy($postreceive, ($git->dir . '/.git/hooks/')) - or Error::Simple->throw('Creating post commit hooks failed.'); - - copy($postupdate, ($git->dir . '/.git/hooks/')) - or Error::Simple->throw('Creating post commit hooks failed.'); - - chmod(0x755, ($git->dir . '.git/hooks/post-receive', $git->dir . '.git/hooks/post-update')); - return 1; }