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

Improve error reporting for git errors #203

Merged
merged 3 commits into from
Jun 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
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
Loading