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

Commit fc15df2

Browse files
adam-grant-hendryLee-W
authored andcommitted
test(commit): use double-quotes
On Windows, `Popen` with `shell=True` reads the `COMSPEC` environment variable to determine the shell to run, which defaults to Command Prompt (see https://docs.python.org/3/library/subprocess.html#subprocess.run). For backwards-compatibility for older OS utility scripts, `COMSPEC` should not be changed on Windows. Command Prompt requires double-quotes instead of single-quotes. See - https://stackoverflow.com/questions/25534995/escape-double-quotes-in-git-config-from-cmd) - https://docs.python.org/3/library/subprocess.html#converting-an-argument-sequence-to-a-string-on-windows Note that although the commitizen shell `scripts` shebangs have been changed to a portable variety (i.e. `#!/usr/bin/env sh`), which runs Git Bash on Windows when Git is installed (i.e. the `sh.exe` executable that ships with Git for Windows), `subprocess.Popen()` opens a child process from the active running shell (i.e. via `CreateProcess()`). Hence, it will still read `COMSPEC` and run a Command Prompt shell.
1 parent ecbc53e commit fc15df2

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

tests/test_bump_create_commit_message.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
import sys
23
from pathlib import Path
34
from textwrap import dedent
@@ -55,7 +56,10 @@ def test_bump_pre_commit_changelog(tmp_commitizen_project, mocker, freezer, retr
5556
"""
5657
)
5758
cmd.run("git add -A")
58-
cmd.run("git commit -m 'fix: _test'")
59+
if os.name == "nt":
60+
cmd.run('git commit -m "fix: _test"')
61+
else:
62+
cmd.run("git commit -m 'fix: _test'")
5963
cmd.run("pre-commit install")
6064
cli.main()
6165
# Pre-commit fixed last line adding extra indent and "\" char
@@ -93,7 +97,10 @@ def test_bump_pre_commit_changelog_fails_always(
9397
"""
9498
)
9599
cmd.run("git add -A")
96-
cmd.run("git commit -m 'feat: forbid changelogs'")
100+
if os.name == "nt":
101+
cmd.run('git commit -m "feat: forbid changelogs"')
102+
else:
103+
cmd.run("git commit -m 'feat: forbid changelogs'")
97104
cmd.run("pre-commit install")
98105
with pytest.raises(exceptions.BumpCommitFailedError):
99106
cli.main()

tests/test_git.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,10 @@ def test_is_staging_clean_when_updating_file(tmp_commitizen_project):
206206

207207
cmd.run("touch test_file")
208208
cmd.run("git add test_file")
209-
cmd.run("git commit -m 'add test_file'")
209+
if os.name == "nt":
210+
cmd.run('git commit -m "add test_file"')
211+
else:
212+
cmd.run("git commit -m 'add test_file'")
210213
cmd.run("echo 'test' > test_file")
211214

212215
assert git.is_staging_clean() is True

0 commit comments

Comments
 (0)