4 use warnings FATAL => 'all';
6 use Getopt::Long qw(:config gnu_getopt);
11 "force" => \my $force,
12 ) or die("Error in command line arguments\n");
14 my $old_version = shift
15 or die "no old version provided!\n";
17 my ($new_decimal, $new_vstring) = bump_version($old_version, $bump);
19 warn "Bumping $old_version -> $new_decimal\n";
23 |lib[/\\].*\.(?:pod|pm)
40 if (system "git diff --quiet --cached HEAD") {
41 die "Staged changes!\n";
43 for (`git ls-files`) {
46 unless /^$file_match$/;
47 $files{$_} = `git show HEAD:"$_"`;
54 my $fn = File::Spec->abs2rel($_, '.');
55 if (-d && $fn !~ /^$dir_match$/) {
56 $File::Find::prune = 1;
62 unless $fn =~ /^$file_match$/;
64 or die "can't open $fn: $!";
65 $files{$fn} = do { local $/; <$fh> };
72 (^.* \$VERSION \s* = \s* )
73 (['"]?) v?([0-9]+(?:[._][0-9]+)*) \2
82 (^.* ['"]?version['"] \s* => \s* )
83 (['"]?) v?([0-9]+(?:[._][0-9]+)*) \2
93 for my $file (sort keys %files) {
94 my $content = $files{$file};
96 my $re = $file eq 'Makefile.PL' ? $MAKE_RE : $FILE_RE;
97 my @lines = split /\r?\n/, $content;
98 for my $ln (0 .. $#lines) {
99 my $line = $lines[$ln];
100 if ($lines[$ln] =~ $re) {
101 die "unable to bump version number in $file from $old_version, found $3\n"
102 if !$force && $3 ne $old_version;
103 my $comment = ($5 ? $5 . $new_vstring : '');
104 my $new_line = "$1'$new_decimal'$4$comment$6";
105 $file_diff .= <<"END_DIFF";
106 @@ -@{[ $ln ]},3 +@{[ $ln ]},3 @@
115 $patch .= <<"END_HEADER" . $file_diff;
122 my ($fh, $file) = File::Temp::tempfile( "bump-version-XXXXXX", TMPDIR => 1 );
123 print { $fh } $patch;
125 system qw(git --no-pager apply --apply --stat), $file
129 system qw(git apply --cached), $file
132 my $message = "Bumping version to $new_decimal";
133 system qw(git commit -m), $message
139 my $dotted = $version =~ s/^v//;
140 my @parts = split /\./, $version;
141 if (!$dotted && @parts == 2) {
142 my $dec = pop @parts;
144 $dec .= "0" x ((- length $dec) % 3);
145 push @parts, $dec =~ /(\d{1,3})/g;
152 my ($version, $new) = @_;
154 my %bump_part = (major => 0, minor => 1, bugfix => 2, last => -1);
155 my $bump_this = $bump_part{$new||'last'};
160 if (defined $bump_this) {
161 if ($version =~ /^v/ || ($version =~ tr/.//) > 1) {
162 my @parts = version_parts($version);
163 $parts[$bump_this]++;
164 $parts[$_] = 0 for (($bump_this < 0 ? @parts : 0)+$bump_this+1 .. $#parts);
167 $new_vstring = join '.', @parts;
168 my $format = '%i.'. join '', map { '%03i' } @parts[1 .. $#parts];
169 $new_decimal = sprintf $format, @parts;
172 my $alpha_pos = index($version, '_');
174 $version =~ s/^(\d+)\.//;
176 push @parts, $version =~ /(\d{1,3})/g;
177 my $format = '%i.'.join '', map { '%0'.length($_).'i' } @parts[1 .. $#parts];
178 $parts[$bump_this]++;
179 $parts[$_] = 0 for (($bump_this < 0 ? @parts : 0)+$bump_this+1 .. $#parts);
180 $new_decimal = sprintf $format, @parts;
181 substr $new_decimal, $alpha_pos, 0, '_'
183 $new_vstring = join '.', version_parts($new_decimal);
186 elsif ($new =~ /^v?[0-9]+(?:[._][0-9]+)*$/) {
188 $new_vstring = join('.', version_parts($new_decimal));
191 die "no idea which part to bump - $new means nothing to me"
193 return ($new_decimal, $new_vstring);