From 3519ae7d300fcb3095b9064272f025255adf4c2b Mon Sep 17 00:00:00 2001 From: TTW Date: Sat, 30 Mar 2024 15:50:22 +0800 Subject: [PATCH 1/3] 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 --- commitizen/git.py | 2 +- tests/test_git.py | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/commitizen/git.py b/commitizen/git.py index 900ca9298e..53e7335a3f 100644 --- a/commitizen/git.py +++ b/commitizen/git.py @@ -112,7 +112,7 @@ def commit( f.write(message.encode("utf-8")) f.close() - command = f"git commit {args} -F {f.name}" + command = f'git commit {args} -F "{f.name}"' if committer_date and os.name == "nt": # pragma: no cover # Using `cmd /v /c "{command}"` sets environment variables only for that command diff --git a/tests/test_git.py b/tests/test_git.py index 3b7a08f94a..60001d2e9b 100644 --- a/tests/test_git.py +++ b/tests/test_git.py @@ -293,3 +293,32 @@ def test_create_tag_with_message(tmp_commitizen_project): assert git.get_tag_message(tag_name) == ( tag_message if platform.system() != "Windows" else f"'{tag_message}'" ) + + +@pytest.mark.parametrize( + "file_path,expected_cmd", + [ + ( + "/tmp/temp file", + 'git commit --signoff -F "/tmp/temp file"', + ), # File contains spaces + ( + "/tmp dir/temp file", + 'git commit --signoff -F "/tmp dir/temp file"', + ), # Path contains spaces + ( + "/tmp/tempfile", + 'git commit --signoff -F "/tmp/tempfile"', + ), # Path does not contain spaces + ], +) +def test_commit_with_spaces_in_path(mocker, file_path, expected_cmd): + mock_run = mocker.patch("commitizen.cmd.run", return_value=FakeCommand()) + mock_unlink = mocker.patch("os.unlink") + mock_temp_file = mocker.patch("commitizen.git.NamedTemporaryFile") + mock_temp_file.return_value.name = file_path + + git.commit("feat: new feature", "--signoff") + + mock_run.assert_called_once_with(expected_cmd) + mock_unlink.assert_called_once_with(file_path) From 6148bf1d98d40d9ff344b5fc1095f721c646527c Mon Sep 17 00:00:00 2001 From: TTW Date: Sat, 30 Mar 2024 16:22:08 +0800 Subject: [PATCH 2/3] test(tests/test_git.py): use the IDs tool to clearly describe each test item --- tests/test_git.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/tests/test_git.py b/tests/test_git.py index 60001d2e9b..8af332d214 100644 --- a/tests/test_git.py +++ b/tests/test_git.py @@ -301,15 +301,20 @@ def test_create_tag_with_message(tmp_commitizen_project): ( "/tmp/temp file", 'git commit --signoff -F "/tmp/temp file"', - ), # File contains spaces + ), ( "/tmp dir/temp file", 'git commit --signoff -F "/tmp dir/temp file"', - ), # Path contains spaces + ), ( "/tmp/tempfile", 'git commit --signoff -F "/tmp/tempfile"', - ), # Path does not contain spaces + ), + ], + ids=[ + "File contains spaces", + "Path contains spaces", + "Path does not contain spaces", ], ) def test_commit_with_spaces_in_path(mocker, file_path, expected_cmd): From 8d5f6303e7501317ea3e4a3569fa7111411a5ad5 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Sat, 30 Mar 2024 08:31:53 +0000 Subject: [PATCH 3/3] =?UTF-8?q?bump:=20version=203.21.1=20=E2=86=92=203.21?= =?UTF-8?q?.2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .pre-commit-config.yaml | 2 +- CHANGELOG.md | 6 ++++++ commitizen/__version__.py | 2 +- pyproject.toml | 4 ++-- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 63c283e1c1..a07b16ca20 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -46,7 +46,7 @@ repos: exclude: "poetry.lock" - repo: https://github.com/commitizen-tools/commitizen - rev: v3.21.1 # automatically updated by Commitizen + rev: v3.21.2 # automatically updated by Commitizen hooks: - id: commitizen - id: commitizen-branch diff --git a/CHANGELOG.md b/CHANGELOG.md index ca27f0a2ee..82e455c569 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## v3.21.2 (2024-03-30) + +### Fix + +- **commitizen/git.py,-tests/test_git.py**: Resolve tempfile path spaces issue in git commit function + ## v3.21.1 (2024-03-30) ### Fix diff --git a/commitizen/__version__.py b/commitizen/__version__.py index ea92c23757..6a2d1c0215 100644 --- a/commitizen/__version__.py +++ b/commitizen/__version__.py @@ -1 +1 @@ -__version__ = "3.21.1" +__version__ = "3.21.2" diff --git a/pyproject.toml b/pyproject.toml index 4697401b98..d250e274af 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [tool.commitizen] -version = "3.21.1" +version = "3.21.2" tag_format = "v$version" version_files = [ "pyproject.toml:version", @@ -9,7 +9,7 @@ version_files = [ [tool.poetry] name = "commitizen" -version = "3.21.1" +version = "3.21.2" description = "Python commitizen client tool" authors = ["Santiago Fraire "] license = "MIT"