show the first line here when testing with a harness
[gitmo/Moose.git] / inc / GitUpToDate.pm
1 package inc::GitUpToDate;
2 use Moose;
3
4 with 'Dist::Zilla::Role::BeforeBuild';
5
6 sub 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
17 sub before_build {
18     my $self = shift;
19
20     return unless $ENV{DZIL_RELEASING};
21
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
38 1;