1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-03-17 21:18:31 +02:00

no more config in git command struct

This commit is contained in:
Jesse Duffield 2021-12-29 11:41:33 +11:00
parent 18ab086126
commit 03b946cc8f
17 changed files with 28 additions and 38 deletions

View File

@ -84,7 +84,7 @@ func (c *GitCommand) GetUpstreamForBranch(branchName string) (string, error) {
}
func (c *GitCommand) GetBranchGraphCmdObj(branchName string) oscommands.ICmdObj {
branchLogCmdTemplate := c.Config.GetUserConfig().Git.BranchLogCmd
branchLogCmdTemplate := c.UserConfig.Git.BranchLogCmd
templateValues := map[string]string{
"branchName": c.OSCommand.Quote(branchName),
}
@ -128,7 +128,7 @@ type MergeOpts struct {
// Merge merge
func (c *GitCommand) Merge(branchName string, opts MergeOpts) error {
mergeArgs := c.Config.GetUserConfig().Git.Merging.Args
mergeArgs := c.UserConfig.Git.Merging.Args
command := fmt.Sprintf("git merge --no-edit %s %s", mergeArgs, c.OSCommand.Quote(branchName))
if opts.FastForwardOnly {

View File

@ -209,7 +209,7 @@ func TestGitCommandGetAllBranchGraph(t *testing.T) {
assert.EqualValues(t, []string{"log", "--graph", "--all", "--color=always", "--abbrev-commit", "--decorate", "--date=relative", "--pretty=medium"}, args)
return secureexec.Command("echo")
}
cmdStr := gitCmd.Config.GetUserConfig().Git.AllBranchesLogCmd
cmdStr := gitCmd.UserConfig.Git.AllBranchesLogCmd
_, err := gitCmd.OSCommand.RunWithOutput(gitCmd.NewCmdObj(cmdStr))
assert.NoError(t, err)
}

View File

@ -66,7 +66,7 @@ func (c *GitCommand) AmendHeadCmdObj() oscommands.ICmdObj {
}
func (c *GitCommand) ShowCmdObj(sha string, filterPath string) oscommands.ICmdObj {
contextSize := c.Config.GetUserConfig().Git.DiffContextSize
contextSize := c.UserConfig.Git.DiffContextSize
filterPathArg := ""
if filterPath != "" {
filterPathArg = fmt.Sprintf(" -- %s", c.OSCommand.Quote(filterPath))

View File

@ -144,7 +144,7 @@ func TestGitCommandShowCmdObj(t *testing.T) {
for _, s := range scenarios {
t.Run(s.testName, func(t *testing.T) {
gitCmd.Config.GetUserConfig().Git.DiffContextSize = s.contextSize
gitCmd.UserConfig.Git.DiffContextSize = s.contextSize
cmdStr := gitCmd.ShowCmdObj("1234567890", s.filterPath).ToString()
assert.Equal(t, s.expected, cmdStr)
})

View File

@ -20,7 +20,7 @@ func (c *GitCommand) ConfiguredPager() string {
}
func (c *GitCommand) GetPager(width int) string {
useConfig := c.Config.GetUserConfig().Git.Paging.UseConfig
useConfig := c.UserConfig.Git.Paging.UseConfig
if useConfig {
pager := c.ConfiguredPager()
return strings.Split(pager, "| less")[0]
@ -30,18 +30,18 @@ func (c *GitCommand) GetPager(width int) string {
"columnWidth": strconv.Itoa(width/2 - 6),
}
pagerTemplate := c.Config.GetUserConfig().Git.Paging.Pager
pagerTemplate := c.UserConfig.Git.Paging.Pager
return utils.ResolvePlaceholderString(pagerTemplate, templateValues)
}
func (c *GitCommand) colorArg() string {
return c.Config.GetUserConfig().Git.Paging.ColorArg
return c.UserConfig.Git.Paging.ColorArg
}
// UsingGpg tells us whether the user has gpg enabled so that we can know
// whether we need to run a subprocess to allow them to enter their password
func (c *GitCommand) UsingGpg() bool {
overrideGpg := c.Config.GetUserConfig().Git.OverrideGpg
overrideGpg := c.UserConfig.Git.OverrideGpg
if overrideGpg {
return false
}

View File

@ -6,7 +6,6 @@ import (
"github.com/jesseduffield/lazygit/pkg/commands/git_config"
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
"github.com/jesseduffield/lazygit/pkg/config"
"github.com/jesseduffield/lazygit/pkg/utils"
)
@ -17,11 +16,9 @@ func NewDummyGitCommand() *GitCommand {
// NewDummyGitCommandWithOSCommand creates a new dummy GitCommand for testing
func NewDummyGitCommandWithOSCommand(osCommand *oscommands.OSCommand) *GitCommand {
newAppConfig := config.NewDummyAppConfig()
return &GitCommand{
Common: utils.NewDummyCommon(),
OSCommand: osCommand,
Config: newAppConfig,
GitConfig: git_config.NewFakeGitConfig(map[string]string{}),
GetCmdWriter: func() io.Writer { return ioutil.Discard },
}

View File

@ -209,7 +209,7 @@ func (c *GitCommand) WorktreeFileDiffCmdObj(node models.IFile, plain bool, cache
colorArg := c.colorArg()
quotedPath := c.OSCommand.Quote(node.GetPath())
ignoreWhitespaceArg := ""
contextSize := c.Config.GetUserConfig().Git.DiffContextSize
contextSize := c.UserConfig.Git.DiffContextSize
if cached {
cachedArg = "--cached"
}
@ -229,7 +229,7 @@ func (c *GitCommand) WorktreeFileDiffCmdObj(node models.IFile, plain bool, cache
}
func (c *GitCommand) ApplyPatch(patch string, flags ...string) error {
filepath := filepath.Join(c.Config.GetTempDir(), utils.GetCurrentRepoName(), time.Now().Format("Jan _2 15.04.05.000000000")+".patch")
filepath := filepath.Join(oscommands.GetTempDir(), utils.GetCurrentRepoName(), time.Now().Format("Jan _2 15.04.05.000000000")+".patch")
c.Log.Infof("saving temporary patch to %s", filepath)
if err := c.OSCommand.CreateFileWithContent(filepath, patch); err != nil {
return err
@ -252,7 +252,7 @@ func (c *GitCommand) ShowFileDiff(from string, to string, reverse bool, fileName
func (c *GitCommand) ShowFileDiffCmdObj(from string, to string, reverse bool, fileName string, plain bool) oscommands.ICmdObj {
colorArg := c.colorArg()
contextSize := c.Config.GetUserConfig().Git.DiffContextSize
contextSize := c.UserConfig.Git.DiffContextSize
if plain {
colorArg = "never"
}
@ -334,7 +334,7 @@ func (c *GitCommand) ResetAndClean() error {
}
func (c *GitCommand) EditFileCmdStr(filename string, lineNumber int) (string, error) {
editor := c.Config.GetUserConfig().OS.EditCommand
editor := c.UserConfig.OS.EditCommand
if editor == "" {
editor = c.GitConfig.Get("core.editor")
@ -364,6 +364,6 @@ func (c *GitCommand) EditFileCmdStr(filename string, lineNumber int) (string, er
"line": strconv.Itoa(lineNumber),
}
editCmdTemplate := c.Config.GetUserConfig().OS.EditCommandTemplate
editCmdTemplate := c.UserConfig.OS.EditCommandTemplate
return utils.ResolvePlaceholderString(editCmdTemplate, templateValues), nil
}

View File

@ -435,7 +435,7 @@ func TestGitCommandDiff(t *testing.T) {
t.Run(s.testName, func(t *testing.T) {
gitCmd := NewDummyGitCommand()
gitCmd.OSCommand.Command = s.command
gitCmd.Config.GetUserConfig().Git.DiffContextSize = s.contextSize
gitCmd.UserConfig.Git.DiffContextSize = s.contextSize
gitCmd.WorktreeFileDiff(s.file, s.plain, s.cached, s.ignoreWhitespace)
})
}
@ -488,7 +488,7 @@ func TestGitCommandShowFileDiff(t *testing.T) {
t.Run(s.testName, func(t *testing.T) {
gitCmd := NewDummyGitCommand()
gitCmd.OSCommand.Command = s.command
gitCmd.Config.GetUserConfig().Git.DiffContextSize = s.contextSize
gitCmd.UserConfig.Git.DiffContextSize = s.contextSize
_, _ = gitCmd.ShowFileDiff(s.from, s.to, s.reverse, "test.txt", s.plain)
})
}
@ -946,8 +946,8 @@ func TestEditFileCmdStr(t *testing.T) {
}
for _, s := range scenarios {
gitCmd.Config.GetUserConfig().OS.EditCommand = s.configEditCommand
gitCmd.Config.GetUserConfig().OS.EditCommandTemplate = s.configEditCommandTemplate
gitCmd.UserConfig.OS.EditCommand = s.configEditCommand
gitCmd.UserConfig.OS.EditCommandTemplate = s.configEditCommandTemplate
gitCmd.OSCommand.Command = s.command
gitCmd.OSCommand.Getenv = s.getenv
gitCmd.GitConfig = git_config.NewFakeGitConfig(s.gitConfigMockResponses)

View File

@ -31,7 +31,6 @@ type GitCommand struct {
*common.Common
OSCommand *oscommands.OSCommand
Repo *gogit.Repository
Config config.AppConfigurer
DotGitDir string
onSuccessfulContinue func() error
PatchManager *patch.PatchManager
@ -75,7 +74,6 @@ func NewGitCommand(
Common: cmn,
OSCommand: osCommand,
Repo: repo,
Config: config,
DotGitDir: dotGitDir,
PushToCurrent: pushToCurrent,
GitConfig: gitConfig,

View File

@ -7,7 +7,6 @@ import (
"github.com/jesseduffield/lazygit/pkg/commands/models"
"github.com/jesseduffield/lazygit/pkg/common"
"github.com/jesseduffield/lazygit/pkg/utils"
"github.com/sirupsen/logrus"
)
// context:
@ -24,14 +23,11 @@ import (
// BranchListBuilder returns a list of Branch objects for the current repo
type BranchListBuilder struct {
*common.Common
log *logrus.Entry
getRawBranches func() (string, error)
getCurrentBranchName func() (string, string, error)
reflogCommits []*models.Commit
}
// common things: log, user config, Tr.
func NewBranchListBuilder(
cmn *common.Common,
getRawBranches func() (string, error),

View File

@ -410,7 +410,7 @@ func (c *CommitListBuilder) getLogCmd(opts GetCommitsOptions) oscommands.ICmdObj
filterFlag = fmt.Sprintf(" --follow -- %s", c.OSCommand.Quote(opts.FilterPath))
}
config := c.GitCommand.Config.GetUserConfig().Git.Log
config := c.GitCommand.UserConfig.Git.Log
orderFlag := "--" + config.Order
allFlag := ""

View File

@ -485,3 +485,7 @@ func sanitisedCommandOutput(output []byte, err error) (string, error) {
}
return outputString, nil
}
func GetTempDir() string {
return filepath.Join(os.TempDir(), "lazygit")
}

View File

@ -57,7 +57,7 @@ func TestOSCommandOpenFileDarwin(t *testing.T) {
OSCmd := NewDummyOSCommand()
OSCmd.Platform.OS = "darwin"
OSCmd.Command = s.command
OSCmd.Config.GetUserConfig().OS.OpenCommand = "open {{filename}}"
OSCmd.UserConfig.OS.OpenCommand = "open {{filename}}"
s.test(OSCmd.OpenFile(s.filename))
}
@ -131,7 +131,7 @@ func TestOSCommandOpenFileLinux(t *testing.T) {
OSCmd := NewDummyOSCommand()
OSCmd.Command = s.command
OSCmd.Platform.OS = "linux"
OSCmd.Config.GetUserConfig().OS.OpenCommand = `xdg-open {{filename}} > /dev/null`
OSCmd.UserConfig.OS.OpenCommand = `xdg-open {{filename}} > /dev/null`
s.test(OSCmd.OpenFile(s.filename))
}

View File

@ -79,7 +79,7 @@ func TestOSCommandOpenFileWindows(t *testing.T) {
OSCmd := NewDummyOSCommand()
OSCmd.Command = s.command
OSCmd.Platform.OS = "windows"
OSCmd.Config.GetUserConfig().OS.OpenCommand = `start "" {{filename}}`
OSCmd.UserConfig.OS.OpenCommand = `start "" {{filename}}`
s.test(OSCmd.OpenFile(s.filename))
}

View File

@ -15,7 +15,7 @@ func (c *GitCommand) StashSave(message string) error {
// GetStashEntryDiff stash diff
func (c *GitCommand) ShowStashEntryCmdStr(index int) string {
return fmt.Sprintf("git stash show -p --stat --color=%s --unified=%d stash@{%d}", c.colorArg(), c.Config.GetUserConfig().Git.DiffContextSize, index)
return fmt.Sprintf("git stash show -p --stat --color=%s --unified=%d stash@{%d}", c.colorArg(), c.UserConfig.Git.DiffContextSize, index)
}
// StashSaveStagedChanges stashes only the currently staged changes. This takes a few steps

View File

@ -61,7 +61,7 @@ func TestGitCommandShowStashEntryCmdStr(t *testing.T) {
for _, s := range scenarios {
t.Run(s.testName, func(t *testing.T) {
gitCmd := NewDummyGitCommand()
gitCmd.Config.GetUserConfig().Git.DiffContextSize = s.contextSize
gitCmd.UserConfig.Git.DiffContextSize = s.contextSize
cmdStr := gitCmd.ShowStashEntryCmdStr(s.index)
assert.Equal(t, s.expected, cmdStr)
})

View File

@ -39,7 +39,6 @@ type AppConfigurer interface {
GetUserConfig() *UserConfig
GetUserConfigPaths() []string
GetUserConfigDir() string
GetTempDir() string
GetAppState() *AppState
SaveAppState() error
SetIsNewRepo(bool)
@ -226,10 +225,6 @@ func (c *AppConfig) GetUserConfigDir() string {
return c.UserConfigDir
}
func (c *AppConfig) GetTempDir() string {
return c.TempDir
}
func (c *AppConfig) ReloadUserConfig() error {
userConfig, err := loadUserConfigWithDefaults(c.UserConfigPaths)
if err != nil {