Skip to content

Commit 495ea3e

Browse files
author
Matt Belle
committed
fix(git): commit bodies with carriage returns are correctly split by line
This should enable us to correctly parse squashed commits made on an SCM server residing on a Windows OS.
1 parent 1d89195 commit 495ea3e

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

commitizen/git.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ def from_rev_and_commit(cls, rev_and_commit: str) -> GitCommit:
118118
>>> commit.parents
119119
['def456', 'ghi789']
120120
"""
121-
rev, parents, title, author, author_email, *body_list = rev_and_commit.split(
122-
"\n"
121+
rev, parents, title, author, author_email, *body_list = (
122+
rev_and_commit.splitlines()
123123
)
124124
return cls(
125125
rev=rev.strip(),

tests/test_git.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -395,18 +395,21 @@ def test_get_filenames_in_commit_error(util: UtilFixture):
395395
assert str(excinfo.value) == "fatal: bad object HEAD"
396396

397397

398-
def test_git_commit_from_rev_and_commit():
398+
@pytest.mark.parametrize(
399+
"body_newline", ["\n", "\r\n"], ids=["line_feed", "carriage_return"]
400+
)
401+
def test_git_commit_from_rev_and_commit(body_newline):
399402
# Test data with all fields populated
403+
body = body_newline.join(
404+
["This is a detailed description", "of the new feature", "with multiple lines"]
405+
)
400406
rev_and_commit = (
401407
"abc123\n" # rev
402408
"def456 ghi789\n" # parents
403409
"feat: add new feature\n" # title
404410
"John Doe\n" # author
405411
"john@example.com\n" # author_email
406-
"This is a detailed description\n" # body
407-
"of the new feature\n"
408-
"with multiple lines"
409-
)
412+
) + body
410413

411414
commit = git.GitCommit.from_rev_and_commit(rev_and_commit)
412415

0 commit comments

Comments
 (0)