10000 Merge pull request #341 from commitizen-tools/fix-git-message-parsing · fcurella/commitizen@b901bea · GitHub
[go: up one dir, main page]

Skip to content

Commit b901bea

Browse files
authored
Merge pull request commitizen-tools#341 from commitizen-tools/fix-git-message-parsing
Fix git message parsing
2 parents 3ef5257 + f01a03c commit b901bea

File tree

3 files changed

+40
-4
lines changed

3 files changed

+40
-4
lines changed

commitizen/commands/init.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ def _install_pre_commit_hook(self):
122122
# .pre-commit-config does not exist
123123
config_data["repos"] = [cz_hook_config]
124124
else:
125-
# breakpoint()
126125
with open(pre_commit_config_filename) as config_file:
127126
yaml_data = yaml.safe_load(config_file)
128127
if yaml_data:

commitizen/git.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,7 @@ def get_commits(
7979
return []
8080

8181
git_commits = []
82-
for rev_and_commit in c.out.split(delimiter):
83-
rev_and_commit = rev_and_commit.strip()
82+
for rev_and_commit in c.out.split(f"\n{delimiter}\n"):
8483
if not rev_and_commit:
8584
continue
8685
rev, title, author, author_email, *body_list = rev_and_commit.split("\n")

tests/test_git.py

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import pytest
55

6-
from commitizen import git
6+
from commitizen import cmd, git
77
from tests.utils import FakeCommand, create_file_and_commit
88

99

@@ -73,7 +73,45 @@ def test_get_commits_author_and_email():
7373
assert "@" in commit.author_email
7474

7575

76+
def test_get_commits_without_email(mocker):
77+
raw_commit = (
78+
"a515bb8f71c403f6f7d1c17b9d8ebf2ce3959395\n"
79+
"\n"
80+
"user name\n"
81+
"\n"
82+
"----------commit-delimiter----------\n"
83+
"12d3b4bdaa996ea7067a07660bb5df4772297bdd\n"
84+
"feat(users): add username\n"
85+
"user name\n"
86+
"\n"
87+
"----------commit-delimiter----------\n"
88+
)
89+
mocker.patch("commitizen.cmd.run", return_value=FakeCommand(out=raw_commit))
90+
91+
commits = git.get_commits()
92+
93+
assert commits[0].author == "user name"
94+
assert commits[1].author == "user name"
95+
96+
assert commits[0].author_email == ""
97+
assert commits[1].author_email == ""
98+
99+
assert commits[0].title == ""
100+
assert commits[1].title == "feat(users): add username"
101+
102+
76103
def test_get_tag_names_has_correct_arrow_annotation():
77104
arrow_annotation = inspect.getfullargspec(git.get_tag_names).annotations["return"]
78105

79106
assert arrow_annotation == List[Optional[str]]
107+
108+
109+
def test_get_latest_tag_name(tmp_commitizen_project):
110+
with tmp_commitizen_project.as_cwd():
111+
tag_name = git.get_latest_tag_name()
112+
assert tag_name is None
113+
114+
create_file_and_commit("feat(test): test")
115+
cmd.run("git tag 1.0")
116+
tag_name = git.get_latest_tag_name()
117+
assert tag_name == "1.0"

0 commit comments

Comments
 (0)
0