diff options
author | Lorry Tar Creator <lorry-tar-importer@lorry> | 2015-06-06 17:50:16 +0000 |
---|---|---|
committer | Lorry Tar Creator <lorry-tar-importer@lorry> | 2015-06-06 17:50:16 +0000 |
commit | 5ac2026f7eed78958d69d051e7a8e993dcf51205 (patch) | |
tree | 298c3d2f08bdfe5689998b11892d72a897985be1 /inc/GitUpToDate.pm | |
download | Moose-tarball-5ac2026f7eed78958d69d051e7a8e993dcf51205.tar.gz |
Moose-2.1405HEADMoose-2.1405master
Diffstat (limited to 'inc/GitUpToDate.pm')
-rw-r--r-- | inc/GitUpToDate.pm | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/inc/GitUpToDate.pm b/inc/GitUpToDate.pm new file mode 100644 index 0000000..b688d8a --- /dev/null +++ b/inc/GitUpToDate.pm @@ -0,0 +1,52 @@ +package inc::GitUpToDate; +use Moose; + +with 'Dist::Zilla::Role::BeforeBuild'; + +sub git { + if (wantarray) { + chomp(my @ret = qx{git $_[0]}); + return @ret; + } + else { + chomp(my $ret = qx{git $_[0]}); + return $ret; + } +} + +sub before_build { + my $self = shift; + + return unless $ENV{DZIL_RELEASING}; + + 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; + + + # now also check that HEAD is current with the release branch + # that is, that the release branch is an ancestor commit of HEAD. + my $release_branch = ($self->zilla->plugin_named('Git::CheckFor::CorrectBranch')->release_branch)[0]; + foreach my $remote ('origin/', '') + { + my $release_commit = git "rev-parse ${remote}$release_branch"; + my $common_ancestor = git "merge-base $head $release_commit"; + + die "Branch $branch does not contain all commits from the current release branch ", + "(common ancestor for ${remote}$release_branch: $common_ancestor)" + if $common_ancestor ne $release_commit; + } +} + +1; |