From e73ce3077401ba986019c79c96c71eade3ae570a Mon Sep 17 00:00:00 2001 From: Jusong Yu Date: Thu, 18 May 2023 16:17:34 +0200 Subject: [PATCH] Add --ignore-vcs-tag to support bumping older versions (#207) * Add --ignore-vcs-tag to support bumping older versions --- CHANGELOG.md | 8 ++++++ README.md | 61 +++++++++++++++++++++++++--------------------- src/bumpver/cli.py | 11 ++++++++- test/test_cli.py | 32 ++++++++++++++++++++++++ 4 files changed, 83 insertions(+), 29 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ea1b8bc..01de408 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # 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 - Fix [#200][gh_i200]: Fix compatability with packaging 23.0. diff --git a/README.md b/README.md index f176ef5..4d1e298 100644 --- a/README.md +++ b/README.md @@ -572,8 +572,8 @@ Usage: bumpver [OPTIONS] COMMAND [ARGS]... Options: --version Show the version and exit. - --help Show this message and exit. -v, --verbose Control log level. -vv for debug level. + -h, --help Show this message and exit. Commands: grep Search file(s) for a version pattern. @@ -594,22 +594,27 @@ Usage: bumpver update [OPTIONS] Update project files with the incremented version string. 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. -v, --verbose Control log level. -vv for debug level. --allow-dirty Commit even when working directory is has - uncomitted changes. (WARNING: The commit will - still be aborted if there are uncomitted to - files with version strings. + uncomitted changes. (WARNING: The commit + will still be aborted if there are + uncomitted to files with version strings. + --ignore-vcs-tag Ignore VCS tag invariant and update version + anyway. --set-version Set version explicitly. --date Set explicit date in format YYYY-0M-0D (e.g. - 2021-05-13). + 2023-05-18). --pin-date Leave date components unchanged. --pin-increments Leave the auto-increments INC0 and INC1 + unchanged. --tag-num Increment release tag number (rc1, rc2, rc3..). - -t, --tag Override release tag of current_version. Valid - options are: alpha, beta, dev, rc, post, final. + -t, --tag Override release tag of current_version. + Valid options are: alpha, beta, dev, rc, + post, final. -p, --patch Increment PATCH component. -m, --minor Increment MINOR component. --major Increment MAJOR component. @@ -617,7 +622,7 @@ Options: --commit / --no-commit Create a commit with all updated files. --tag-commit / --no-tag-commit Tag the newly created commit. --push / --no-push Push to the default remote. - --help Show this message and exit. + -h, --help Show this message and exit. ``` @@ -729,24 +734,24 @@ If you wish to avoid this, you should use a pattern which maintains lexicographi -| pattern | examples | PEP440 | lexico. | -|---------------------------------|-------------------------------------|--------|---------| -| `MAJOR.MINOR.PATCH[PYTAGNUM]` | `0.13.10 0.16.10rc1` | yes | no | -| `MAJOR.MINOR[.PATCH[PYTAGNUM]]` | `1.11 0.3.0b5` | yes | no | -| `YYYY.BUILD[PYTAGNUM]` | `2020.1031 2020.1148a0` | yes | yes | -| `YYYY.BUILD[-TAG]` | `2021.1393-beta 2022.1279` | no | yes | -| `YYYY.INC0[PYTAGNUM]` | `2020.10 2021.12b2` | yes | no | -| `YYYY0M.PATCH[-TAG]` | `202005.12 202210.15-beta` | no | no¹ | -| `YYYY0M.BUILD[-TAG]` | `202106.1071 202106.1075-beta` | no | yes | -| `YYYY.0M` | `2020.02 2022.09` | no | yes | -| `YYYY.MM` | `2020.8 2020.10` | yes | no | -| `YYYY.WW` | `2020.8 2021.14` | yes | no | -| `YYYY.MM.PATCH[PYTAGNUM]` | `2020.3.12b0 2021.6.19b0` | yes | no | -| `YYYY.0M.PATCH[PYTAGNUM]` | `2020.10.15b0 2022.07.7b0` | no | no¹ | -| `YYYY.MM.INC0` | `2021.6.2 2022.8.9` | yes | no | -| `YYYY.MM.DD` | `2020.5.18 2021.8.2` | yes | no | -| `YYYY.0M.0D` | `2020.08.24 2022.05.03` | no | yes | -| `YY.0M.PATCH` | `21.04.2 21.11.12` | no | no² | +| pattern | examples | PEP440 | lexico. | +|---------------------------------|-----------------------------------|--------|---------| +| `MAJOR.MINOR.PATCH[PYTAGNUM]` | `0.13.10 0.16.10` | yes | no | +| `MAJOR.MINOR[.PATCH[PYTAGNUM]]` | `0.11.15 0.16.18` | yes | no | +| `YYYY.BUILD[PYTAGNUM]` | `2020.1031 2020.1406` | yes | yes | +| `YYYY.BUILD[-TAG]` | `2021.1393-beta 2022.1279` | no | yes | +| `YYYY.INC0[PYTAGNUM]` | `2020.4b0 2020.16` | yes | no | +| `YYYY0M.PATCH[-TAG]` | `202210.10 202211.13-beta` | no | no¹ | +| `YYYY0M.BUILD[-TAG]` | `202005.1269-beta 202206.1056` | no | yes | +| `YYYY.0M` | `2020.01 2021.04` | no | yes | +| `YYYY.MM` | `2020.2 2022.2` | yes | no | +| `YYYY.WW` | `2020.33 2020.39` | yes | no | +| `YYYY.MM.PATCH[PYTAGNUM]` | `2022.3.1b0 2022.11.15b0` | yes | no | +| `YYYY.0M.PATCH[PYTAGNUM]` | `2020.03.2 2022.02.4` | no | no¹ | +| `YYYY.MM.INC0` | `2020.7.10 2021.7.7` | yes | no | +| `YYYY.MM.DD` | `2020.8.9 2020.8.20` | yes | no | +| `YYYY.0M.0D` | `2020.11.02 2022.05.03` | no | yes | +| `YY.0M.PATCH` | `20.05.12 22.03.5` | no | no² | @@ -769,7 +774,7 @@ number would run backwards if it was created around New Year. -```sql +``` YYYY WW UU GGGG VV 2020-12-26 (Sat): 2020 51 51 2020 52 2020-12-27 (Sun): 2020 51 52 2020 52 diff --git a/src/bumpver/cli.py b/src/bumpver/cli.py index 168971b..25c2af0 100755 --- a/src/bumpver/cli.py +++ b/src/bumpver/cli.py @@ -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): logger.error("Invariant violated: New version must be greater than 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 else: return True @@ -726,6 +727,12 @@ def _parse_vcs_options( "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 @click.option( "-c", @@ -752,6 +759,7 @@ def _parse_vcs_options( def update( dry : bool = False, allow_dirty : bool = False, + ignore_vcs_tag: bool = False, fetch : bool = True, verbose : int = 0, major : bool = False, @@ -786,7 +794,8 @@ def update( logger.warning(f"Invalid argument: {ex}") 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 if set_version is None: diff --git a/test/test_cli.py b/test/test_cli.py index bcccb21..117ca31 100644 --- a/test/test_cli.py +++ b/test/test_cli.py @@ -1295,3 +1295,35 @@ def test_get_latest_vcs_version_tag(runner): _, cfg = config.init() latest_version = cli.get_latest_vcs_version_tag(cfg, fetch=False) 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"