diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2021-12-29 11:41:33 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2021-12-29 11:41:33 +1100 |
commit | 4ab4af441e78dbbd19bbd479c2cc31b3e08d037f (patch) | |
tree | 32749e8cd8da6476ad31e6f211e324b930aea8f2 /pkg/commands | |
parent | bdc54a5debd8f6b71a52d66841d986c5a74ca813 (diff) |
no more config in git command struct
Diffstat (limited to 'pkg/commands')
-rw-r--r-- | pkg/commands/branches.go | 4 | ||||
-rw-r--r-- | pkg/commands/branches_test.go | 2 | ||||
-rw-r--r-- | pkg/commands/commits.go | 2 | ||||
-rw-r--r-- | pkg/commands/commits_test.go | 2 | ||||
-rw-r--r-- | pkg/commands/config.go | 8 | ||||
-rw-r--r-- | pkg/commands/dummies.go | 3 | ||||
-rw-r--r-- | pkg/commands/files.go | 10 | ||||
-rw-r--r-- | pkg/commands/files_test.go | 8 | ||||
-rw-r--r-- | pkg/commands/git.go | 2 | ||||
-rw-r--r-- | pkg/commands/loading_branches.go | 4 | ||||
-rw-r--r-- | pkg/commands/loading_commits.go | 2 | ||||
-rw-r--r-- | pkg/commands/oscommands/os.go | 4 | ||||
-rw-r--r-- | pkg/commands/oscommands/os_default_test.go | 4 | ||||
-rw-r--r-- | pkg/commands/oscommands/os_windows_test.go | 2 | ||||
-rw-r--r-- | pkg/commands/stash_entries.go | 2 | ||||
-rw-r--r-- | pkg/commands/stash_entries_test.go | 2 |
16 files changed, 28 insertions, 33 deletions
diff --git a/pkg/commands/branches.go b/pkg/commands/branches.go index 20938621d..274168311 100644 --- a/pkg/commands/branches.go +++ b/pkg/commands/branches.go @@ -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 { diff --git a/pkg/commands/branches_test.go b/pkg/commands/branches_test.go index ee050e5be..7064f4968 100644 --- a/pkg/commands/branches_test.go +++ b/pkg/commands/branches_test.go @@ -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) } diff --git a/pkg/commands/commits.go b/pkg/commands/commits.go index 269eef073..447e9adb8 100644 --- a/pkg/commands/commits.go +++ b/pkg/commands/commits.go @@ -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)) diff --git a/pkg/commands/commits_test.go b/pkg/commands/commits_test.go index 04a5c01d7..aed0ba5ff 100644 --- a/pkg/commands/commits_test.go +++ b/pkg/commands/commits_test.go @@ -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) }) diff --git a/pkg/commands/config.go b/pkg/commands/config.go index 922e4f580..34126788d 100644 --- a/pkg/commands/config.go +++ b/pkg/commands/config.go @@ -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 } diff --git a/pkg/commands/dummies.go b/pkg/commands/dummies.go index 2e74dbc12..c17179c8e 100644 --- a/pkg/commands/dummies.go +++ b/pkg/commands/dummies.go @@ -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 }, } diff --git a/pkg/commands/files.go b/pkg/commands/files.go index 289337b70..28f37612f 100644 --- a/pkg/commands/files.go +++ b/pkg/commands/files.go @@ -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 } diff --git a/pkg/commands/files_test.go b/pkg/commands/files_test.go index 6965f82c2..4e7a077c7 100644 --- a/pkg/commands/files_test.go +++ b/pkg/commands/files_test.go @@ -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) diff --git a/pkg/commands/git.go b/pkg/commands/git.go index a29f519d6..cdccfc29c 100644 --- a/pkg/commands/git.go +++ b/pkg/commands/git.go @@ -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, diff --git a/pkg/commands/loading_branches.go b/pkg/commands/loading_branches.go index b79fd5640..0c850649f 100644 --- a/pkg/commands/loading_branches.go +++ b/pkg/commands/loading_branches.go @@ -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), diff --git a/pkg/commands/loading_commits.go b/pkg/commands/loading_commits.go index 6f0935054..52955eef3 100644 --- a/pkg/commands/loading_commits.go +++ b/pkg/commands/loading_commits.go @@ -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 := "" diff --git a/pkg/commands/oscommands/os.go b/pkg/commands/oscommands/os.go index f28f28c06..931be80b7 100644 --- a/pkg/commands/oscommands/os.go +++ b/pkg/commands/oscommands/os.go @@ -485,3 +485,7 @@ func sanitisedCommandOutput(output []byte, err error) (string, error) { } return outputString, nil } + +func GetTempDir() string { + return filepath.Join(os.TempDir(), "lazygit") +} diff --git a/pkg/commands/oscommands/os_default_test.go b/pkg/commands/oscommands/os_default_test.go index 5e15b1498..60b45f0dd 100644 --- a/pkg/commands/oscommands/os_default_test.go +++ b/pkg/commands/oscommands/os_default_test.go @@ -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)) } diff --git a/pkg/commands/oscommands/os_windows_test.go b/pkg/commands/oscommands/os_windows_test.go index 720f2705a..60853b841 100644 --- a/pkg/commands/oscommands/os_windows_test.go +++ b/pkg/commands/oscommands/os_windows_test.go @@ -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)) } diff --git a/pkg/commands/stash_entries.go b/pkg/commands/stash_entries.go index e557ba529..f80b7a858 100644 --- a/pkg/commands/stash_entries.go +++ b/pkg/commands/stash_entries.go @@ -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 diff --git a/pkg/commands/stash_entries_test.go b/pkg/commands/stash_entries_test.go index 29a9dc36f..03b630b33 100644 --- a/pkg/commands/stash_entries_test.go +++ b/pkg/commands/stash_entries_test.go @@ -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) }) |