Skip to content

Commit c04048c

Browse files
test(bump): cover _stage_updated_files error path
The git.add return-code check added in the previous reviewer-feedback commit was not exercised by tests. This adds a regression test that mocks git.add returning non-zero and asserts BumpCommitFailedError is raised with a useful message. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 53dd1cb commit c04048c

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

tests/commands/test_bump_command.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from commitizen import cmd, defaults, git, hooks
1414
from commitizen.config.base_config import BaseConfig
1515
from commitizen.exceptions import (
16+
BumpCommitFailedError,
1617
BumpTagFailedError,
1718
CommitizenException,
1819
CurrentVersionNotFoundError,
@@ -1409,6 +1410,42 @@ def test_bump_skips_commit_when_no_files_changed(
14091410
add_mock.assert_not_called()
14101411

14111412

1413+
def test_bump_raises_when_git_add_fails(
1414+
mocker: MockFixture, tmp_commitizen_project: Path, util: UtilFixture
1415+
):
1416+
"""Regression test: ``cz bump`` reports a failing ``git.add``."""
1417+
project_root = tmp_commitizen_project
1418+
tmp_commitizen_cfg_file = project_root / "pyproject.toml"
1419+
tmp_commitizen_cfg_file.write_text(
1420+
"\n".join(
1421+
[
1422+
"[tool.commitizen]",
1423+
'version = "0.1.0"',
1424+
'tag_format = "v$version"',
1425+
'version_files = ["pyproject.toml:version"]',
1426+
]
1427+
),
1428+
)
1429+
util.create_file_and_commit("feat: first feature")
1430+
1431+
mocker.patch(
1432+
"commitizen.git.add",
1433+
return_value=cmd.Command(
1434+
out="",
1435+
err="fatal: pathspec did not match any files",
1436+
stdout=b"",
1437+
stderr=b"fatal: pathspec did not match any files",
1438+
return_code=128,
1439+
),
1440+
)
1441+
1442+
with pytest.raises(BumpCommitFailedError) as exc_info:
1443+
util.run_cli("bump", "--yes")
1444+
1445+
assert "git.add error" in str(exc_info.value)
1446+
assert "fatal: pathspec" in str(exc_info.value)
1447+
1448+
14121449
def test_is_initial_tag(mocker: MockFixture, tmp_commitizen_project, util: UtilFixture):
14131450
"""Test the _is_initial_tag method behavior."""
14141451
# Create a commit but no tags

0 commit comments

Comments
 (0)