From 75d3938a4842b2aa667dcd902e376a5a01a797e5 Mon Sep 17 00:00:00 2001 From: Georgiy Ignatov Date: Wed, 22 Apr 2020 13:28:21 +0300 Subject: [PATCH 1/3] fix(git): fix returned value for GitCommit.message when body is empty GitCommit.message should return only title without excess newlines if commit body is empty. --- commitizen/git.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/commitizen/git.py b/commitizen/git.py index 058ba89a00..b8afa816dd 100644 --- a/commitizen/git.py +++ b/commitizen/git.py @@ -21,7 +21,10 @@ def __init__(self, rev, title, body=""): @property def message(self): - return f"{self.title}\n\n{self.body}" + message = self.title + if self.body: + message = message + f"\n\n{self.body}" + return message def __repr__(self): return f"{self.title} ({self.rev})" From bde1c4315a6a1ff2b565c94255fa20a4066dd5f4 Mon Sep 17 00:00:00 2001 From: Georgiy Ignatov Date: Wed, 22 Apr 2020 13:33:37 +0300 Subject: [PATCH 2/3] test(git): add test that checks GitCommit.message with empty body --- tests/test_git.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/test_git.py b/tests/test_git.py index ef7cb2cdc9..3a6638b329 100644 --- a/tests/test_git.py +++ b/tests/test_git.py @@ -47,3 +47,10 @@ def test_get_tag_names(mocker): "commitizen.cmd.run", return_value=FakeCommand(out="", err="No tag available") ) assert git.get_tag_names() == [] + + +def test_git_message_with_empty_body(): + commit_title = "Some Title" + commit = git.GitCommit("test_rev", "Some Title", body="") + + assert commit.message == commit_title From f21693efb5809138d4b027d3d1bde0800899976c Mon Sep 17 00:00:00 2001 From: Georgiy Ignatov Date: Wed, 22 Apr 2020 14:12:57 +0300 Subject: [PATCH 3/3] refactor(git): replace GitCommit.message code with one-liner --- commitizen/git.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/commitizen/git.py b/commitizen/git.py index b8afa816dd..a2531a87e4 100644 --- a/commitizen/git.py +++ b/commitizen/git.py @@ -21,10 +21,7 @@ def __init__(self, rev, title, body=""): @property def message(self): - message = self.title - if self.body: - message = message + f"\n\n{self.body}" - return message + return f"{self.title}\n\n{self.body}".strip() def __repr__(self): return f"{self.title} ({self.rev})"