From 26859f306fc54f8cc05028412f9e0a3d50b82cff Mon Sep 17 00:00:00 2001 From: Noah Kantrowitz Date: Wed, 21 Oct 2020 21:34:28 -0700 Subject: [PATCH 1/2] Allow not updating the config file, even when it exists. --- bumpversion/cli.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/bumpversion/cli.py b/bumpversion/cli.py index b107e10d..00d56739 100644 --- a/bumpversion/cli.py +++ b/bumpversion/cli.py @@ -127,7 +127,7 @@ def main(original_args=None): # store the new version _update_config_file( - config, config_file, config_newlines, config_file_exists, args.new_version, args.dry_run, + config, config_file, config_newlines, config_file_exists, args.new_version, args.dry_run, args.no_update_config, ) # commit and tag @@ -294,7 +294,7 @@ def _load_configuration(config_file, explicit_config, defaults): except NoOptionError: pass # no default value then ;) - for boolvaluename in ("commit", "tag", "dry_run"): + for boolvaluename in ("commit", "tag", "dry_run", "no_update_config"): try: defaults[boolvaluename] = config.getboolean( "bumpversion", boolvaluename @@ -411,6 +411,12 @@ def _parse_arguments_phase_2(args, known_args, defaults, root_parser): help="Template for complete string to replace", default=defaults.get("replace", "{new_version}"), ) + parser2.add_argument( + "--no-update-config", + action="store_true", + help="Do not update the config file with current_version", + default=defaults.get("no_update_config", False), + ) known_args, remaining_argv = parser2.parse_known_args(args) defaults.update(vars(known_args)) @@ -632,12 +638,12 @@ def _log_list(config, new_version): def _update_config_file( - config, config_file, config_newlines, config_file_exists, new_version, dry_run, + config, config_file, config_newlines, config_file_exists, new_version, dry_run, no_update_config, ): config.set("bumpversion", "current_version", new_version) new_config = io.StringIO() try: - write_to_config_file = (not dry_run) and config_file_exists + write_to_config_file = (not dry_run) and (not no_update_config) and config_file_exists logger.info( "%s to config file %s:", From ec9d42d0fa5fecc42f291fb2d6d172c100c06a44 Mon Sep 17 00:00:00 2001 From: Noah Kantrowitz Date: Wed, 21 Oct 2020 21:56:52 -0700 Subject: [PATCH 2/2] Update test banner. --- tests/test_cli.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/test_cli.py b/tests/test_cli.py index 748d4860..30ffe950 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -144,6 +144,8 @@ def _mock_calls_to_string(called_mock): {current_version}) --replace REPLACE Template for complete string to replace (default: {new_version}) + --no-update-config Do not update the config file with current_version + (default: False) --current-version VERSION Version that needs to be updated (default: None) --no-configured-files