Skip to content

Conversation

@baloo
Copy link
Contributor

@baloo baloo commented Aug 15, 2025

This adds support for extra headers. While git has a set of "standard headers" (tree, parent, author, committer, and encoding), it will also support extra headers when serializing.

The extra headers must come after the standard ones, but they are otherwise freetyped.

Jujutsu takes advantage of that to store its own identifier (change-id) as an extra header.

Because signatures will cover the hash of the whole commit (standard headers, extra headers and the message. Everything but the signature itself), if we deserialize a commit and then EncodeWithoutSignature to get back the "canonical" representation of a commit, if we don't serialize back the extra headers, the hash will no longer match and the signature will fail to verify.

This adds support for parsing and reencoding the extra headers from the original commit and it's expected to fix support for Jujutsu signed commits.

Fixes #1626

@baloo
Copy link
Contributor Author

baloo commented Aug 15, 2025

Would this be accepted in a backport to release-v5?
Edit: hopefully yes: #1633

@baloo baloo force-pushed the baloo/jj-signed-commits branch 2 times, most recently from da8a130 to 4609194 Compare August 21, 2025 16:14
@baloo baloo changed the title commit: support extra headers, support jujutsu signed commit plumbing: support commit extra headers, support jujutsu signed commit Aug 21, 2025
@baloo baloo changed the title plumbing: support commit extra headers, support jujutsu signed commit plumbing: support commits extra headers, support jujutsu signed commit Aug 21, 2025
@baloo
Copy link
Contributor Author

baloo commented Sep 2, 2025

@pjbgf any chance to get a review here? (Could I ask you'd click the button to run the CI for me? CI runs are restricted for first time contributors)

@baloo baloo force-pushed the baloo/jj-signed-commits branch 2 times, most recently from 691fde8 to 1bc63b7 Compare September 6, 2025 20:09
@baloo
Copy link
Contributor Author

baloo commented Sep 6, 2025

Rebased with fixes in #1643.

Turns out I can run actions on my fork: baloo#1

Copy link
Member

@pjbgf pjbgf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@baloo thanks for looking into this. Overall the changes look good, I just think we are missing some input validation when encoding the extra header into the commits. Can you take a look at that please?

Comment on lines 348 to 415
for _, header := range c.ExtraHeaders {
if _, err = fmt.Fprintf(w, "\n%s", header); err != nil {
return err
}
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add some validation around this logic. I'm not completely sure of all the validation that takes place upstream, but it would be good to explore adding checks for:

  • Empty values
  • Headers with the same name as core headers (tree, author, committer, parent, etc.)
  • Header names without values
  • Header values without names

Whatever we can confirm upstream blocks, we should also block.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this version works for you?

@pjbgf
Copy link
Member

pjbgf commented Sep 7, 2025

Would this be accepted in a backport to release-v5?

I'm happy to support the backporting once this PR is merged.

@baloo baloo force-pushed the baloo/jj-signed-commits branch from 1bc63b7 to 6e1764b Compare September 7, 2025 22:37
This adds support for extra headers. While git has a set of 
["standard headers"] (`tree`, `parent`, `author`, `committer`, and
`encoding`), it will also support [extra headers] when serializing.

The extra headers must come after the standard ones, but they are
otherwise freetyped.

[Jujutsu] takes advantage of that to store its own identifier
(`change-id`) as an extra header.

Because signatures will cover the hash of the whole commit (standard
headers, extra headers and the message. Everything but the signature
itself), if we deserialize a commit and then `EncodeWithoutSignature` to
get back the "canonical" representation of a commit, if we don't
serialize back the extra headers, the hash will no longer match and the
signature will fail to verify.

This adds support for parsing and reencoding the extra headers from the
original commit and it's expected to fix support for Jujutsu signed
commits.

Fixes go-git#1626

["standard headers"]: https://github.com/git/git/blob/724518f3884d8707c5f51428ba98c115818229b8/commit.c#L1450
[extra headers]: https://github.com/git/git/blob/724518f3884d8707c5f51428ba98c115818229b8/commit.c#L1690
[Jujutsu]: https://github.com/jj-vcs/jj
@baloo baloo force-pushed the baloo/jj-signed-commits branch from 6e1764b to eb42b9a Compare September 11, 2025 17:21
@baloo
Copy link
Contributor Author

baloo commented Sep 16, 2025

@pjbgf any chance to get another review here? This bug has been a problem in my everyday workflow and I'd love to get it fixed.

Thanks a lot!

Copy link
Member

@pjbgf pjbgf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@baloo thanks for adding support for extra headers to go-git! 🙇

@pjbgf pjbgf merged commit 6e57f9e into go-git:main Sep 17, 2025
16 checks passed
tstenner pushed a commit to tstenner/go-git that referenced this pull request Sep 17, 2025
plumbing: support commits extra headers, support jujutsu signed commit
@baloo baloo deleted the baloo/jj-signed-commits branch September 24, 2025 17:37
@baloo
Copy link
Contributor Author

baloo commented Sep 24, 2025

Deployed this morning. Works as expected, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

EncodeWithoutSignature breaks signatures generated by Jujutsu

2 participants