Skip to content

Commit 58c9c5a

Browse files
committed
fix(git): handle the empty commit and empty email cases
1 parent 3ef5257 commit 58c9c5a

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

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: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,33 @@ 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

0 commit comments

Comments
 (0)