Add --ignore-vcs-tag to support bumping older versions (#207)

* Add --ignore-vcs-tag to support bumping older versions
This commit is contained in:
Jusong Yu 2023-05-18 16:17:34 +02:00 committed by GitHub
parent 04d7ecc112
commit e73ce30774
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 83 additions and 29 deletions

View file

@ -1,5 +1,13 @@
# Changelog for https://github.com/mbarkhau/bumpver # Changelog for https://github.com/mbarkhau/bumpver
## BumpVer 2023.1122
- Fix [#207][gh_i207]: Add --ignore-vcs-tag for old version support purpose
[gh_i207]: https://github.com/mbarkhau/bumpver/issues/207
Thank you [Jusong Yu](https://github.com/unkcpz) for your contribution.
## BumpVer 2023.1121 ## BumpVer 2023.1121
- Fix [#200][gh_i200]: Fix compatability with packaging 23.0. - Fix [#200][gh_i200]: Fix compatability with packaging 23.0.

View file

@ -572,8 +572,8 @@ Usage: bumpver [OPTIONS] COMMAND [ARGS]...
Options: Options:
--version Show the version and exit. --version Show the version and exit.
--help Show this message and exit.
-v, --verbose Control log level. -vv for debug level. -v, --verbose Control log level. -vv for debug level.
-h, --help Show this message and exit.
Commands: Commands:
grep Search file(s) for a version pattern. grep Search file(s) for a version pattern.
@ -594,22 +594,27 @@ Usage: bumpver update [OPTIONS]
Update project files with the incremented version string. Update project files with the incremented version string.
Options: Options:
-d, --dry Display diff of changes, don't rewrite files. -d, --dry Display diff of changes, don't rewrite
files.
-f, --fetch / -n, --no-fetch Sync tags from remote origin. -f, --fetch / -n, --no-fetch Sync tags from remote origin.
-v, --verbose Control log level. -vv for debug level. -v, --verbose Control log level. -vv for debug level.
--allow-dirty Commit even when working directory is has --allow-dirty Commit even when working directory is has
uncomitted changes. (WARNING: The commit will uncomitted changes. (WARNING: The commit
still be aborted if there are uncomitted to will still be aborted if there are
files with version strings. uncomitted to files with version strings.
--ignore-vcs-tag Ignore VCS tag invariant and update version
anyway.
--set-version <VERSION> Set version explicitly. --set-version <VERSION> Set version explicitly.
--date <ISODATE> Set explicit date in format YYYY-0M-0D (e.g. --date <ISODATE> Set explicit date in format YYYY-0M-0D (e.g.
2021-05-13). 2023-05-18).
--pin-date Leave date components unchanged. --pin-date Leave date components unchanged.
--pin-increments Leave the auto-increments INC0 and INC1 --pin-increments Leave the auto-increments INC0 and INC1
unchanged.
--tag-num Increment release tag number (rc1, rc2, --tag-num Increment release tag number (rc1, rc2,
rc3..). rc3..).
-t, --tag <NAME> Override release tag of current_version. Valid -t, --tag <NAME> Override release tag of current_version.
options are: alpha, beta, dev, rc, post, final. Valid options are: alpha, beta, dev, rc,
post, final.
-p, --patch Increment PATCH component. -p, --patch Increment PATCH component.
-m, --minor Increment MINOR component. -m, --minor Increment MINOR component.
--major Increment MAJOR component. --major Increment MAJOR component.
@ -617,7 +622,7 @@ Options:
--commit / --no-commit Create a commit with all updated files. --commit / --no-commit Create a commit with all updated files.
--tag-commit / --no-tag-commit Tag the newly created commit. --tag-commit / --no-tag-commit Tag the newly created commit.
--push / --no-push Push to the default remote. --push / --no-push Push to the default remote.
--help Show this message and exit. -h, --help Show this message and exit.
``` ```
<!-- END bumpver update --help --> <!-- END bumpver update --help -->
@ -729,24 +734,24 @@ If you wish to avoid this, you should use a pattern which maintains lexicographi
<!-- BEGIN pattern_examples --> <!-- BEGIN pattern_examples -->
| pattern | examples | PEP440 | lexico. | | pattern | examples | PEP440 | lexico. |
|---------------------------------|-------------------------------------|--------|---------| |---------------------------------|-----------------------------------|--------|---------|
| `MAJOR.MINOR.PATCH[PYTAGNUM]` | `0.13.10 0.16.10rc1` | yes | no | | `MAJOR.MINOR.PATCH[PYTAGNUM]` | `0.13.10 0.16.10` | yes | no |
| `MAJOR.MINOR[.PATCH[PYTAGNUM]]` | `1.11 0.3.0b5` | yes | no | | `MAJOR.MINOR[.PATCH[PYTAGNUM]]` | `0.11.15 0.16.18` | yes | no |
| `YYYY.BUILD[PYTAGNUM]` | `2020.1031 2020.1148a0` | yes | yes | | `YYYY.BUILD[PYTAGNUM]` | `2020.1031 2020.1406` | yes | yes |
| `YYYY.BUILD[-TAG]` | `2021.1393-beta 2022.1279` | no | yes | | `YYYY.BUILD[-TAG]` | `2021.1393-beta 2022.1279` | no | yes |
| `YYYY.INC0[PYTAGNUM]` | `2020.10 2021.12b2` | yes | no | | `YYYY.INC0[PYTAGNUM]` | `2020.4b0 2020.16` | yes | no |
| `YYYY0M.PATCH[-TAG]` | `202005.12 202210.15-beta` | no | no¹ | | `YYYY0M.PATCH[-TAG]` | `202210.10 202211.13-beta` | no | no¹ |
| `YYYY0M.BUILD[-TAG]` | `202106.1071 202106.1075-beta` | no | yes | | `YYYY0M.BUILD[-TAG]` | `202005.1269-beta 202206.1056` | no | yes |
| `YYYY.0M` | `2020.02 2022.09` | no | yes | | `YYYY.0M` | `2020.01 2021.04` | no | yes |
| `YYYY.MM` | `2020.8 2020.10` | yes | no | | `YYYY.MM` | `2020.2 2022.2` | yes | no |
| `YYYY.WW` | `2020.8 2021.14` | yes | no | | `YYYY.WW` | `2020.33 2020.39` | yes | no |
| `YYYY.MM.PATCH[PYTAGNUM]` | `2020.3.12b0 2021.6.19b0` | yes | no | | `YYYY.MM.PATCH[PYTAGNUM]` | `2022.3.1b0 2022.11.15b0` | yes | no |
| `YYYY.0M.PATCH[PYTAGNUM]` | `2020.10.15b0 2022.07.7b0` | no | no¹ | | `YYYY.0M.PATCH[PYTAGNUM]` | `2020.03.2 2022.02.4` | no | no¹ |
| `YYYY.MM.INC0` | `2021.6.2 2022.8.9` | yes | no | | `YYYY.MM.INC0` | `2020.7.10 2021.7.7` | yes | no |
| `YYYY.MM.DD` | `2020.5.18 2021.8.2` | yes | no | | `YYYY.MM.DD` | `2020.8.9 2020.8.20` | yes | no |
| `YYYY.0M.0D` | `2020.08.24 2022.05.03` | no | yes | | `YYYY.0M.0D` | `2020.11.02 2022.05.03` | no | yes |
| `YY.0M.PATCH` | `21.04.2 21.11.12` | no | no² | | `YY.0M.PATCH` | `20.05.12 22.03.5` | no | no² |
<!-- END pattern_examples --> <!-- END pattern_examples -->
@ -769,7 +774,7 @@ number would run backwards if it was created around New Year.
<!-- BEGIN weeknum_example --> <!-- BEGIN weeknum_example -->
```sql ```
YYYY WW UU GGGG VV YYYY WW UU GGGG VV
2020-12-26 (Sat): 2020 51 51 2020 52 2020-12-26 (Sat): 2020 51 51 2020 52
2020-12-27 (Sun): 2020 51 52 2020 52 2020-12-27 (Sun): 2020 51 52 2020 52

View file

@ -520,6 +520,7 @@ def _is_valid_version(raw_pattern: str, old_version: str, new_version: str) -> b
if version.parse_version(new_version) <= version.parse_version(old_version): if version.parse_version(new_version) <= version.parse_version(old_version):
logger.error("Invariant violated: New version must be greater than old version ") logger.error("Invariant violated: New version must be greater than old version ")
logger.error(f" Failed Invariant: '{new_version}' > '{old_version}'") logger.error(f" Failed Invariant: '{new_version}' > '{old_version}'")
logger.error("If the invariant is from vcs tags try '--ignore-vcs-tag' option.")
return False return False
else: else:
return True return True
@ -726,6 +727,12 @@ def _parse_vcs_options(
"to files with version strings." "to files with version strings."
), ),
) )
@click.option(
"--ignore-vcs-tag",
default=False,
is_flag=True,
help="Ignore VCS tag invariant and update version anyway.",
)
@version_options @version_options
@click.option( @click.option(
"-c", "-c",
@ -752,6 +759,7 @@ def _parse_vcs_options(
def update( def update(
dry : bool = False, dry : bool = False,
allow_dirty : bool = False, allow_dirty : bool = False,
ignore_vcs_tag: bool = False,
fetch : bool = True, fetch : bool = True,
verbose : int = 0, verbose : int = 0,
major : bool = False, major : bool = False,
@ -786,7 +794,8 @@ def update(
logger.warning(f"Invalid argument: {ex}") logger.warning(f"Invalid argument: {ex}")
sys.exit(1) sys.exit(1)
cfg = _update_cfg_from_vcs(cfg, fetch) if not ignore_vcs_tag:
cfg = _update_cfg_from_vcs(cfg, fetch)
old_version = cfg.current_version old_version = cfg.current_version
if set_version is None: if set_version is None:

View file

@ -1295,3 +1295,35 @@ def test_get_latest_vcs_version_tag(runner):
_, cfg = config.init() _, cfg = config.init()
latest_version = cli.get_latest_vcs_version_tag(cfg, fetch=False) latest_version = cli.get_latest_vcs_version_tag(cfg, fetch=False)
assert latest_version == "0.1.10" assert latest_version == "0.1.10"
def test_ignore_vcs_tag(runner, monkeypatch):
result = runner.invoke(cli.cli, ['init', "-vv"])
assert result.exit_code == 0
_update_config_val("bumpver.toml", push="false")
_update_config_val("bumpver.toml", current_version='"0.1.8"')
_update_config_val("bumpver.toml", version_pattern='"MAJOR.MINOR.PATCH"')
_vcs_init("git", files=["bumpver.toml"])
_, cfg = config.init()
# mock latest vcs tag 0.2.0 but cfg.current_version is 0.1.8
monkeypatch.setattr(cli, "get_latest_vcs_version_tag", lambda cfg, fetch: "0.2.0")
assert cfg.current_version == "0.1.8"
assert cli.get_latest_vcs_version_tag(cfg, fetch=False) == "0.2.0"
result = runner.invoke(cli.cli, ['update', "--set-version", "0.1.9"])
assert result.exit_code == 1
result = runner.invoke(
cli.cli, ['update', "-vv", "--ignore-vcs-tag", "--dry", "--set-version", "0.1.9"]
)
assert result.exit_code == 0
out_lines = set(result.output.splitlines())
assert '-current_version = "0.1.8"' in out_lines
assert '+current_version = "0.1.9"' in out_lines
latest_version = cli.get_latest_vcs_version_tag(cfg, fetch=False)
assert latest_version == "0.2.0"