Skip to content

Commit e4a21be

Browse files
committed
refactor(cmd): add return code to Command
1 parent e37e3e6 commit e4a21be

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

commitizen/cmd.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ class Command(NamedTuple):
77
err: str
88
stdout: bytes
99
stderr: bytes
10+
return_code: int
1011

1112

1213
def run(cmd: str) -> Command:
@@ -18,4 +19,5 @@ def run(cmd: str) -> Command:
1819
stdin=subprocess.PIPE,
1920
)
2021
stdout, stderr = process.communicate()
21-
return Command(stdout.decode(), stderr.decode(), stdout, stderr)
22+
return_code = process.returncode
23+
return Command(stdout.decode(), stderr.decode(), stdout, stderr, return_code)

tests/commands/test_commit_command.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def test_commit(config, mocker):
3434
}
3535

3636
commit_mock = mocker.patch("commitizen.git.commit")
37-
commit_mock.return_value = cmd.Command("success", "", "", "")
37+
commit_mock.return_value = cmd.Command("success", "", "", "", 0)
3838
success_mock = mocker.patch("commitizen.out.success")
3939

4040
commands.Commit(config, {})()
@@ -44,7 +44,7 @@ def test_commit(config, mocker):
4444
@pytest.mark.usefixtures("staging_is_clean")
4545
def test_commit_retry_fails_no_backup(config, mocker):
4646
commit_mock = mocker.patch("commitizen.git.commit")
47-
commit_mock.return_value = cmd.Command("success", "", "", "")
47+
commit_mock.return_value = cmd.Command("success", "", "", "", 0)
4848

4949
with pytest.raises(NoCommitBackupError) as excinfo:
5050
commands.Commit(config, {"retry": True})()
@@ -65,7 +65,7 @@ def test_commit_retry_works(config, mocker):
6565
}
6666

6767
commit_mock = mocker.patch("commitizen.git.commit")
68-
commit_mock.return_value = cmd.Command("", "error", "", "")
68+
commit_mock.return_value = cmd.Command("", "error", "", "", 0)
6969
error_mock = mocker.patch("commitizen.out.error")
7070

7171
with pytest.raises(CommitError):
@@ -79,7 +79,7 @@ def test_commit_retry_works(config, mocker):
7979

8080
# Previous commit failed, so retry should pick up the backup commit
8181
# commit_mock = mocker.patch("commitizen.git.commit")
82-
commit_mock.return_value = cmd.Command("success", "", "", "")
82+
commit_mock.return_value = cmd.Command("success", "", "", "", 0)
8383
success_mock = mocker.patch("commitizen.out.success")
8484

8585
commands.Commit(config, {"retry": True})()

0 commit comments

Comments
 (0)