summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRuss Allbery <rra@cpan.org>2022-01-15 18:17:36 -0800
committerRuss Allbery <rra@cpan.org>2022-01-15 18:17:36 -0800
commitdc7e139d0b60d28a282652e3f69d0196d72b968d (patch)
treebe26792f375faf875c06afdd796ed2c45ad70177
parent03098af3dc6b8da699d1372b09e4f3b77b632656 (diff)
Fix .versions update from docknot release
Fix .versions updating via docknot release when the package that needs to be udpated is not the first line of the file.
-rw-r--r--Changes3
-rw-r--r--lib/App/DocKnot/Spin/Versions.pm41
-rwxr-xr-xt/release/basic.t5
3 files changed, 29 insertions, 20 deletions
diff --git a/Changes b/Changes
index a5dbdee..2eb3515 100644
--- a/Changes
+++ b/Changes
@@ -4,6 +4,9 @@
- Fix import error when running docknot release.
+ - Fix .versions updating via docknot release when the package that needs
+ to be udpated is not the first line of the file.
+
6.01 - 2022-01-15
- Add new docknot release command and corresponding App::DocKnot::Release
diff --git a/lib/App/DocKnot/Spin/Versions.pm b/lib/App/DocKnot/Spin/Versions.pm
index 1655ff0..9212eaa 100644
--- a/lib/App/DocKnot/Spin/Versions.pm
+++ b/lib/App/DocKnot/Spin/Versions.pm
@@ -168,26 +168,29 @@ sub update_version {
# Edits the line for the package to replace the version and release date.
my $edit = sub {
- my $line = $_;
- my ($product, $old_version, $old_date, $old_time)
- = split(q{ }, $line);
- return if $product ne $package;
-
- # We're going to replace the old version with the new one, but we need
- # to space-pad one or the other if they're not the same length.
- my $version_string = $version;
- while (length($old_version) > length($version_string)) {
- $version_string .= q{ };
- }
- while (length($old_version) < length($version_string)) {
- $old_version .= q{ };
- }
+ my @lines = split(m{ \n }xms, $_);
+ for my $line (@lines) {
+ my ($product, $old_version, $old_date, $old_time)
+ = split(q{ }, $line);
+ next if $product ne $package;
+
+ # We're going to replace the old version with the new one, but we
+ # need to space-pad one or the other if they're not the same
+ # length.
+ my $version_string = $version;
+ while (length($old_version) > length($version_string)) {
+ $version_string .= q{ };
+ }
+ while (length($old_version) < length($version_string)) {
+ $old_version .= q{ };
+ }
- # Make the replacement.
- $line =~ s{ \Q$old_version\E }{$version_string}xms;
- $line =~ s{ \Q$old_date\E }{$date}xms;
- $line =~ s{ \Q$old_time\E }{$time}xms;
- $_ = $line;
+ # Make the replacement.
+ $line =~ s{ \Q$old_version\E }{$version_string}xms;
+ $line =~ s{ \Q$old_date\E }{$date}xms;
+ $line =~ s{ \Q$old_time\E }{$time}xms;
+ }
+ $_ = join("\n", @lines) . "\n";
};
# Apply that change to our versions file, and then re-read the contents to
diff --git a/t/release/basic.t b/t/release/basic.t
index 4379136..597cb95 100755
--- a/t/release/basic.t
+++ b/t/release/basic.t
@@ -59,6 +59,7 @@ my $spin_path = $tempdir->child('spin');
$spin_path->mkpath();
my $versions_path = $spin_path->child('.versions');
$versions_path->spew_utf8(
+ "foo 1.0 2021-12-14 17:31:32 software/foo/index.th\n",
"empty 1.9 2022-01-01 16:00:00 software/empty/index.th\n",
);
Git::Repository->run('init', { cwd => "$spin_path", quiet => 1 });
@@ -105,7 +106,9 @@ for my $ext (@extensions) {
}
# Check that the version file was updated.
-my @versions = split(q{ }, $versions_path->slurp_utf8());
+my $versions_line;
+(undef, $versions_line) = $versions_path->lines_utf8();
+my @versions = split(q{ }, $versions_line);
is($versions[0], 'empty', '.versions line');
is($versions[1], '1.10', '...version updated');
isnt(join(q{ }, @versions[2, 3]), '2022-01-01 16:00:00', '...date updated');