From a5dca4c210260c6dd395ef034db442d58b0342b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rados=C5=82aw=20Gryta?= Date: Thu, 25 Jan 2024 14:21:26 +0100 Subject: [PATCH 1/2] Fix missing current version within the context --- bumpversion/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bumpversion/utils.py b/bumpversion/utils.py index c6d30cc5..be3e32d0 100644 --- a/bumpversion/utils.py +++ b/bumpversion/utils.py @@ -75,7 +75,7 @@ def get_context( ) -> ChainMap: """Return the context for rendering messages and tags.""" ctx = base_context(config.scm_info) - ctx.new_child({"current_version": config.current_version}) + ctx = ctx.new_child({"current_version": config.current_version}) if current_version: ctx = ctx.new_child({f"current_{part}": current_version[part].value for part in current_version}) if new_version: From 10e5d7dceea97b1c26868d35978353f7d7595fd5 Mon Sep 17 00:00:00 2001 From: Corey Oordt Date: Thu, 25 Jan 2024 08:16:19 -0600 Subject: [PATCH 2/2] Fixed bad error checking with SCM --- bumpversion/scm.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/bumpversion/scm.py b/bumpversion/scm.py index fa4496df..f518e3e4 100644 --- a/bumpversion/scm.py +++ b/bumpversion/scm.py @@ -14,7 +14,7 @@ if TYPE_CHECKING: # pragma: no-coverage from bumpversion.config import Config -from bumpversion.exceptions import DirtyWorkingDirectoryError, SignedTagsError +from bumpversion.exceptions import BumpVersionError, DirtyWorkingDirectoryError, SignedTagsError logger = get_indented_logger(__name__) @@ -54,6 +54,12 @@ class SourceCodeManager: def commit(cls, message: str, current_version: str, new_version: str, extra_args: Optional[list] = None) -> None: """Commit the changes.""" extra_args = extra_args or [] + if not current_version: + logger.warning("No current version given, using an empty string.") + current_version = "" + if not new_version: + logger.warning("No new version given, using an empty string.") + new_version = "" with NamedTemporaryFile("wb", delete=False) as f: f.write(message.encode("utf-8")) @@ -66,10 +72,13 @@ def commit(cls, message: str, current_version: str, new_version: str, extra_args try: cmd = [*cls._COMMIT_COMMAND, f.name, *extra_args] subprocess.run(cmd, env=env, capture_output=True, check=True) # noqa: S603 - except subprocess.CalledProcessError as exc: # pragma: no-coverage - err_msg = f"Failed to run {exc.cmd}: return code {exc.returncode}, output: {exc.output}" + except (subprocess.CalledProcessError, TypeError) as exc: # pragma: no-coverage + if isinstance(exc, TypeError): + err_msg = f"Failed to run {cls._COMMIT_COMMAND}: {exc}" + else: + err_msg = f"Failed to run {exc.cmd}: return code {exc.returncode}, output: {exc.output}" logger.exception(err_msg) - raise exc + raise BumpVersionError(err_msg) from exc finally: os.unlink(f.name)