add a dzil plugin to ensure that the git checkout is up to date
[gitmo/Moose.git] / inc / GitUpToDate.pm
diff --git a/inc/GitUpToDate.pm b/inc/GitUpToDate.pm
new file mode 100644 (file)
index 0000000..35020e7
--- /dev/null
@@ -0,0 +1,36 @@
+package inc::GitUpToDate;
+use Moose;
+
+with 'Dist::Zilla::Role::BeforeRelease';
+
+sub git {
+    if (wantarray) {
+        chomp(my @ret = qx{git $_[0]});
+        return @ret;
+    }
+    else {
+        chomp(my $ret = qx{git $_[0]});
+        return $ret;
+    }
+}
+
+sub before_release {
+    my $self = shift;
+
+    my $branch = git "symbolic-ref HEAD";
+    die "Could not get the current branch"
+        unless $branch;
+
+    $branch =~ s{refs/heads/}{};
+
+    $self->log("Ensuring branch $branch is up to date");
+
+    git "fetch origin";
+    my $origin = git "rev-parse origin/$branch";
+    my $head = git "rev-parse HEAD";
+
+    die "Branch $branch is not up to date (origin: $origin, HEAD: $head)"
+        if $origin ne $head;
+}
+
+1;