Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 6654ef1

Browse files
fix(git): force the default git locale on methods relying on parsing the output (#1012)
1 parent 0e93206 commit 6654ef1

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

‎commitizen/cmd.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
import subprocess
23
from typing import NamedTuple
34

@@ -28,6 +29,8 @@ def _try_decode(bytes_: bytes) -> str:
2829

2930

3031
def run(cmd: str, env=None) -> Command:
32+
if env is not None:
33+
env = {**os.environ, **env}
3134
process = subprocess.Popen(
3235
cmd,
3336
shell=True,

‎commitizen/git.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,9 @@ def get_tags(
175175
f'%(object)"'
176176
)
177177
extra = "--merged" if reachable_only else ""
178-
c = cmd.run(f"git tag --format={formatter} --sort=-creatordate {extra}")
178+
# Force the default language for parsing
179+
env = {"LC_ALL": "C", "LANG": "C", "LANGUAGE": "C"}
180+
c = cmd.run(f"git tag --format={formatter} --sort=-creatordate {extra}", env=env)
179181
if c.return_code != 0:
180182
if reachable_only and c.err == "fatal: malformed object name HEAD\n":
181183
# this can happen if there are no commits in the repo yet

‎tests/test_git.py‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,18 @@ def test_get_reachable_tags(tmp_commitizen_project):
7171
assert tag_names == {"1.0.0", "1.0.1"}
7272

7373

74+
@pytest.mark.parametrize("locale", ["en_US", "fr_FR"])
75+
def test_get_reachable_tags_with_commits(
76+
tmp_commitizen_project, locale: str, monkeypatch: pytest.MonkeyPatch
77+
):
78+
monkeypatch.setenv("LANG", f"{locale}.UTF-8")
79+
monkeypatch.setenv("LANGUAGE", f"{locale}.UTF-8")
80+
monkeypatch.setenv("LC_ALL", f"{locale}.UTF-8")
81+
with tmp_commitizen_project.as_cwd():
82+
tags = git.get_tags(reachable_only=True)
83+
assert tags == []
84+
85+
7486
def test_get_tag_names(mocker: MockFixture):
7587
tag_str = "v1.0.0\n" "v0.5.0\n" "v0.0.1\n"
7688
mocker.patch("commitizen.cmd.run", return_value=FakeCommand(out=tag_str))

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /