Ver código fonte

fix incorrect empty message commit serialization

* Fixes incorrect signature verification for commits with an empty message,
  as encoded by CGit (https://github.com/jelmer/dulwich/issues/1429)
Castedo Ellerman 4 meses atrás
pai
commit
6289902bbc
3 arquivos alterados com 26 adições e 3 exclusões
  1. 1 1
      dulwich/objects.py
  2. 24 1
      tests/compat/test_porcelain.py
  3. 1 1
      tests/test_objects.py

+ 1 - 1
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
 
 

+ 24 - 1
tests/compat/test_porcelain.py

@@ -126,7 +126,6 @@ class CommitCreateSignTestCase(PorcelainGpgTestCase, CompatTestCase):
                 "commit",
                 "--allow-empty",
                 "-S" + PorcelainGpgTestCase.DEFAULT_KEY_ID,
-                "--allow-empty-message",
                 "-m",
                 "foo",
             ],
@@ -139,3 +138,27 @@ class CommitCreateSignTestCase(PorcelainGpgTestCase, CompatTestCase):
         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()

+ 1 - 1
tests/test_objects.py

@@ -1066,7 +1066,7 @@ class TagSerializeTests(TestCase):
                 b"type blob\n"
                 b"tag 0.1\n"
                 b"tagger Jelmer Vernooij <jelmer@samba.org> "
-                b"423423423 +0000\n"
+                b"423423423 +0000\n\n"
             ),
             x.as_raw_string(),
         )