From: Jesse Luehrs <doy@tozt.net>
Date: Mon, 6 Jun 2011 20:16:35 +0000 (-0500)
Subject: add a dzil plugin to ensure that the git checkout is up to date
X-Git-Tag: 2.0008~17
X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=b7fbf2739595f2a9a8cb8caaf429a48662314ac8;p=gitmo%2FMoose.git

add a dzil plugin to ensure that the git checkout is up to date
---

diff --git a/dist.ini b/dist.ini
index c75937a..3bdc0b7 100644
--- a/dist.ini
+++ b/dist.ini
@@ -5,6 +5,7 @@ copyright_holder = Infinity Interactive, Inc.
 
 version = 2.0007
 
+[=inc::GitUpToDate]
 [=inc::RequireAuthorDeps]
 [=inc::Clean]
 
diff --git a/inc/GitUpToDate.pm b/inc/GitUpToDate.pm
new file mode 100644
index 0000000..35020e7
--- /dev/null
+++ b/inc/GitUpToDate.pm
@@ -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;