use Config;
use File::Spec;
use File::Find;
-use ExtUtils::MakeMaker ();
+use Getopt::Long qw(:config gnu_getopt);
-my $version = $ARGV[0] or die "version required!";
+GetOptions(
+ "branch=s" => \(my $branch = 'master'),
+ "changelog=s" => \(my $changelog = 'Changes'),
+) or die("Error in command line arguments\n");
+
+my $version = shift or die "version required!";
my $make = $Config{make};
my $null = File::Spec->devnull;
die "Tag v$version already exists!";
}
-File::Find::find({ no_chdir => 1, wanted => sub {
- return
- unless -f && /\.pm$/;
- my $file_version = MM->parse_version($_);
- die "Module $_ version $file_version doesn't match dist version $version"
- unless $file_version eq 'undef' || $file_version eq $version;
-}}, 'lib');
-
-for (scalar `"$make" manifest 2>&1 >$null`) {
- $_ && die "$make manifest changed:\n$_ Go check it and retry";
-}
-
-for (scalar `git status`) {
- /^(?:# )?On branch master/ || die "Not on master. EEEK";
- /Your branch is behind|Your branch and .*? have diverged/ && die "Not synced with upstream";
-}
+chomp(my $head = `git symbolic-ref -q HEAD`);
+(my $current_branch = $head) =~ s{^refs/heads/}{};
+$head eq "refs/heads/$branch"
+ or die "Current branch is $current_branch, not $branch. EEEK!\n";
+chomp(my $upstream = `git for-each-ref --format="%(upstream)" $head`);
+length $upstream
+ or die "No upstream branch configured for $branch!\n";
+my $base_rev = `git merge-base $upstream $head`;
+my $upstream_rev = `git rev-parse --verify $upstream`;
+$upstream_rev eq $base_rev
+ or die "Not synced with upstream!\n";
for (scalar `git diff`) {
- length && die "Outstanding changes";
+ length && die "Outstanding changes!\n";
}
my $ymd = sprintf(
"%i-%02i-%02i", (gmtime)[5]+1900, (gmtime)[4]+1, (gmtime)[3]
);
my $changes_line = "$version - $ymd\n";
-my @cached = grep /^\+/, `git diff --cached -U0`;
-@cached > 0 or die "Please add:\n\n$changes_line\nto Changes stage Changes (git add Changes)";
-@cached == 2 or die "Pre-commit Changes not just Changes line";
-$cached[0] =~ /^\+\+\+ .\/Changes\n/ or die "Changes not changed";
-$cached[1] eq "+$changes_line" or die "Changes new line should be: \n\n$changes_line ";
-
-{ no warnings 'exec'; `cpan-upload -h`; }
-$? and die "cpan-upload not available";
+my @cached = grep /^\+/, `git diff --cached -U0 --no-prefix`;
+@cached > 0 or die "Please add:\n\n$changes_line\nto $changelog and stage $changelog (git add $changelog)\n";
+@cached == 2 or die "All '$changelog' changes must be committed aside from version heading\n";
+$cached[0] =~ /^\+\+\+ \Q$changelog\E\n/ or die "$changelog not changed\n";
+$cached[1] eq "+$changes_line" or die "$changelog new line should be: \n\n$changes_line\n";