1d38b133827e5b9b6e48fca5a3bd2a6ae8f43db2
[p5sagit/Distar.git] / helpers / preflight
1 #!/usr/bin/env perl
2 use strict;
3 use warnings FATAL => 'all';
4 use Config;
5 use File::Spec;
6 use File::Find;
7 use Getopt::Long qw(:config gnu_getopt);
8
9 GetOptions(
10   "branch=s"     => \(my $branch = 'master'),
11   "changelog=s"  => \(my $changelog = 'Changes'),
12 ) or die("Error in command line arguments\n");
13
14 my $version = shift or die "version required!";
15
16 my $make = $Config{make};
17 my $null = File::Spec->devnull;
18
19 system("git fetch");
20 if (system("git rev-parse --quiet --verify v$version >$null") == 0) {
21   die "Tag v$version already exists!";
22 }
23
24 for (scalar `git status`) {
25   /^(?:# )?On branch \Q$branch\E/ || die "Not on $branch. EEEK";
26   /Your branch is behind|Your branch and .*? have diverged/ && die "Not synced with upstream";
27 }
28
29 for (scalar `git diff`) {
30   length && die "Outstanding changes";
31 }
32 my $ymd = sprintf(
33   "%i-%02i-%02i", (gmtime)[5]+1900, (gmtime)[4]+1, (gmtime)[3]
34 );
35 my $changes_line = "$version - $ymd\n";
36 my @cached = grep /^\+/, `git diff --cached -U0`;
37 @cached > 0 or die "Please add:\n\n$changes_line\nto $changelog and stage $changelog (git add $changelog)";
38 @cached == 2 or die "All '$changelog' changes must be committed aside from version heading";
39 $cached[0] =~ /^\+\+\+ .\/\Q$changelog\E\n/ or die "$changelog not changed";
40 $cached[1] eq "+$changes_line" or die "$changelog new line should be: \n\n$changes_line ";
41
42 { no warnings 'exec'; `cpan-upload -h`; }
43 $? and die "cpan-upload not available";