Respect commit.gpgsign config in auto-commit strategy#313
Open
oryanmoshe wants to merge 1 commit intoentireio:mainfrom
Open
Respect commit.gpgsign config in auto-commit strategy#313oryanmoshe wants to merge 1 commit intoentireio:mainfrom
oryanmoshe wants to merge 1 commit intoentireio:mainfrom
Conversation
When users have commit.gpgsign=true, go-git's worktree.Commit() creates unsigned commits. Fall back to git CLI when signing is enabled, which handles GPG, SSH, and X.509 automatically. The go-git path is unchanged when signing is not configured. Follows the existing CLI fallback pattern (HardResetWithProtection, CheckoutBranch). Fixes entireio#311 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
7c06361 to
86edbb5
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
commit.gpgsign=trueis set in git config,commitOrHead()now falls back to the git CLI so commits are properly signedFixes #311
Why git CLI instead of go-git?
go-git v5's
CommitOptions.SignKeyonly accepts*openpgp.Entity— an in-process OpenPGP key. This means it cannot handle:gpg.format = ssh) — increasingly common, GitHub's default recommendationgpg.format = x509) — used in enterprise environmentsThe git CLI handles all of these automatically based on the user's config. This is the same pattern used by
HardResetWithProtectionandCheckoutBranchin this codebase — go-git is preferred, but the CLI is used when go-git has a gap:The signing gap is similar: go-git can create commits but can't sign them in a way that covers all methods users actually use.
What changed
auto_commit.go— 3 functions added/modified:commitOrHead()— checksshouldSignCommits()before the existing go-git path. When false (most users), behavior is identical to before.shouldSignCommits()— readscommit.gpgsignviagit config --get(respects local/global/system/includes).commitWithCLI()— creates the commit viagit commit, with the same empty-commit handling as the go-git path.auto_commit_test.go— 4 new tests:TestShouldSignCommits_Disabled/_Enabled— config detectionTestCommitWithCLI_CreatesCommit— verifies commit message and authorTestCommitWithCLI_EmptyCommit— returns HEAD hash (matches go-git behavior)Verified end-to-end
Tested with a fresh repo,
commit.gpgsign=true, auto-commit strategy:Without this fix, the same commit would have no signature (go-git ignores
commit.gpgsign).Test plan
TestShouldSignCommits_Disabled— returns false when gpgsign=falseTestShouldSignCommits_Enabled— returns true when gpgsign=trueTestCommitWithCLI_CreatesCommit— CLI path creates commit with correct message/authorTestCommitWithCLI_EmptyCommit— CLI path returns HEAD hash for empty commitsmise run test:ci— unit + integration with race detection)commit.gpgsign=true🤖 Generated with Claude Code