Skip to content

git: Clean up API around signing commits and tags#1847

Merged
pjbgf merged 5 commits intogo-git:mainfrom
pjbgf:signing
Feb 14, 2026
Merged

git: Clean up API around signing commits and tags#1847
pjbgf merged 5 commits intogo-git:mainfrom
pjbgf:signing

Conversation

@pjbgf
Copy link
Member

@pjbgf pjbgf commented Feb 13, 2026

The support for signatures beyond PGP were introduced as non-breaking enhancements within v5. This PR introduces breaking changes to better reflect the existing support.

  • Remove SignKey from CommitOptions. Users should use the field Signer instead, which is supported since v5.
  • Field PGPSignature in both Tag and Commit structs are now called Signature, to reflect the support of signatures beyond PGP.
  • Cherry-pick the removal of support for BEGIN CERTIFICATE for x509 signatures. This change aligns with upstream git and gnupg. We will continue to support BEGIN SIGNED MESSAGE, as per official git docs.

Follow-up from #690, #996 and #1029.

Relates to #910 #400.

pjbgf and others added 4 commits February 13, 2026 17:43
The SignKey field has been superseded by the Signer interface, which
provides greater extensibility and supports signing options beyond
PGP.

Signed-off-by: Paulo Gomes <pjbgf@linux.com>
The support for signing commits using other mechanisms beyond
PGP was introduced as a patch change in the v5 release, which
meant that cleaning up previous types was out of scope.

As a breaking change Commit.PGPSignature is now being renamed
to Commit.Signature, reflecting that this field is agnostic to
the method used to generate the signature.

Signed-off-by: Paulo Gomes <pjbgf@linux.com>
The support for signing tags using other mechanisms beyond
PGP was introduced as a patch change in the v5 release, which
meant that cleaning up previous types was out of scope.

As a breaking change Tag.PGPSignature is now being renamed
to Tag.Signature, reflecting that this field is agnostic to
the method used to generate the signature.

Signed-off-by: Paulo Gomes <pjbgf@linux.com>
…E` PEM label

This keeps feature parity with `git` behavior.
See PR go-git#1169 for more details and context.
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces breaking API cleanups to reflect existing support for multiple signature types (beyond OpenPGP) across commits and annotated tags, and aligns X.509 signature parsing behavior with upstream git/gnupg.

Changes:

  • Remove SignKey from CommitOptions, relying solely on CommitOptions.Signer for commit signing.
  • Rename PGPSignature to Signature on object.Commit and object.Tag, updating encode/decode/verify call sites and tests accordingly.
  • Update signature parsing to no longer treat -----BEGIN CERTIFICATE----- as an X.509 signature marker (only SIGNED MESSAGE is recognized).

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
worktree_commit_test.go Updates commit-signing tests to use CommitOptions.Signer instead of SignKey.
worktree_commit.go Removes SignKeySigner fallback conversion; writes commit signatures to Commit.Signature.
signer_test.go Updates the signer example to reference Signature instead of PGPSignature.
repository.go Writes tag signatures to Tag.Signature instead of Tag.PGPSignature.
plumbing/object/tag_test.go Updates tag signature serialization/verification tests to use Signature.
plumbing/object/tag.go Renames PGPSignature field to Signature and updates decode/encode/verify flows.
plumbing/object/signature_test.go Adjusts tests to reflect removal of BEGIN CERTIFICATE detection for X.509.
plumbing/object/signature.go Removes -----BEGIN CERTIFICATE----- from recognized X.509 signature formats.
plumbing/object/commit_test.go Updates commit signature tests to use Signature.
plumbing/object/commit.go Renames PGPSignature field to Signature and updates decode/encode/verify flows.
options.go Removes CommitOptions.SignKey, leaving CommitOptions.Signer as the signing mechanism.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

hiddeco
hiddeco previously approved these changes Feb 13, 2026
Copy link
Member

@hiddeco hiddeco left a comment

Choose a reason for hiding this comment

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

💯

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Paulo Gomes <paulo.gomes.uk@gmail.com>
@pjbgf pjbgf merged commit e32ef24 into go-git:main Feb 14, 2026
14 checks passed
@pjbgf pjbgf deleted the signing branch February 14, 2026 09:57
@terlar
Copy link

terlar commented Feb 16, 2026

After this change, should the gpgSigner be public so everyone don't have to copy this code?
https://github.com/go-git/go-git/blob/main/worktree_commit.go#L258

Or is the plan that this kind of logic should be extracted into the openpgp package itself?

Now this code is only used and accessible within the tests for worktree_commit.

@pjbgf
Copy link
Member Author

pjbgf commented Feb 16, 2026

@terlar thanks for the ping, I'm working on this and just created an issue to highlight that.

This PR was just a stepping stone towards a more consistent and user-friendly API around this feature.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants