diff --git a/src/bumpver/cli.py b/src/bumpver/cli.py index 6fffac3..70425a9 100755 --- a/src/bumpver/cli.py +++ b/src/bumpver/cli.py @@ -678,27 +678,27 @@ def _update_cfg_from_vcs(cfg: config.Config, fetch: bool) -> config.Config: def _parse_vcs_options( - cfg : config.Config, - commit: typ.Optional[bool] = None, - tag : typ.Optional[bool] = None, - push : typ.Optional[bool] = None, + cfg : config.Config, + commit : typ.Optional[bool] = None, + tag_commit: typ.Optional[bool] = None, + push : typ.Optional[bool] = None, ) -> config.Config: + if commit is False and tag_commit: + raise ValueError("--no-commit and --tag-commit cannot be used at the same time") + if commit is False and push: + raise ValueError("--no-commit and --push cannot be used at the same time") + if commit is not None: - if not commit: - if tag: - raise ValueError("--no-commit and --tag-commit cannot be used at the same time") - if push: - raise ValueError("--no-commit and --push cannot be used at the same time") cfg = cfg._replace(commit=commit) - if tag is not None: - if tag and not cfg.commit: - raise ValueError( - "--tag-commit requires the --commit flag if commit=False in the config file" - ) - cfg = cfg._replace(tag=tag) + + if not cfg.commit and tag_commit: + raise ValueError("--tag-commit requires either --commit or commit=True in your config") + if not cfg.commit and push: + raise ValueError("--push requires either --commit or commit=True in your config") + + if tag_commit is not None: + cfg = cfg._replace(tag=tag_commit) if push is not None: - if push and not cfg.commit: - raise ValueError("--push requires the --commit flag if commit=False in the config file") cfg = cfg._replace(push=push) return cfg diff --git a/test/test_cli.py b/test/test_cli.py index b06972a..7c8ffeb 100644 --- a/test/test_cli.py +++ b/test/test_cli.py @@ -691,18 +691,16 @@ def test_incorrect_vcs_option_tag_push(runner, caplog): result = runner.invoke(cli.cli, ['update', "-vv", "--tag-commit"]) assert result.exit_code == 1 assert len(caplog.records) == 1 - assert ( - "Invalid argument: --tag-commit requires the --commit flag if commit=False in the config file" - in caplog.records[0].message + expected = ( + "Invalid argument: --tag-commit requires either --commit or commit=True in your config" ) + assert expected in caplog.records[0].message result = runner.invoke(cli.cli, ['update', "-vv", "--push"]) assert result.exit_code == 1 assert len(caplog.records) == 2 - assert ( - "Invalid argument: --push requires the --commit flag if commit=False in the config file" - in caplog.records[1].message - ) + expected = "Invalid argument: --push requires either --commit or commit=True in your config" + assert expected in caplog.records[1].message @pytest.mark.parametrize("version_pattern, cur_version, cur_pep440", DEFAULT_VERSION_PATTERNS)