diff --git a/dulwich/objects.py b/dulwich/objects.py index 48d3712f9..03426eda1 100644 --- a/dulwich/objects.py +++ b/dulwich/objects.py @@ -728,8 +728,8 @@ def _format_message(headers, body): yield git_line(field, lines[0]) for line in lines[1:]: yield b" " + line + b"\n" + yield b"\n" # There must be a new line after the headers if body: - yield b"\n" # There must be a new line after the headers yield body diff --git a/tests/compat/test_porcelain.py b/tests/compat/test_porcelain.py index 1fb49ade4..f396c92c9 100644 --- a/tests/compat/test_porcelain.py +++ b/tests/compat/test_porcelain.py @@ -91,3 +91,74 @@ def test_verify(self): tag = self.repo[b"refs/tags/verifyme"] self.assertNotEqual(tag.signature, None) tag.verify() + + +@skipIf( + platform.python_implementation() == "PyPy" or sys.platform == "win32", + "gpgme not easily available or supported on Windows and PyPy", +) +class CommitCreateSignTestCase(PorcelainGpgTestCase, CompatTestCase): + def test_sign(self): + # Test that dulwich signatures can be verified by CGit + cfg = self.repo.get_config() + cfg.set(("user",), "signingKey", PorcelainGpgTestCase.DEFAULT_KEY_ID) + self.import_default_key() + + porcelain.commit( + self.repo.path, + b"messy message messiah", + b"foo ", + signoff=True, + ) + + run_git_or_fail( + [f"--git-dir={self.repo.controldir()}", "verify-commit", "-v", "HEAD"], + env={"GNUPGHOME": os.environ["GNUPGHOME"]}, + ) + + def test_verify(self): + # Test that CGit signatures can be verified by dulwich + self.import_default_key() + + run_git_or_fail( + [ + f"--git-dir={self.repo.controldir()}", + "commit", + "--allow-empty", + "-S" + PorcelainGpgTestCase.DEFAULT_KEY_ID, + "-m", + "foo", + ], + env={ + "GNUPGHOME": os.environ["GNUPGHOME"], + "GIT_COMMITTER_NAME": "Joe Example", + "GIT_COMMITTER_EMAIL": "joe@example.com", + }, + ) + commit = self.repo[b"HEAD"] + self.assertNotEqual(commit.gpgsig, None) + commit.verify() + + def test_verify_with_empty_message(self): + # Test that CGit signatures can be verified by dulwich + self.import_default_key() + + run_git_or_fail( + [ + f"--git-dir={self.repo.controldir()}", + "commit", + "--allow-empty", + "-S" + PorcelainGpgTestCase.DEFAULT_KEY_ID, + "--allow-empty-message", + "-m", + "", + ], + env={ + "GNUPGHOME": os.environ["GNUPGHOME"], + "GIT_COMMITTER_NAME": "Joe Example", + "GIT_COMMITTER_EMAIL": "joe@example.com", + }, + ) + commit = self.repo[b"HEAD"] + self.assertNotEqual(commit.gpgsig, None) + commit.verify() diff --git a/tests/test_objects.py b/tests/test_objects.py index 4be85dd3b..81f2190c7 100644 --- a/tests/test_objects.py +++ b/tests/test_objects.py @@ -1066,7 +1066,7 @@ def test_serialize_none_message(self): b"type blob\n" b"tag 0.1\n" b"tagger Jelmer Vernooij " - b"423423423 +0000\n" + b"423423423 +0000\n\n" ), x.as_raw_string(), )