Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions commitizen/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ def from_rev_and_commit(cls, rev_and_commit: str) -> GitCommit:
>>> commit.parents
['def456', 'ghi789']
"""
rev, parents, title, author, author_email, *body_list = rev_and_commit.split(
"\n"
rev, parents, title, author, author_email, *body_list = (
rev_and_commit.splitlines()
)
Comment thread
MattBelle marked this conversation as resolved.
return cls(
rev=rev.strip(),
Expand Down
13 changes: 8 additions & 5 deletions tests/test_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,18 +395,21 @@ def test_get_filenames_in_commit_error(util: UtilFixture):
assert str(excinfo.value) == "fatal: bad object HEAD"


def test_git_commit_from_rev_and_commit():
@pytest.mark.parametrize(
"body_newline", ["\n", "\r\n"], ids=["line_feed", "carriage_return"]
)
def test_git_commit_from_rev_and_commit(body_newline):
# Test data with all fields populated
body = body_newline.join(
["This is a detailed description", "of the new feature", "with multiple lines"]
)
rev_and_commit = (
"abc123\n" # rev
"def456 ghi789\n" # parents
"feat: add new feature\n" # title
"John Doe\n" # author
"john@example.com\n" # author_email
Comment thread
MattBelle marked this conversation as resolved.
Outdated
"This is a detailed description\n" # body
"of the new feature\n"
"with multiple lines"
)
) + body

commit = git.GitCommit.from_rev_and_commit(rev_and_commit)

Expand Down