4 use warnings FATAL => 'all';
6 use Getopt::Long qw(:config gnu_compat);
11 ) or die("Error in command line arguments\n");
13 my ($old_version, $bump) = @ARGV;
14 my ($new_decimal, $new_vstring) = bump_version($old_version, $bump);
16 warn "Bumping $old_version -> $new_decimal\n";
20 if (system "git diff --quiet --cached HEAD") {
21 die "Staged changes!\n";
23 for (`git ls-files`) {
26 unless /^lib\/.*\.(?:pod|pm)$/ || /^Makefile\.PL$/;
27 $files{$_} = `git show HEAD:"$_"`;
37 unless /^lib\/.*\.(?:pod|pm)$/ || /^Makefile\.PL$/;
39 or die "can't open $_: $!";
40 $files{$_} = do { local $/; <$fh> };
47 (^.* \$VERSION \s* = \s* )
48 (['"]?) v?([0-9]+(?:[._][0-9]+)*) \2
57 (^.* version \s* => \s* )
58 (['"]?) v?([0-9]+(?:[._][0-9]+)*) \2
68 for my $file (sort keys %files) {
69 my $content = $files{$file};
71 my $re = $file eq 'Makefile.PL' ? $MAKE_RE : $FILE_RE;
72 my @lines = split /\r?\n/, $content;
73 for my $ln (0 .. $#lines) {
74 my $line = $lines[$ln];
75 if ($lines[$ln] =~ $re) {
76 die "unable to bump version number in $file from $old_version, found $3\n"
77 if $3 ne $old_version;
78 my $comment = ($5 ? $5 . $new_vstring : '');
79 my $new_line = "$1'$new_decimal'$4$comment$6";
80 $file_diff .= <<"END_DIFF";
81 @@ -@{[ $ln ]},3 +@{[ $ln ]},3 @@
90 $patch .= <<"END_HEADER" . $file_diff;
97 my ($fh, $file) = File::Temp::tempfile( "bump-version-XXXXXX", TMPDIR => 1 );
100 system qw(git --no-pager apply --apply --stat), $file
104 system qw(git apply --cached), $file
107 my $message = "Bumping version to $new_decimal";
108 system qw(git commit -m), $message
114 my $dotted = $version =~ s/^v//;
115 my @parts = split /\./, $version;
116 if (!$dotted && @parts == 2) {
117 my $dec = pop @parts;
119 push @parts, $dec =~ /(\d{1,3})/g;
128 my ($old_version, $new) = @_;
130 my %bump_part = (major => 0, minor => 1, bugfix => 2);
131 my $bump_this = $bump_part{$new||'bugfix'};
136 if (defined $bump_this) {
137 my @new_parts = version_parts($old_version);
138 $new_parts[$bump_this]++;
139 $new_parts[$_] = 0 for ($bump_this+1 .. $#new_parts);
140 $new_vstring = join('.', @new_parts);
141 my $alpha_pos = index($old_version, '_');
142 my $format = '%i.' . ( '%03i' x (@new_parts - 1) );
143 $new_decimal = sprintf($format, @new_parts);
144 substr $new_decimal, $alpha_pos, 0, '_'
147 elsif ($new =~ /^v?[0-9]+(?:[._][0-9]+)*$/) {
149 $new_vstring = join('.', version_parts($new_decimal));
152 die "no idea which part to bump - $new means nothing to me"
154 return ($new_decimal, $new_vstring);