mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-06-15 00:15:32 +02:00
refactor: Express WithGpgHelper with a config key parameter
This commit is contained in:
committed by
Stefan Haller
parent
6fb3b7430c
commit
f779a5878d
@ -57,16 +57,27 @@ func (self *ConfigCommands) GetPager(width int) string {
|
|||||||
return utils.ResolvePlaceholderString(pagerTemplate, templateValues)
|
return utils.ResolvePlaceholderString(pagerTemplate, templateValues)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NeedsGpgSubprocessForCommit tells us whether the user has gpg enabled for commit actions
|
type GpgConfigKey string
|
||||||
|
|
||||||
|
const (
|
||||||
|
CommitGpgSign GpgConfigKey = "commit.gpgSign"
|
||||||
|
TagGpgSign GpgConfigKey = "tag.gpgSign"
|
||||||
|
)
|
||||||
|
|
||||||
|
// NeedsGpgSubprocess tells us whether the user has gpg enabled for the specified action type
|
||||||
// and needs a subprocess because they have a process where they manually
|
// and needs a subprocess because they have a process where they manually
|
||||||
// enter their password every time a GPG action is taken
|
// enter their password every time a GPG action is taken
|
||||||
func (self *ConfigCommands) NeedsGpgSubprocessForCommit() bool {
|
func (self *ConfigCommands) NeedsGpgSubprocess(key GpgConfigKey) bool {
|
||||||
overrideGpg := self.UserConfig().Git.OverrideGpg
|
overrideGpg := self.UserConfig().Git.OverrideGpg
|
||||||
if overrideGpg {
|
if overrideGpg {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
return self.gitConfig.GetBool("commit.gpgSign")
|
return self.gitConfig.GetBool(string(key))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *ConfigCommands) NeedsGpgSubprocessForCommit() bool {
|
||||||
|
return self.NeedsGpgSubprocess(CommitGpgSign)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *ConfigCommands) GetCoreEditor() string {
|
func (self *ConfigCommands) GetCoreEditor() string {
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package helpers
|
package helpers
|
||||||
|
|
||||||
|
import "github.com/jesseduffield/lazygit/pkg/commands/git_commands"
|
||||||
|
|
||||||
type AmendHelper struct {
|
type AmendHelper struct {
|
||||||
c *HelperCommon
|
c *HelperCommon
|
||||||
gpg *GpgHelper
|
gpg *GpgHelper
|
||||||
@ -18,5 +20,5 @@ func NewAmendHelper(
|
|||||||
func (self *AmendHelper) AmendHead() error {
|
func (self *AmendHelper) AmendHead() error {
|
||||||
cmdObj := self.c.Git().Commit.AmendHeadCmdObj()
|
cmdObj := self.c.Git().Commit.AmendHeadCmdObj()
|
||||||
self.c.LogAction(self.c.Tr.Actions.AmendCommit)
|
self.c.LogAction(self.c.Tr.Actions.AmendCommit)
|
||||||
return self.gpg.WithGpgHandling(cmdObj, self.c.Tr.AmendingStatus, nil)
|
return self.gpg.WithGpgHandling(cmdObj, git_commands.CommitGpgSign, self.c.Tr.AmendingStatus, nil)
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/jesseduffield/gocui"
|
"github.com/jesseduffield/gocui"
|
||||||
|
"github.com/jesseduffield/lazygit/pkg/commands/git_commands"
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
|
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||||
)
|
)
|
||||||
@ -22,8 +23,8 @@ func NewGpgHelper(c *HelperCommon) *GpgHelper {
|
|||||||
// WithWaitingStatus we get stuck there and can't return to lazygit. We could
|
// WithWaitingStatus we get stuck there and can't return to lazygit. We could
|
||||||
// fix this bug, or just stop running subprocesses from within there, given that
|
// fix this bug, or just stop running subprocesses from within there, given that
|
||||||
// we don't need to see a loading status if we're in a subprocess.
|
// we don't need to see a loading status if we're in a subprocess.
|
||||||
func (self *GpgHelper) WithGpgHandling(cmdObj oscommands.ICmdObj, waitingStatus string, onSuccess func() error) error {
|
func (self *GpgHelper) WithGpgHandling(cmdObj oscommands.ICmdObj, configKey git_commands.GpgConfigKey, waitingStatus string, onSuccess func() error) error {
|
||||||
useSubprocess := self.c.Git().Config.NeedsGpgSubprocessForCommit()
|
useSubprocess := self.c.Git().Config.NeedsGpgSubprocess(configKey)
|
||||||
if useSubprocess {
|
if useSubprocess {
|
||||||
success, err := self.c.RunSubprocess(cmdObj)
|
success, err := self.c.RunSubprocess(cmdObj)
|
||||||
if success && onSuccess != nil {
|
if success && onSuccess != nil {
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
|
||||||
|
"github.com/jesseduffield/lazygit/pkg/commands/git_commands"
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
||||||
"github.com/jesseduffield/lazygit/pkg/config"
|
"github.com/jesseduffield/lazygit/pkg/config"
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/context"
|
"github.com/jesseduffield/lazygit/pkg/gui/context"
|
||||||
@ -111,10 +112,11 @@ func (self *WorkingTreeHelper) HandleCommitPressWithMessage(initialMessage strin
|
|||||||
func (self *WorkingTreeHelper) handleCommit(summary string, description string, forceSkipHooks bool) error {
|
func (self *WorkingTreeHelper) handleCommit(summary string, description string, forceSkipHooks bool) error {
|
||||||
cmdObj := self.c.Git().Commit.CommitCmdObj(summary, description, forceSkipHooks)
|
cmdObj := self.c.Git().Commit.CommitCmdObj(summary, description, forceSkipHooks)
|
||||||
self.c.LogAction(self.c.Tr.Actions.Commit)
|
self.c.LogAction(self.c.Tr.Actions.Commit)
|
||||||
return self.gpgHelper.WithGpgHandling(cmdObj, self.c.Tr.CommittingStatus, func() error {
|
return self.gpgHelper.WithGpgHandling(cmdObj, git_commands.CommitGpgSign, self.c.Tr.CommittingStatus,
|
||||||
self.commitsHelper.OnCommitSuccess()
|
func() error {
|
||||||
return nil
|
self.commitsHelper.OnCommitSuccess()
|
||||||
})
|
return nil
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *WorkingTreeHelper) switchFromCommitMessagePanelToEditor(filepath string, forceSkipHooks bool) error {
|
func (self *WorkingTreeHelper) switchFromCommitMessagePanelToEditor(filepath string, forceSkipHooks bool) error {
|
||||||
|
@ -6,6 +6,7 @@ import (
|
|||||||
|
|
||||||
"github.com/go-errors/errors"
|
"github.com/go-errors/errors"
|
||||||
"github.com/jesseduffield/gocui"
|
"github.com/jesseduffield/gocui"
|
||||||
|
"github.com/jesseduffield/lazygit/pkg/commands/git_commands"
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands/types/enums"
|
"github.com/jesseduffield/lazygit/pkg/commands/types/enums"
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/context"
|
"github.com/jesseduffield/lazygit/pkg/gui/context"
|
||||||
@ -412,6 +413,7 @@ func (self *LocalCommitsController) handleReword(summary string, description str
|
|||||||
if models.IsHeadCommit(self.c.Model().Commits, self.c.Contexts().LocalCommits.GetSelectedLineIdx()) {
|
if models.IsHeadCommit(self.c.Model().Commits, self.c.Contexts().LocalCommits.GetSelectedLineIdx()) {
|
||||||
// we've selected the top commit so no rebase is required
|
// we've selected the top commit so no rebase is required
|
||||||
return self.c.Helpers().GPG.WithGpgHandling(self.c.Git().Commit.RewordLastCommit(summary, description),
|
return self.c.Helpers().GPG.WithGpgHandling(self.c.Git().Commit.RewordLastCommit(summary, description),
|
||||||
|
git_commands.CommitGpgSign,
|
||||||
self.c.Tr.RewordingStatus, nil)
|
self.c.Tr.RewordingStatus, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user