Skip to content

Commit

Permalink
#45: Skip bumping when distance is 0
Browse files Browse the repository at this point in the history
  • Loading branch information
mtkennerly committed Apr 5, 2022
1 parent eaad8de commit 7843df6
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 13 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,9 @@
## Unreleased

* Fixed the `--bump` CLI option and the `bump` argument of `Version.serialize`
bumping even on a commit with a version tag. Now, no bumping occurs on such
a commit.

## v1.11.0 (2022-03-15)

* Explicitly specified `Optional[...]` typing on arguments with a default of `None`.
Expand Down
3 changes: 2 additions & 1 deletion dunamai/__init__.py
Expand Up @@ -500,13 +500,14 @@ def serialize(
:param bump: If true, increment the last part of the `base` by 1,
unless `stage` is set, in which case either increment `revision`
by 1 or set it to a default of 2 if there was no revision.
Does nothing when on a commit with a version tag.
:param tagged_metadata: If true, insert the `tagged_metadata` in the
version as the first part of the metadata segment.
This is ignored when `format` is used.
"""
base = self.base
revision = self.revision
if bump:
if bump and self.distance > 0:
bumped = self.bump()
base = bumped.base
revision = bumped.revision
Expand Down
1 change: 1 addition & 0 deletions dunamai/__main__.py
Expand Up @@ -88,6 +88,7 @@
"Increment the last part of the version `base` by 1,"
" unless the `stage` is set, in which case increment the `revision`"
" by 1 or set it to a default of 2 if there was no `revision`"
" Does nothing when on a commit with a version tag."
),
},
]
Expand Down
27 changes: 15 additions & 12 deletions tests/unit/test_dunamai.py
Expand Up @@ -145,25 +145,20 @@ def test__version__serialize__pep440() -> None:
assert Version("1", stage=("b", 2)).serialize() == "1b2"
assert Version("1", stage=("rc", 2)).serialize() == "1rc2"

assert Version("0.1.0").serialize(bump=True) == "0.1.1"
assert Version("0.1.0").serialize(bump=True) == "0.1.0"
assert Version("0.1.0", distance=3).serialize(bump=True) == "0.1.1.dev3"
assert Version("1").serialize(bump=True) == "2"
assert Version("1", distance=3).serialize(bump=True) == "2.dev3"
assert Version("0.1.0", stage=("a", None)).serialize(bump=True) == "0.1.0a2"
assert Version("0.1.0", stage=("a", None), distance=3).serialize(bump=True) == "0.1.0a2.dev3"
assert Version("0.1.0", stage=("b", 2)).serialize(bump=True) == "0.1.0b3"
assert Version("0.1.0", stage=("b", 2), distance=3).serialize(bump=True) == "0.1.0b3.dev3"

assert Version("0.1.0", epoch=2).serialize() == "2!0.1.0"

assert Version("0.1.0", stage=("post", 1)).serialize() == "0.1.0.post1"
assert Version("0.1.0", stage=("post", 1)).serialize(bump=True) == "0.1.0.post2"
assert Version("0.1.0", stage=("post", 1), distance=3).serialize() == "0.1.0.post1.dev3"
assert (
Version("0.1.0", stage=("post", 1), distance=3).serialize(bump=True) == "0.1.0.post2.dev3"
)
assert Version("0.1.0", stage=("dev", 1)).serialize() == "0.1.0.dev1"
assert Version("0.1.0", stage=("dev", 1)).serialize(bump=True) == "0.1.0.dev2"
assert Version("0.1.0", stage=("dev", 1), distance=3).serialize() == "0.1.0.dev4"
assert Version("0.1.0", stage=("dev", 1), distance=3).serialize(bump=True) == "0.1.0.dev5"

Expand Down Expand Up @@ -220,12 +215,16 @@ def test__version__serialize__semver() -> None:
assert Version("0.1.0", stage=("beta", 2)).serialize(style=style) == "0.1.0-beta.2"
assert Version("0.1.0", stage=("rc", 2)).serialize(style=style) == "0.1.0-rc.2"

assert Version("0.1.0").serialize(style=style, bump=True) == "0.1.1"
assert Version("0.1.0").serialize(style=style, bump=True) == "0.1.0"
assert Version("0.1.0", distance=3).serialize(style=style, bump=True) == "0.1.1-pre.3"
assert (
Version("0.1.0", stage=("alpha", None)).serialize(style=style, bump=True) == "0.1.0-alpha.2"
Version("0.1.0", stage=("alpha", None), distance=3).serialize(style=style, bump=True)
== "0.1.0-alpha.2.pre.3"
)
assert (
Version("0.1.0", stage=("beta", 2), distance=4).serialize(style=style, bump=True)
== "0.1.0-beta.3.pre.4"
)
assert Version("0.1.0", stage=("beta", 2)).serialize(style=style, bump=True) == "0.1.0-beta.3"

assert Version("0.1.0", epoch=2).serialize(style=style) == "0.1.0"

Expand Down Expand Up @@ -282,12 +281,16 @@ def test__version__serialize__pvp() -> None:
assert Version("0.1.0", stage=("beta", 2)).serialize(style=style) == "0.1.0-beta-2"
assert Version("0.1.0", stage=("rc", 2)).serialize(style=style) == "0.1.0-rc-2"

assert Version("0.1.0").serialize(style=style, bump=True) == "0.1.1"
assert Version("0.1.0").serialize(style=style, bump=True) == "0.1.0"
assert Version("0.1.0", distance=3).serialize(style=style, bump=True) == "0.1.1-pre-3"
assert (
Version("0.1.0", stage=("alpha", None)).serialize(style=style, bump=True) == "0.1.0-alpha-2"
Version("0.1.0", stage=("alpha", None), distance=3).serialize(style=style, bump=True)
== "0.1.0-alpha-2-pre-3"
)
assert (
Version("0.1.0", stage=("beta", 2), distance=4).serialize(style=style, bump=True)
== "0.1.0-beta-3-pre-4"
)
assert Version("0.1.0", stage=("beta", 2)).serialize(style=style, bump=True) == "0.1.0-beta-3"

assert Version("0.1.0", epoch=2).serialize(style=style) == "0.1.0"

Expand Down

0 comments on commit 7843df6

Please sign in to comment.