add a dzil plugin to ensure that the git checkout is up to date
[gitmo/Moose.git] / inc / GitUpToDate.pm
1 package inc::GitUpToDate;
2 use Moose;
3
4 with 'Dist::Zilla::Role::BeforeRelease';
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_release {
18     my $self = shift;
19
20     my $branch = git "symbolic-ref HEAD";
21     die "Could not get the current branch"
22         unless $branch;
23
24     $branch =~ s{refs/heads/}{};
25
26     $self->log("Ensuring branch $branch is up to date");
27
28     git "fetch origin";
29     my $origin = git "rev-parse origin/$branch";
30     my $head = git "rev-parse HEAD";
31
32     die "Branch $branch is not up to date (origin: $origin, HEAD: $head)"
33         if $origin ne $head;
34 }
35
36 1;