A mutable class will throw errors from inside CMOP, and that's expected
[gitmo/Moose.git] / inc / GitUpToDate.pm
CommitLineData
32f47d4c 1package inc::GitUpToDate;
2use Moose;
3
32e9a3ed 4with 'Dist::Zilla::Role::BeforeBuild';
32f47d4c 5
6sub git {
7 if (wantarray) {
8 chomp(my @ret = qx{git $_[0]});
9 return @ret;
10 }
11 else {
12 chomp(my $ret = qx{git $_[0]});
13 return $ret;
14 }
15}
16
32e9a3ed 17sub before_build {
32f47d4c 18 my $self = shift;
19
32e9a3ed 20 return unless $ENV{DZIL_RELEASING};
21
32f47d4c 22 my $branch = git "symbolic-ref HEAD";
23 die "Could not get the current branch"
24 unless $branch;
25
26 $branch =~ s{refs/heads/}{};
27
28 $self->log("Ensuring branch $branch is up to date");
29
30 git "fetch origin";
31 my $origin = git "rev-parse origin/$branch";
32 my $head = git "rev-parse HEAD";
33
34 die "Branch $branch is not up to date (origin: $origin, HEAD: $head)"
35 if $origin ne $head;
36}
37
381;