Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

130 crash when supplying commit argument #133

Merged
merged 3 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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 @@
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
2 changes: 1 addition & 1 deletion bumpversion/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Loading