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 3519ae7

Browse files
ttw225Lee-W
authored andcommitted
fix(commitizen/git.py,-tests/test_git.py): Resolve tempfile path spaces issue in git commit function
This test verifies parameter passing using markers to ensure that function arguments are correctly handled and propagated. #572
1 parent 223532b commit 3519ae7

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

‎commitizen/git.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def commit(
112112
f.write(message.encode("utf-8"))
113113
f.close()
114114

115-
command = f"git commit {args} -F {f.name}"
115+
command = f'git commit {args} -F "{f.name}"'
116116

117117
if committer_date and os.name == "nt": # pragma: no cover
118118
# Using `cmd /v /c "{command}"` sets environment variables only for that command

‎tests/test_git.py‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,3 +293,32 @@ def test_create_tag_with_message(tmp_commitizen_project):
293293
assert git.get_tag_message(tag_name) == (
294294
tag_message if platform.system() != "Windows" else f"'{tag_message}'"
295295
)
296+
297+
298+
@pytest.mark.parametrize(
299+
"file_path,expected_cmd",
300+
[
301+
(
302+
"/tmp/temp file",
303+
'git commit --signoff -F "/tmp/temp file"',
304+
), # File contains spaces
305+
(
306+
"/tmp dir/temp file",
307+
'git commit --signoff -F "/tmp dir/temp file"',
308+
), # Path contains spaces
309+
(
310+
"/tmp/tempfile",
311+
'git commit --signoff -F "/tmp/tempfile"',
312+
), # Path does not contain spaces
313+
],
314+
)
315+
def test_commit_with_spaces_in_path(mocker, file_path, expected_cmd):
316+
mock_run = mocker.patch("commitizen.cmd.run", return_value=FakeCommand())
317+
mock_unlink = mocker.patch("os.unlink")
318+
mock_temp_file = mocker.patch("commitizen.git.NamedTemporaryFile")
319+
mock_temp_file.return_value.name = file_path
320+
321+
git.commit("feat: new feature", "--signoff")
322+
323+
mock_run.assert_called_once_with(expected_cmd)
324+
mock_unlink.assert_called_once_with(file_path)

0 commit comments

Comments
(0)

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