Skip to content

Commit e36d432

Browse files
committed
fix(commands/commit): check cz commit msg
1 parent 967131f commit e36d432

File tree

7 files changed

+36
-23
lines changed

7 files changed

+36
-23
lines changed

commitizen/commands/commit.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import contextlib
22
import os
33
import tempfile
4+
from os.path import exists
45

56
import questionary
67

@@ -61,11 +62,24 @@ def prompt_commit_questions(self) -> str:
6162
raise NoAnswersError()
6263
return cz.message(answers)
6364

65+
def is_blank_commit_file(self, filename) -> bool:
66+
if not exists(filename):
67+
return True
68+
with open(filename, "tr") as f:
69+
for x in f:
70+
if len(x) == 0 or x[0] == "#":
71+
continue
72+
elif x[0] != "\r" and x[0] != "\n":
73+
return False
74+
return True
75+
6476
def __call__(self):
6577
dry_run: bool = self.arguments.get("dry_run")
6678

6779
commit_msg_file: str = self.arguments.get("commit_msg_file")
6880
if commit_msg_file:
81+
if not self.is_blank_commit_file(commit_msg_file):
82+
return
6983
wrap_stdio()
7084

7185
if git.is_staging_clean() and not dry_run:

commitizen/wrap_stdio.py

Lines changed: 0 additions & 16 deletions
This file was deleted.

commitizen/wrap_stdio/__init__.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import sys
2+
3+
if sys.platform == "win32": # pragma: no cover
4+
from .windows import _unwrap_stdio, _wrap_stdio
5+
elif sys.platform == "linux":
6+
from .linux import _unwrap_stdio, _wrap_stdio # pragma: no cover
7+
else:
8+
from .unix import _unwrap_stdio, _wrap_stdio # pragma: no cover
9+
10+
11+
def wrap_stdio():
12+
_wrap_stdio()
13+
14+
15+
def unwrap_stdio():
16+
_unwrap_stdio()
File renamed without changes.
File renamed without changes.
File renamed without changes.

tests/test_wrap_stdio.py renamed to tests/wrap_stdio/test_wrap_stdio.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
import sys
22

3-
from commitizen import wrap_stdio, wrap_stdio_linux, wrap_stdio_unix, wrap_stdio_windows
3+
from commitizen import wrap_stdio
44

5-
6-
def test_warp_stdio_exists():
7-
assert hasattr(wrap_stdio_windows, "sys")
8-
assert hasattr(wrap_stdio_linux, "sys")
9-
assert hasattr(wrap_stdio_unix, "sys")
5+
# def test_warp_stdio_exists():
6+
# assert hasattr(wrap_stdio_windows, "sys")
7+
# assert hasattr(wrap_stdio_linux, "sys")
8+
# assert hasattr(wrap_stdio_unix, "sys")
109

1110

1211
if sys.platform == "win32": # pragma: no cover
1312
pass
1413
elif sys.platform == "linux":
15-
from commitizen.wrap_stdio_linux import WrapStdinLinux, WrapStdoutLinux
14+
from commitizen.wrap_stdio.linux import WrapStdinLinux, WrapStdoutLinux
1615

1716
def test_wrap_stdin_linux(mocker):
1817

0 commit comments

Comments
 (0)