Skip to content
Open
Show file tree
Hide file tree
Changes from all 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()
)
return cls(
rev=rev.strip(),
Expand Down
40 changes: 23 additions & 17 deletions tests/test_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,17 +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():
# Test data with all fields populated
rev_and_commit = (
"abc123\n" # rev
"def456 ghi789\n" # parents
"feat: add new feature\n" # title
"John Doe\n" # author
"[email protected]\n" # author_email
"This is a detailed description\n" # body
"of the new feature\n"
"with multiple lines"
@pytest.mark.parametrize(
"linebreak", ["\n", "\r\n"], ids=["line_feed", "carriage_return"]
)
def test_git_commit_from_rev_and_commit(linebreak):
rev_and_commit = linebreak.join(
[
"abc123", # rev
"def456 ghi789", # parents
"feat: add new feature", # title
"John Doe", # author
"[email protected]", # author_email
"This is a detailed description", # body
"of the new feature",
"with multiple lines",
]
)

commit = git.GitCommit.from_rev_and_commit(rev_and_commit)
Expand All @@ -421,12 +425,14 @@ def test_git_commit_from_rev_and_commit():
assert commit.parents == ["def456", "ghi789"]

# Test with minimal data
minimal_commit = (
"abc123\n" # rev
"\n" # no parents
"feat: minimal commit\n" # title
"John Doe\n" # author
"[email protected]\n" # author_email
minimal_commit = linebreak.join(
[
"abc123", # rev
"", # no parents
"feat: minimal commit", # title
"John Doe", # author
"[email protected]", # author_email
]
)

commit = git.GitCommit.from_rev_and_commit(minimal_commit)
Expand Down