diff --git a/commitizen/git.py b/commitizen/git.py index e598ff065..dc2603898 100644 --- a/commitizen/git.py +++ b/commitizen/git.py @@ -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(), diff --git a/tests/test_git.py b/tests/test_git.py index 3fb25a8e6..933399781 100644 --- a/tests/test_git.py +++ b/tests/test_git.py @@ -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 - "john@example.com\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 + "john@example.com", # 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) @@ -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 - "john@example.com\n" # author_email + minimal_commit = linebreak.join( + [ + "abc123", # rev + "", # no parents + "feat: minimal commit", # title + "John Doe", # author + "john@example.com", # author_email + ] ) commit = git.GitCommit.from_rev_and_commit(minimal_commit)