Skip to content

Commit

Permalink
Fixed bad error checking with SCM
Browse files Browse the repository at this point in the history
  • Loading branch information
coordt committed Jan 25, 2024
1 parent 6b9ea0b commit 10e5d7d
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions bumpversion/scm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down Expand Up @@ -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 = ""

Check warning on line 59 in bumpversion/scm.py

View check run for this annotation

Codecov / codecov/patch

bumpversion/scm.py#L58-L59

Added lines #L58 - L59 were not covered by tests
if not new_version:
logger.warning("No new version given, using an empty string.")
new_version = ""

Check warning on line 62 in bumpversion/scm.py

View check run for this annotation

Codecov / codecov/patch

bumpversion/scm.py#L61-L62

Added lines #L61 - L62 were not covered by tests

with NamedTemporaryFile("wb", delete=False) as f:
f.write(message.encode("utf-8"))
Expand All @@ -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)

Expand Down

0 comments on commit 10e5d7d

Please sign in to comment.