Skip to content

Commit 8ac0d6d

Browse files
author
Chris McDonnell
committed
feat: Use annotated tags if users use GPG
We follow the established hack of rejecting users if they have GPG enabled, but have not indicated that they will not need to manually enter their password by setting git.overrideGpg = true. Should be possible to do, based on the commit implementation.
1 parent 333ed50 commit 8ac0d6d

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

pkg/commands/git_commands/config.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,22 @@ func (self *ConfigCommands) NeedsGpgSubprocessForCommit() bool {
6969
return self.gitConfig.GetBool("commit.gpgSign")
7070
}
7171

72+
// NeedsGpgSubprocessForTag tells us whether the user has gpg enabled for tag actions
73+
// and needs a subprocess because they have a process where they manually
74+
// enter their password every time a GPG action is taken
75+
func (self *ConfigCommands) NeedsGpgSubprocessForTag() bool {
76+
overrideGpg := self.UserConfig().Git.OverrideGpg
77+
if overrideGpg {
78+
return false
79+
}
80+
81+
return self.gitConfig.GetBool("tag.gpgSign")
82+
}
83+
84+
func (self *ConfigCommands) GetTagGpgSign() bool {
85+
return self.gitConfig.GetBool("tag.gpgSign")
86+
}
87+
7288
func (self *ConfigCommands) GetCoreEditor() string {
7389
return self.gitConfig.Get("core.editor")
7490
}

pkg/gui/controllers/helpers/tags_helper.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package helpers
22

33
import (
4+
"errors"
5+
46
"github.com/jesseduffield/gocui"
57
"github.com/jesseduffield/lazygit/pkg/gui/context"
68
"github.com/jesseduffield/lazygit/pkg/gui/types"
@@ -22,7 +24,11 @@ func NewTagsHelper(c *HelperCommon, commitsHelper *CommitsHelper) *TagsHelper {
2224
func (self *TagsHelper) OpenCreateTagPrompt(ref string, onCreate func()) error {
2325
doCreateTag := func(tagName string, description string, force bool) error {
2426
return self.c.WithWaitingStatus(self.c.Tr.CreatingTag, func(gocui.Task) error {
25-
if description != "" {
27+
if self.c.Git().Config.NeedsGpgSubprocessForTag() {
28+
return errors.New(self.c.Tr.DisabledForGPG)
29+
}
30+
// We must create an annotated tag when users use GPG, even if the message is empty
31+
if description != "" || self.c.Git().Config.GetTagGpgSign() {
2632
self.c.LogAction(self.c.Tr.Actions.CreateAnnotatedTag)
2733
if err := self.c.Git().Tag.CreateAnnotated(tagName, ref, description, force); err != nil {
2834
return err

0 commit comments

Comments
 (0)