Skip to content

Commit

Permalink
Merge pull request #203 from callowayproject/202-calledprocesserror-g…
Browse files Browse the repository at this point in the history
…it-commit-f-tmp

Improve error reporting for git errors
  • Loading branch information
coordt authored Jun 25, 2024
2 parents ce31778 + cb050a8 commit 5506ace
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
3 changes: 2 additions & 1 deletion bumpversion/scm.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ def commit(cls, message: str, current_version: str, new_version: str, extra_args
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}"
output = "\n".join([x for x in [exc.stdout, exc.stderr] if x])
err_msg = f"Failed to run {exc.cmd}: return code {exc.returncode}, output: {output}"
logger.exception(err_msg)
raise BumpVersionError(err_msg) from exc
finally:
Expand Down
32 changes: 31 additions & 1 deletion tests/test_bump.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
"""Tests for the bump module."""

from pathlib import Path
import shutil
from textwrap import dedent
from unittest.mock import MagicMock, patch

import pytest

from bumpversion import bump
from bumpversion.exceptions import ConfigurationError
from bumpversion.exceptions import ConfigurationError, VersionNotFoundError
from bumpversion.files import ConfiguredFile
from bumpversion.scm import Git, SCMInfo
from tests.conftest import get_config_data, inside_dir
Expand Down Expand Up @@ -125,6 +126,35 @@ def test_passing_new_version_sets_version(self, mock_update_config_file, mock_mo
assert mock_update_config_file.call_args[0][3] == version_config.parse(new_version)
assert mock_update_config_file.call_args[0][5] is dry_run

@patch("bumpversion.bump.commit_and_tag")
@patch("bumpversion.bump.update_config_file")
def test_doesnt_commit_if_modify_error(
self, mock_update_config_file, mock_commit_and_tag, tmp_path: Path, fixtures_path: Path
):
from bumpversion import config

# Arrange
setup_py_path = tmp_path / "setup.py"
setup_py_path.touch()
init_path = tmp_path / "bumpversion/__init__.py"
init_path.parent.mkdir(parents=True)
init_path.touch()
orig_config_path = fixtures_path / "basic_cfg.toml"
dest_config_path = tmp_path / "pyproject.toml"
shutil.copyfile(orig_config_path, dest_config_path)
version_part = "patch"

# Act
with inside_dir(tmp_path):
config = config.get_configuration(config_file=dest_config_path)
with pytest.raises(VersionNotFoundError):
bump.do_bump(version_part, None, config)

# Assert
mock_commit_and_tag.assert_not_called()

mock_update_config_file.assert_not_called()

@patch("bumpversion.files.modify_files")
@patch("bumpversion.bump.update_config_file")
def test_when_new_equals_current_nothing_happens(self, mock_update_config_file, mock_modify_files, tmp_path: Path):
Expand Down

0 comments on commit 5506ace

Please sign in to comment.