Moose is installed by Dist::Zilla so safe to use
[p5sagit/Oyster.git] / lib / Oyster / Deploy / Git.pm
1 package Oyster::Deploy::Git;
2 use strict;
3 use warnings;
4
5 #use Git::Wrapper;    # sorry fails tests!
6 use Moose;
7
8 our $post_receive = q{
9 #!/bin/sh
10 cd ..
11 /usr/bin/git reset --hard HEAD
12 dzil listdeps | xargs cpanm --local-lib=~/perl5
13 };
14
15 our $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
26 sudo /etc/init.d/lighttpd restart
27 };
28
29 sub create {
30   my $self = shift;
31   my $location = shift;
32
33   if( -f $location || -d $location ) {
34     die("$location already exists");
35   }
36
37   mkdir($location);
38   #my $git = Git::Wrapper->new($location);
39   #$git->init();
40   qx{cd $location ; git init};
41
42   open my $fh_post_receive, '>', "$location/.git/hooks/post-receive"
43     or die "Cannot write to " .  "$location/.git/hooks/post-receive: $!";
44   print $fh_post_receive $post_receive;
45   close $fh_post_receive
46     or die "Cannot close " . "$location/.git/hooks/post-receive: $!";
47
48   open my $fh_post_update, '>', "$location/.git/hooks/post-update"
49     or die "Cannot write to " . "$location/.git/hooks/post-update: $!";
50   print $fh_post_update $post_update;
51   close $fh_post_update
52     or die "Cannot close " . "$location/.git/hooks/post-update: $!";
53
54   chmod(0x755, ("$location/.git/hooks/post-receive", "$location/.git/hooks/post-update"));
55
56   return 1;
57 }
58
59
60 1;