Skip to content

Commit c05a03f

Browse files
committed
fix(check): expand env vars in rev_range arg
1 parent 1d89cc5 commit c05a03f

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

commitizen/commands/check.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
import os
34
import re
45
import sys
56
from pathlib import Path
@@ -41,6 +42,8 @@ def __init__(self, config: BaseConfig, arguments: CheckArgs, *args: object) -> N
4142
self.commit_msg_file = arguments.get("commit_msg_file")
4243
self.commit_msg = arguments.get("message")
4344
self.rev_range = arguments.get("rev_range")
45+
if self.rev_range is not None:
46+
self.rev_range = os.path.expandvars(self.rev_range)
4447
self.allow_abort = bool(
4548
arguments.get("allow_abort", config.settings["allow_abort"])
4649
)

tests/commands/test_check_command.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
import os
34
from io import StringIO
45
from typing import TYPE_CHECKING, Any
56

@@ -448,3 +449,25 @@ def test_check_command_with_custom_validator_failed(
448449
util.run_cli(
449450
"--name", "cz_custom_validator", "check", "--commit-msg-file", "some_file"
450451
)
452+
453+
454+
@pytest.mark.parametrize(
455+
("rev_range", "expected"),
456+
[
457+
("HEAD~5..HEAD", "HEAD~5..HEAD"),
458+
("$PRE_COMMIT_FROM_REF..$PRE_COMMIT_TO_REF", "v1.0.0..v1.1.0"),
459+
("${PRE_COMMIT_FROM_REF}..${PRE_COMMIT_TO_REF}", "v1.0.0..v1.1.0"),
460+
],
461+
)
462+
def test_check_command_expands_env_vars_in_rev_range(
463+
config, mocker: MockFixture, rev_range: str, expected: str
464+
):
465+
git_get_commits = mocker.patch(
466+
"commitizen.git.get_commits", return_value=_build_fake_git_commits(COMMIT_LOG)
467+
)
468+
mocker.patch.dict(
469+
os.environ,
470+
{"PRE_COMMIT_FROM_REF": "v1.0.0", "PRE_COMMIT_TO_REF": "v1.1.0"},
471+
)
472+
commands.Check(config=config, arguments={"rev_range": rev_range})()
473+
git_get_commits.assert_called_once_with(None, expected)

0 commit comments

Comments
 (0)