Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 3ce4ed8

Browse files
skoefLee-W
authored andcommitted
fix(bump): fixed environment variables in bump hooks
During development of #644, merging the hook environment variables with existing OS variables broke.
1 parent 1ff575d commit 3ce4ed8

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

commitizen/hooks.py

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

3+
import os
4+
35
from commitizen import cmd, out
46
from commitizen.exceptions import RunHookError
57

@@ -25,7 +27,7 @@ def run(hooks, _env_prefix="CZ_", **env):
2527
def _format_env(prefix: str, env: dict[str, str]) -> dict[str, str]:
2628
"""_format_env() prefixes all given environment variables with the given
2729
prefix so it can be passed directly to cmd.run()."""
28-
penv = dict()
30+
penv = dict(os.environ)
2931
for name, value in env.items():
3032
name = prefix + name.upper()
3133
value = str(value) if value is not None else ""

tests/test_bump_hooks.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
from unittest.mock import call
23

34
import pytest
@@ -17,7 +18,10 @@ def test_run(mocker: MockFixture):
1718
hooks.run(bump_hooks)
1819

1920
cmd_run_mock.assert_has_calls(
20-
[call("pre_bump_hook", env={}), call("pre_bump_hook_1", env={})]
21+
[
22+
call("pre_bump_hook", env=dict(os.environ)),
23+
call("pre_bump_hook_1", env=dict(os.environ)),
24+
]
2125
)
2226

2327

0 commit comments

Comments
 (0)