1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-06-25 00:46:54 +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 { func (c *GitCommand) GetBranchGraphCmdObj(branchName string) oscommands.ICmdObj {
branchLogCmdTemplate := c.Config.GetUserConfig().Git.BranchLogCmd branchLogCmdTemplate := c.UserConfig.Git.BranchLogCmd
templateValues := map[string]string{ templateValues := map[string]string{
"branchName": c.OSCommand.Quote(branchName), "branchName": c.OSCommand.Quote(branchName),
} }
@ -128,7 +128,7 @@ type MergeOpts struct {
// Merge merge // Merge merge
func (c *GitCommand) Merge(branchName string, opts MergeOpts) error { 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)) command := fmt.Sprintf("git merge --no-edit %s %s", mergeArgs, c.OSCommand.Quote(branchName))
if opts.FastForwardOnly { 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) assert.EqualValues(t, []string{"log", "--graph", "--all", "--color=always", "--abbrev-commit", "--decorate", "--date=relative", "--pretty=medium"}, args)
return secureexec.Command("echo") return secureexec.Command("echo")
} }
cmdStr := gitCmd.Config.GetUserConfig().Git.AllBranchesLogCmd cmdStr := gitCmd.UserConfig.Git.AllBranchesLogCmd
_, err := gitCmd.OSCommand.RunWithOutput(gitCmd.NewCmdObj(cmdStr)) _, err := gitCmd.OSCommand.RunWithOutput(gitCmd.NewCmdObj(cmdStr))
assert.NoError(t, err) 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 { func (c *GitCommand) ShowCmdObj(sha string, filterPath string) oscommands.ICmdObj {
contextSize := c.Config.GetUserConfig().Git.DiffContextSize contextSize := c.UserConfig.Git.DiffContextSize
filterPathArg := "" filterPathArg := ""
if filterPath != "" { if filterPath != "" {
filterPathArg = fmt.Sprintf(" -- %s", c.OSCommand.Quote(filterPath)) filterPathArg = fmt.Sprintf(" -- %s", c.OSCommand.Quote(filterPath))

View File

@ -144,7 +144,7 @@ func TestGitCommandShowCmdObj(t *testing.T) {
for _, s := range scenarios { for _, s := range scenarios {
t.Run(s.testName, func(t *testing.T) { 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() cmdStr := gitCmd.ShowCmdObj("1234567890", s.filterPath).ToString()
assert.Equal(t, s.expected, cmdStr) assert.Equal(t, s.expected, cmdStr)
}) })

View File

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

View File

@ -6,7 +6,6 @@ import (
"github.com/jesseduffield/lazygit/pkg/commands/git_config" "github.com/jesseduffield/lazygit/pkg/commands/git_config"
"github.com/jesseduffield/lazygit/pkg/commands/oscommands" "github.com/jesseduffield/lazygit/pkg/commands/oscommands"
"github.com/jesseduffield/lazygit/pkg/config"
"github.com/jesseduffield/lazygit/pkg/utils" "github.com/jesseduffield/lazygit/pkg/utils"
) )
@ -17,11 +16,9 @@ func NewDummyGitCommand() *GitCommand {
// NewDummyGitCommandWithOSCommand creates a new dummy GitCommand for testing // NewDummyGitCommandWithOSCommand creates a new dummy GitCommand for testing
func NewDummyGitCommandWithOSCommand(osCommand *oscommands.OSCommand) *GitCommand { func NewDummyGitCommandWithOSCommand(osCommand *oscommands.OSCommand) *GitCommand {
newAppConfig := config.NewDummyAppConfig()
return &GitCommand{ return &GitCommand{
Common: utils.NewDummyCommon(), Common: utils.NewDummyCommon(),
OSCommand: osCommand, OSCommand: osCommand,
Config: newAppConfig,
GitConfig: git_config.NewFakeGitConfig(map[string]string{}), GitConfig: git_config.NewFakeGitConfig(map[string]string{}),
GetCmdWriter: func() io.Writer { return ioutil.Discard }, 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() colorArg := c.colorArg()
quotedPath := c.OSCommand.Quote(node.GetPath()) quotedPath := c.OSCommand.Quote(node.GetPath())
ignoreWhitespaceArg := "" ignoreWhitespaceArg := ""
contextSize := c.Config.GetUserConfig().Git.DiffContextSize contextSize := c.UserConfig.Git.DiffContextSize
if cached { if cached {
cachedArg = "--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 { 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) c.Log.Infof("saving temporary patch to %s", filepath)
if err := c.OSCommand.CreateFileWithContent(filepath, patch); err != nil { if err := c.OSCommand.CreateFileWithContent(filepath, patch); err != nil {
return err 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 { func (c *GitCommand) ShowFileDiffCmdObj(from string, to string, reverse bool, fileName string, plain bool) oscommands.ICmdObj {
colorArg := c.colorArg() colorArg := c.colorArg()
contextSize := c.Config.GetUserConfig().Git.DiffContextSize contextSize := c.UserConfig.Git.DiffContextSize
if plain { if plain {
colorArg = "never" colorArg = "never"
} }
@ -334,7 +334,7 @@ func (c *GitCommand) ResetAndClean() error {
} }
func (c *GitCommand) EditFileCmdStr(filename string, lineNumber int) (string, error) { func (c *GitCommand) EditFileCmdStr(filename string, lineNumber int) (string, error) {
editor := c.Config.GetUserConfig().OS.EditCommand editor := c.UserConfig.OS.EditCommand
if editor == "" { if editor == "" {
editor = c.GitConfig.Get("core.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), "line": strconv.Itoa(lineNumber),
} }
editCmdTemplate := c.Config.GetUserConfig().OS.EditCommandTemplate editCmdTemplate := c.UserConfig.OS.EditCommandTemplate
return utils.ResolvePlaceholderString(editCmdTemplate, templateValues), nil 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) { t.Run(s.testName, func(t *testing.T) {
gitCmd := NewDummyGitCommand() gitCmd := NewDummyGitCommand()
gitCmd.OSCommand.Command = s.command 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) 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) { t.Run(s.testName, func(t *testing.T) {
gitCmd := NewDummyGitCommand() gitCmd := NewDummyGitCommand()
gitCmd.OSCommand.Command = s.command 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) _, _ = 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 { for _, s := range scenarios {
gitCmd.Config.GetUserConfig().OS.EditCommand = s.configEditCommand gitCmd.UserConfig.OS.EditCommand = s.configEditCommand
gitCmd.Config.GetUserConfig().OS.EditCommandTemplate = s.configEditCommandTemplate gitCmd.UserConfig.OS.EditCommandTemplate = s.configEditCommandTemplate
gitCmd.OSCommand.Command = s.command gitCmd.OSCommand.Command = s.command
gitCmd.OSCommand.Getenv = s.getenv gitCmd.OSCommand.Getenv = s.getenv
gitCmd.GitConfig = git_config.NewFakeGitConfig(s.gitConfigMockResponses) gitCmd.GitConfig = git_config.NewFakeGitConfig(s.gitConfigMockResponses)

View File

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

View File

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

View File

@ -485,3 +485,7 @@ func sanitisedCommandOutput(output []byte, err error) (string, error) {
} }
return outputString, nil 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 := NewDummyOSCommand()
OSCmd.Platform.OS = "darwin" OSCmd.Platform.OS = "darwin"
OSCmd.Command = s.command OSCmd.Command = s.command
OSCmd.Config.GetUserConfig().OS.OpenCommand = "open {{filename}}" OSCmd.UserConfig.OS.OpenCommand = "open {{filename}}"
s.test(OSCmd.OpenFile(s.filename)) s.test(OSCmd.OpenFile(s.filename))
} }
@ -131,7 +131,7 @@ func TestOSCommandOpenFileLinux(t *testing.T) {
OSCmd := NewDummyOSCommand() OSCmd := NewDummyOSCommand()
OSCmd.Command = s.command OSCmd.Command = s.command
OSCmd.Platform.OS = "linux" 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)) s.test(OSCmd.OpenFile(s.filename))
} }

View File

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

View File

@ -15,7 +15,7 @@ func (c *GitCommand) StashSave(message string) error {
// GetStashEntryDiff stash diff // GetStashEntryDiff stash diff
func (c *GitCommand) ShowStashEntryCmdStr(index int) string { 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 // 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 { for _, s := range scenarios {
t.Run(s.testName, func(t *testing.T) { t.Run(s.testName, func(t *testing.T) {
gitCmd := NewDummyGitCommand() gitCmd := NewDummyGitCommand()
gitCmd.Config.GetUserConfig().Git.DiffContextSize = s.contextSize gitCmd.UserConfig.Git.DiffContextSize = s.contextSize
cmdStr := gitCmd.ShowStashEntryCmdStr(s.index) cmdStr := gitCmd.ShowStashEntryCmdStr(s.index)
assert.Equal(t, s.expected, cmdStr) assert.Equal(t, s.expected, cmdStr)
}) })

View File

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