Skip to content

Commit c06d4e7

Browse files
Chris McDonnellstefanhaller
authored andcommitted
fix: Make tag operation use GPG helper to run signing in sub-process
1 parent f779a58 commit c06d4e7

File tree

4 files changed

+28
-24
lines changed

4 files changed

+28
-24
lines changed

pkg/commands/git_commands/config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ func (self *ConfigCommands) NeedsGpgSubprocessForCommit() bool {
8080
return self.NeedsGpgSubprocess(CommitGpgSign)
8181
}
8282

83+
func (self *ConfigCommands) GetGpgTagSign() bool {
84+
return self.gitConfig.GetBool(string(TagGpgSign))
85+
}
86+
8387
func (self *ConfigCommands) GetCoreEditor() string {
8488
return self.gitConfig.Get("core.editor")
8589
}

pkg/commands/git_commands/tag.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package git_commands
22

3-
import "github.com/jesseduffield/gocui"
3+
import (
4+
"github.com/jesseduffield/gocui"
5+
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
6+
)
47

58
type TagCommands struct {
69
*GitCommon
@@ -12,24 +15,24 @@ func NewTagCommands(gitCommon *GitCommon) *TagCommands {
1215
}
1316
}
1417

15-
func (self *TagCommands) CreateLightweight(tagName string, ref string, force bool) error {
18+
func (self *TagCommands) CreateLightweightObj(tagName string, ref string, force bool) oscommands.ICmdObj {
1619
cmdArgs := NewGitCmd("tag").
1720
ArgIf(force, "--force").
1821
Arg("--", tagName).
1922
ArgIf(len(ref) > 0, ref).
2023
ToArgv()
2124

22-
return self.cmd.New(cmdArgs).Run()
25+
return self.cmd.New(cmdArgs)
2326
}
2427

25-
func (self *TagCommands) CreateAnnotated(tagName, ref, msg string, force bool) error {
28+
func (self *TagCommands) CreateAnnotatedObj(tagName, ref, msg string, force bool) oscommands.ICmdObj {
2629
cmdArgs := NewGitCmd("tag").Arg(tagName).
2730
ArgIf(force, "--force").
2831
ArgIf(len(ref) > 0, ref).
2932
Arg("-m", msg).
3033
ToArgv()
3134

32-
return self.cmd.New(cmdArgs).Run()
35+
return self.cmd.New(cmdArgs)
3336
}
3437

3538
func (self *TagCommands) HasTag(tagName string) bool {

pkg/gui/controllers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ func (gui *Gui) resetHelpersAndControllers() {
106106
Suggestions: suggestionsHelper,
107107
Files: helpers.NewFilesHelper(helperCommon),
108108
WorkingTree: helpers.NewWorkingTreeHelper(helperCommon, refsHelper, commitsHelper, gpgHelper),
109-
Tags: helpers.NewTagsHelper(helperCommon, commitsHelper),
109+
Tags: helpers.NewTagsHelper(helperCommon, commitsHelper, gpgHelper),
110110
BranchesHelper: helpers.NewBranchesHelper(helperCommon, worktreeHelper),
111111
GPG: helpers.NewGpgHelper(helperCommon),
112112
MergeAndRebase: rebaseHelper,

pkg/gui/controllers/helpers/tags_helper.go

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

33
import (
4-
"github.com/jesseduffield/gocui"
4+
"github.com/jesseduffield/lazygit/pkg/commands/git_commands"
5+
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
56
"github.com/jesseduffield/lazygit/pkg/gui/context"
67
"github.com/jesseduffield/lazygit/pkg/gui/types"
78
"github.com/jesseduffield/lazygit/pkg/utils"
@@ -10,35 +11,31 @@ import (
1011
type TagsHelper struct {
1112
c *HelperCommon
1213
commitsHelper *CommitsHelper
14+
gpg *GpgHelper
1315
}
1416

15-
func NewTagsHelper(c *HelperCommon, commitsHelper *CommitsHelper) *TagsHelper {
17+
func NewTagsHelper(c *HelperCommon, commitsHelper *CommitsHelper, gpg *GpgHelper) *TagsHelper {
1618
return &TagsHelper{
1719
c: c,
1820
commitsHelper: commitsHelper,
21+
gpg: gpg,
1922
}
2023
}
2124

2225
func (self *TagsHelper) OpenCreateTagPrompt(ref string, onCreate func()) error {
2326
doCreateTag := func(tagName string, description string, force bool) error {
24-
return self.c.WithWaitingStatus(self.c.Tr.CreatingTag, func(gocui.Task) error {
25-
if description != "" {
26-
self.c.LogAction(self.c.Tr.Actions.CreateAnnotatedTag)
27-
if err := self.c.Git().Tag.CreateAnnotated(tagName, ref, description, force); err != nil {
28-
return err
29-
}
30-
} else {
31-
self.c.LogAction(self.c.Tr.Actions.CreateLightweightTag)
32-
if err := self.c.Git().Tag.CreateLightweight(tagName, ref, force); err != nil {
33-
return err
34-
}
35-
}
27+
var command oscommands.ICmdObj
28+
if description != "" || self.c.Git().Config.GetGpgTagSign() {
29+
self.c.LogAction(self.c.Tr.Actions.CreateAnnotatedTag)
30+
command = self.c.Git().Tag.CreateAnnotatedObj(tagName, ref, description, force)
31+
} else {
32+
self.c.LogAction(self.c.Tr.Actions.CreateLightweightTag)
33+
command = self.c.Git().Tag.CreateLightweightObj(tagName, ref, force)
34+
}
3635

36+
return self.gpg.WithGpgHandling(command, git_commands.TagGpgSign, self.c.Tr.CreatingTag, func() error {
3737
self.commitsHelper.OnCommitSuccess()
38-
39-
return self.c.Refresh(types.RefreshOptions{
40-
Mode: types.ASYNC, Scope: []types.RefreshableView{types.COMMITS, types.TAGS},
41-
})
38+
return nil
4239
})
4340
}
4441

0 commit comments

Comments
 (0)