Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion lib/src/project.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,17 @@ class Project {
mutation = m.Sequence([mutation, m.SetPreRelease(pre)]);

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like a cleaner solution would be to strip the pre-release here, like

      mutation = m.Sequence([m.StripPreRelease(), mutation, m.SetPreRelease(pre)]);

but since we don't have StripPreRelease yet, this should work too.

}
final current = await getVersion();
final next = mutation(current);
Version next = mutation(current);
if (next <= current && pre.isNotEmpty && current.isPreRelease) {
// pub_semver's nextPatch/nextMinor/nextMajor strip the pre-release suffix
// rather than incrementing the numeric component (e.g. 0.0.16-beta →
// nextPatch → 0.0.16). When --pre keeps the same identifier the result
// equals the current version. Retry against the stripped release so the
// numeric component actually advances (0.0.16 → nextPatch → 0.0.17 →
// SetPreRelease → 0.0.17-beta).
final base = Version(current.major, current.minor, current.patch);
next = mutation(base);
}
if (next <= current) {
throw ArgumentError(
'The next version must be higher than the current one.');
Expand Down
10 changes: 10 additions & 0 deletions test/functional_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,16 @@ I love my dog.
expect(err.buffer.toString().trim(),
'The next version must be higher than the current one.');
});
test('bump patch --pre=beta from pre-release bumps patch number', () async {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this can be reproduced by adding the line

        ['bump', 'patch', '--pre=alpha']: '0.0.6-alpha',

to the test above

await run(['version', '0.0.16-beta']);
out.buffer.clear();
final code = await run(['bump', 'patch', '--pre=beta']);
expect(code, 0);
expect(err.buffer.toString(), isEmpty);
out.buffer.clear();
await run(['version']);
expect(out.buffer.toString().trim(), '0.0.17-beta');
});
test('incorrect usage', () async {
final code = await run(['bump']);
expect(code, 64);
Expand Down
Loading