Skip to content

Commit f779a58

Browse files
Chris McDonnellstefanhaller
authored andcommitted
refactor: Express WithGpgHelper with a config key parameter
1 parent 6fb3b74 commit f779a58

File tree

5 files changed

+28
-10
lines changed

5 files changed

+28
-10
lines changed

pkg/commands/git_commands/config.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,27 @@ func (self *ConfigCommands) GetPager(width int) string {
5757
return utils.ResolvePlaceholderString(pagerTemplate, templateValues)
5858
}
5959

60-
// NeedsGpgSubprocessForCommit tells us whether the user has gpg enabled for commit actions
60+
type GpgConfigKey string
61+
62+
const (
63+
CommitGpgSign GpgConfigKey = "commit.gpgSign"
64+
TagGpgSign GpgConfigKey = "tag.gpgSign"
65+
)
66+
67+
// NeedsGpgSubprocess tells us whether the user has gpg enabled for the specified action type
6168
// and needs a subprocess because they have a process where they manually
6269
// enter their password every time a GPG action is taken
63-
func (self *ConfigCommands) NeedsGpgSubprocessForCommit() bool {
70+
func (self *ConfigCommands) NeedsGpgSubprocess(key GpgConfigKey) bool {
6471
overrideGpg := self.UserConfig().Git.OverrideGpg
6572
if overrideGpg {
6673
return false
6774
}
6875

69-
return self.gitConfig.GetBool("commit.gpgSign")
76+
return self.gitConfig.GetBool(string(key))
77+
}
78+
79+
func (self *ConfigCommands) NeedsGpgSubprocessForCommit() bool {
80+
return self.NeedsGpgSubprocess(CommitGpgSign)
7081
}
7182

7283
func (self *ConfigCommands) GetCoreEditor() string {

pkg/gui/controllers/helpers/amend_helper.go

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

3+
import "github.com/jesseduffield/lazygit/pkg/commands/git_commands"
4+
35
type AmendHelper struct {
46
c *HelperCommon
57
gpg *GpgHelper
@@ -18,5 +20,5 @@ func NewAmendHelper(
1820
func (self *AmendHelper) AmendHead() error {
1921
cmdObj := self.c.Git().Commit.AmendHeadCmdObj()
2022
self.c.LogAction(self.c.Tr.Actions.AmendCommit)
21-
return self.gpg.WithGpgHandling(cmdObj, self.c.Tr.AmendingStatus, nil)
23+
return self.gpg.WithGpgHandling(cmdObj, git_commands.CommitGpgSign, self.c.Tr.AmendingStatus, nil)
2224
}

pkg/gui/controllers/helpers/gpg_helper.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55

66
"github.com/jesseduffield/gocui"
7+
"github.com/jesseduffield/lazygit/pkg/commands/git_commands"
78
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
89
"github.com/jesseduffield/lazygit/pkg/gui/types"
910
)
@@ -22,8 +23,8 @@ func NewGpgHelper(c *HelperCommon) *GpgHelper {
2223
// WithWaitingStatus we get stuck there and can't return to lazygit. We could
2324
// fix this bug, or just stop running subprocesses from within there, given that
2425
// we don't need to see a loading status if we're in a subprocess.
25-
func (self *GpgHelper) WithGpgHandling(cmdObj oscommands.ICmdObj, waitingStatus string, onSuccess func() error) error {
26-
useSubprocess := self.c.Git().Config.NeedsGpgSubprocessForCommit()
26+
func (self *GpgHelper) WithGpgHandling(cmdObj oscommands.ICmdObj, configKey git_commands.GpgConfigKey, waitingStatus string, onSuccess func() error) error {
27+
useSubprocess := self.c.Git().Config.NeedsGpgSubprocess(configKey)
2728
if useSubprocess {
2829
success, err := self.c.RunSubprocess(cmdObj)
2930
if success && onSuccess != nil {

pkg/gui/controllers/helpers/working_tree_helper.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"regexp"
77

8+
"github.com/jesseduffield/lazygit/pkg/commands/git_commands"
89
"github.com/jesseduffield/lazygit/pkg/commands/models"
910
"github.com/jesseduffield/lazygit/pkg/config"
1011
"github.com/jesseduffield/lazygit/pkg/gui/context"
@@ -111,10 +112,11 @@ func (self *WorkingTreeHelper) HandleCommitPressWithMessage(initialMessage strin
111112
func (self *WorkingTreeHelper) handleCommit(summary string, description string, forceSkipHooks bool) error {
112113
cmdObj := self.c.Git().Commit.CommitCmdObj(summary, description, forceSkipHooks)
113114
self.c.LogAction(self.c.Tr.Actions.Commit)
114-
return self.gpgHelper.WithGpgHandling(cmdObj, self.c.Tr.CommittingStatus, func() error {
115-
self.commitsHelper.OnCommitSuccess()
116-
return nil
117-
})
115+
return self.gpgHelper.WithGpgHandling(cmdObj, git_commands.CommitGpgSign, self.c.Tr.CommittingStatus,
116+
func() error {
117+
self.commitsHelper.OnCommitSuccess()
118+
return nil
119+
})
118120
}
119121

120122
func (self *WorkingTreeHelper) switchFromCommitMessagePanelToEditor(filepath string, forceSkipHooks bool) error {

pkg/gui/controllers/local_commits_controller.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66

77
"github.com/go-errors/errors"
88
"github.com/jesseduffield/gocui"
9+
"github.com/jesseduffield/lazygit/pkg/commands/git_commands"
910
"github.com/jesseduffield/lazygit/pkg/commands/models"
1011
"github.com/jesseduffield/lazygit/pkg/commands/types/enums"
1112
"github.com/jesseduffield/lazygit/pkg/gui/context"
@@ -412,6 +413,7 @@ func (self *LocalCommitsController) handleReword(summary string, description str
412413
if models.IsHeadCommit(self.c.Model().Commits, self.c.Contexts().LocalCommits.GetSelectedLineIdx()) {
413414
// we've selected the top commit so no rebase is required
414415
return self.c.Helpers().GPG.WithGpgHandling(self.c.Git().Commit.RewordLastCommit(summary, description),
416+
git_commands.CommitGpgSign,
415417
self.c.Tr.RewordingStatus, nil)
416418
}
417419

0 commit comments

Comments
 (0)