Skip to content

Commit

Permalink
fix incorrect empty message commit serialization
Browse files Browse the repository at this point in the history
* Fixes incorrect signature verification for commits with an empty message,
  as encoded by CGit (jelmer#1429)
  • Loading branch information
castedo committed Nov 16, 2024
1 parent d90e6a9 commit 6289902
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
2 changes: 1 addition & 1 deletion dulwich/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
25 changes: 24 additions & 1 deletion tests/compat/test_porcelain.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ def test_verify(self):
"commit",
"--allow-empty",
"-S" + PorcelainGpgTestCase.DEFAULT_KEY_ID,
"--allow-empty-message",
"-m",
"foo",
],
Expand All @@ -139,3 +138,27 @@ def test_verify(self):
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()
2 changes: 1 addition & 1 deletion tests/test_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -1066,7 +1066,7 @@ def test_serialize_none_message(self):
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(),
)
Expand Down

0 comments on commit 6289902

Please sign in to comment.