summaryrefslogtreecommitdiffstats
path: root/pkg
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2021-10-23 09:52:19 +1100
committerJesse Duffield <jessedduffield@gmail.com>2021-10-23 10:26:47 +1100
commitb6a5e9d615f0fee7d76f5db33ff48bf32f0ef98b (patch)
tree32644c7c8810c2217cb26d750e5eafee7e07760f /pkg
parent5011cac7ea2b1d8ce9d9976b59c17f579c270fd9 (diff)
use cached git config
Diffstat (limited to 'pkg')
-rw-r--r--pkg/app/app.go20
-rw-r--r--pkg/commands/config.go18
-rw-r--r--pkg/commands/config_test.go70
-rw-r--r--pkg/commands/dummies.go11
-rw-r--r--pkg/commands/files.go2
-rw-r--r--pkg/commands/files_test.go66
-rw-r--r--pkg/commands/git.go37
-rw-r--r--pkg/commands/git_config/cached_git_config.go59
-rw-r--r--pkg/commands/git_config/cached_git_config_test.go116
-rw-r--r--pkg/commands/git_config/fake_git_config.go22
-rw-r--r--pkg/commands/git_config/get_key.go (renamed from pkg/commands/gitconfig.go)2
-rw-r--r--pkg/commands/git_test.go3
-rw-r--r--pkg/commands/loading_files.go2
-rw-r--r--pkg/commands/pull_request_default_test.go6
-rw-r--r--pkg/commands/pull_request_windows_test.go6
-rw-r--r--pkg/commands/remotes.go2
-rw-r--r--pkg/commands/sync.go4
-rw-r--r--pkg/commands/sync_test.go112
-rw-r--r--pkg/gui/recent_repos_panel.go3
19 files changed, 283 insertions, 278 deletions
diff --git a/pkg/app/app.go b/pkg/app/app.go
index e1d30d841..bb7485cca 100644
--- a/pkg/app/app.go
+++ b/pkg/app/app.go
@@ -4,8 +4,18 @@ import (
"bufio"
"errors"
"fmt"
+ "io"
+ "io/ioutil"
+ "log"
+ "os"
+ "path/filepath"
+ "regexp"
+ "strconv"
+ "strings"
+
"github.com/aybabtme/humanlog"
"github.com/jesseduffield/lazygit/pkg/commands"
+ "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/env"
@@ -13,14 +23,6 @@ import (
"github.com/jesseduffield/lazygit/pkg/i18n"
"github.com/jesseduffield/lazygit/pkg/updates"
"github.com/sirupsen/logrus"
- "io"
- "io/ioutil"
- "log"
- "os"
- "path/filepath"
- "regexp"
- "strconv"
- "strings"
)
// App struct
@@ -125,7 +127,7 @@ func NewApp(config config.AppConfigurer, filterPath string) (*App, error) {
return app, err
}
- app.GitCommand, err = commands.NewGitCommand(app.Log, app.OSCommand, app.Tr, app.Config)
+ app.GitCommand, err = commands.NewGitCommand(app.Log, app.OSCommand, app.Tr, app.Config, git_config.NewStdCachedGitConfig(app.Log))
if err != nil {
return app, err
}
diff --git a/pkg/commands/config.go b/pkg/commands/config.go
index 9600c3403..922e4f580 100644
--- a/pkg/commands/config.go
+++ b/pkg/commands/config.go
@@ -15,12 +15,8 @@ func (c *GitCommand) ConfiguredPager() string {
if os.Getenv("PAGER") != "" {
return os.Getenv("PAGER")
}
- output, err := c.RunCommandWithOutput("git config --get-all core.pager")
- if err != nil {
- return ""
- }
- trimmedOutput := strings.TrimSpace(output)
- return strings.Split(trimmedOutput, "\n")[0]
+ output := c.GitConfig.Get("core.pager")
+ return strings.Split(output, "\n")[0]
}
func (c *GitCommand) GetPager(width int) string {
@@ -42,11 +38,6 @@ func (c *GitCommand) colorArg() string {
return c.Config.GetUserConfig().Git.Paging.ColorArg
}
-func (c *GitCommand) GetConfigValue(key string) string {
- output, _ := c.getGitConfigValue(key)
- return output
-}
-
// 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 {
@@ -55,8 +46,5 @@ func (c *GitCommand) UsingGpg() bool {
return false
}
- gpgsign := c.GetConfigValue("commit.gpgsign")
- value := strings.ToLower(gpgsign)
-
- return value == "true" || value == "1" || value == "yes" || value == "on"
+ return c.GitConfig.GetBool("commit.gpgsign")
}
diff --git a/pkg/commands/config_test.go b/pkg/commands/config_test.go
deleted file mode 100644
index c16b53901..000000000
--- a/pkg/commands/config_test.go
+++ /dev/null
@@ -1,70 +0,0 @@
-package commands
-
-import (
- "testing"
-
- "github.com/stretchr/testify/assert"
-)
-
-// TestGitCommandUsingGpg is a function.
-func TestGitCommandUsingGpg(t *testing.T) {
- type scenario struct {
- testName string
- getGitConfigValue func(string) (string, error)
- test func(bool)
- }
-
- scenarios := []scenario{
- {
- "Option global and local config commit.gpgsign is not set",
- func(string) (string, error) { return "", nil },
- func(gpgEnabled bool) {
- assert.False(t, gpgEnabled)
- },
- },
- {
- "Option commit.gpgsign is true",
- func(string) (string, error) {
- return "True", nil
- },
- func(gpgEnabled bool) {
- assert.True(t, gpgEnabled)
- },
- },
- {
- "Option commit.gpgsign is on",
- func(string) (string, error) {
- return "ON", nil
- },
- func(gpgEnabled bool) {
- assert.True(t, gpgEnabled)
- },
- },
- {
- "Option commit.gpgsign is yes",
- func(string) (string, error) {
- return "YeS", nil
- },
- func(gpgEnabled bool) {
- assert.True(t, gpgEnabled)
- },
- },
- {
- "Option commit.gpgsign is 1",
- func(string) (string, error) {
- return "1", nil
- },
- func(gpgEnabled bool) {
- assert.True(t, gpgEnabled)
- },
- },
- }
-
- for _, s := range scenarios {
- t.Run(s.testName, func(t *testing.T) {
- gitCmd := NewDummyGitCommand()
- gitCmd.getGitConfigValue = s.getGitConfigValue
- s.test(gitCmd.UsingGpg())
- })
- }
-}
diff --git a/pkg/commands/dummies.go b/pkg/commands/dummies.go
index b1b6e9441..a8178385d 100644
--- a/pkg/commands/dummies.go
+++ b/pkg/commands/dummies.go
@@ -1,6 +1,7 @@
package commands
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/i18n"
@@ -16,10 +17,10 @@ func NewDummyGitCommand() *GitCommand {
func NewDummyGitCommandWithOSCommand(osCommand *oscommands.OSCommand) *GitCommand {
newAppConfig := config.NewDummyAppConfig()
return &GitCommand{
- Log: utils.NewDummyLog(),
- OSCommand: osCommand,
- Tr: i18n.NewTranslationSet(utils.NewDummyLog(), newAppConfig.GetUserConfig().Gui.Language),
- Config: newAppConfig,
- getGitConfigValue: func(string) (string, error) { return "", nil },
+ Log: utils.NewDummyLog(),
+ OSCommand: osCommand,
+ Tr: i18n.NewTranslationSet(utils.NewDummyLog(), newAppConfig.GetUserConfig().Gui.Language),
+ Config: newAppConfig,
+ GitConfig: git_config.NewFakeGitConfig(map[string]string{}),
}
}
diff --git a/pkg/commands/files.go b/pkg/commands/files.go
index 462b5b899..07c4c4d28 100644
--- a/pkg/commands/files.go
+++ b/pkg/commands/files.go
@@ -331,7 +331,7 @@ func (c *GitCommand) EditFileCmdStr(filename string, lineNumber int) (string, er
editor := c.Config.GetUserConfig().OS.EditCommand
if editor == "" {
- editor = c.GetConfigValue("core.editor")
+ editor = c.GitConfig.Get("core.editor")
}
if editor == "" {
diff --git a/pkg/commands/files_test.go b/pkg/commands/files_test.go
index 0d718a7bf..f72b47ca0 100644
--- a/pkg/commands/files_test.go
+++ b/pkg/commands/files_test.go
@@ -6,6 +6,7 @@ import (
"os/exec"
"testing"
+ "github.com/jesseduffield/lazygit/pkg/commands/git_config"
"github.com/jesseduffield/lazygit/pkg/commands/models"
"github.com/jesseduffield/lazygit/pkg/secureexec"
"github.com/jesseduffield/lazygit/pkg/test"
@@ -523,24 +524,21 @@ func TestGitCommandApplyPatch(t *testing.T) {
}
}
-// TestGitCommandDiscardOldFileChanges is a function.
func TestGitCommandDiscardOldFileChanges(t *testing.T) {
type scenario struct {
- testName string
- getGitConfigValue func(string) (string, error)
- commits []*models.Commit
- commitIndex int
- fileName string
- command func(string, ...string) *exec.Cmd
- test func(error)
+ testName string
+ gitConfigMockResponses map[string]string
+ commits []*models.Commit
+ commitIndex int
+ fileName string
+ command func(string, ...string) *exec.Cmd
+ test func(error)
}
scenarios := []scenario{
{
"returns error when index outside of range of commits",
- func(string) (string, error) {
- return "", nil
- },
+ nil,
[]*models.Commit{},
0,
"test999.txt",
@@ -551,9 +549,7 @@ func TestGitCommandDiscardOldFileChanges(t *testing.T) {
},
{
"returns error when using gpg",
- func(string) (string, error) {
- return "true", nil
- },
+ map[string]string{"commit.gpgsign": "true"},
[]*models.Commit{{Name: "commit", Sha: "123456"}},
0,
"test999.txt",
@@ -564,9 +560,7 @@ func TestGitCommandDiscardOldFileChanges(t *testing.T) {
},
{
"checks out file if it already existed",
- func(string) (string, error) {
- return "", nil
- },
+ nil,
[]*models.Commit{
{Name: "commit", Sha: "123456"},
{Name: "commit2", Sha: "abcdef"},
@@ -608,7 +602,7 @@ func TestGitCommandDiscardOldFileChanges(t *testing.T) {
for _, s := range scenarios {
t.Run(s.testName, func(t *testing.T) {
gitCmd.OSCommand.Command = s.command
- gitCmd.getGitConfigValue = s.getGitConfigValue
+ gitCmd.GitConfig = git_config.NewFakeGitConfig(s.gitConfigMockResponses)
s.test(gitCmd.DiscardOldFileChanges(s.commits, s.commitIndex, s.fileName))
})
}
@@ -725,7 +719,7 @@ func TestEditFileCmdStr(t *testing.T) {
configEditCommandTemplate string
command func(string, ...string) *exec.Cmd
getenv func(string) string
- getGitConfigValue func(string) (string, error)
+ gitConfigMockResponses map[string]string
test func(string, error)
}
@@ -740,9 +734,7 @@ func TestEditFileCmdStr(t *testing.T) {
func(env string) string {
return ""
},
- func(cf string) (string, error) {
- return "", nil
- },
+ nil,
func(cmdStr string, err error) {
assert.EqualError(t, err, "No editor defined in config file, $GIT_EDITOR, $VISUAL, $EDITOR, or git config")
},
@@ -758,9 +750,7 @@ func TestEditFileCmdStr(t *testing.T) {
func(env string) string {
return ""
},
- func(cf string) (string, error) {
- return "", nil
- },
+ nil,
func(cmdStr string, err error) {
assert.NoError(t, err)
assert.Equal(t, "nano "+gitCmd.OSCommand.Quote("test"), cmdStr)
@@ -777,9 +767,7 @@ func TestEditFileCmdStr(t *testing.T) {
func(env string) string {
return ""
},
- func(cf string) (string, error) {
- return "nano", nil
- },
+ map[string]string{"core.editor": "nano"},
func(cmdStr string, err error) {
assert.NoError(t, err)
assert.Equal(t, "nano "+gitCmd.OSCommand.Quote("test"), cmdStr)
@@ -800,9 +788,7 @@ func TestEditFileCmdStr(t *testing.T) {
return ""
},
- func(cf string) (string, error) {
- return "", nil
- },
+ nil,
func(cmdStr string, err error) {
assert.NoError(t, err)
},
@@ -822,9 +808,7 @@ func TestEditFileCmdStr(t *testing.T) {
return ""
},
- func(cf string) (string, error) {
- return "", nil
- },
+ nil,
func(cmdStr string, err error) {
assert.NoError(t, err)
assert.Equal(t, "emacs "+gitCmd.OSCommand.Quote("test"), cmdStr)
@@ -841,9 +825,7 @@ func TestEditFileCmdStr(t *testing.T) {
func(env string) string {
return ""
},
- func(cf string) (string, error) {
- return "", nil
- },
+ nil,
func(cmdStr string, err error) {
assert.NoError(t, err)
assert.Equal(t, "vi "+gitCmd.OSCommand.Quote("test"), cmdStr)
@@ -860,9 +842,7 @@ func TestEditFileCmdStr(t *testing.T) {
func(env string) string {
return ""
},
- func(cf string) (string, error) {
- return "", nil
- },
+ nil,
func(cmdStr string, err error) {
assert.NoError(t, err)
assert.Equal(t, "vi "+gitCmd.OSCommand.Quote("file/with space"), cmdStr)
@@ -879,9 +859,7 @@ func TestEditFileCmdStr(t *testing.T) {
func(env string) string {
return ""
},
- func(cf string) (string, error) {
- return "", nil
- },
+ nil,
func(cmdStr string, err error) {
assert.NoError(t, err)
assert.Equal(t, "vim +1 "+gitCmd.OSCommand.Quote("open file/at line"), cmdStr)
@@ -894,7 +872,7 @@ func TestEditFileCmdStr(t *testing.T) {
gitCmd.Config.GetUserConfig().OS.EditCommandTemplate = s.configEditCommandTemplate
gitCmd.OSCommand.Command = s.command
gitCmd.OSCommand.Getenv = s.getenv
- gitCmd.getGitConfigValue = s.getGitConfigValue
+ gitCmd.GitConfig = git_config.NewFakeGitConfig(s.gitConfigMockResponses)
s.test(gitCmd.EditFileCmdStr(s.filename, 1))
}
}
diff --git a/pkg/commands/git.go b/pkg/commands/git.go
index de7569d81..a1a925de7 100644
--- a/pkg/commands/git.go
+++ b/pkg/commands/git.go
@@ -10,6 +10,7 @@ import (
"github.com/go-errors/errors"
gogit "github.com/jesseduffield/go-git/v5"
+ "github.com/jesseduffield/lazygit/pkg/commands/git_config"
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
"github.com/jesseduffield/lazygit/pkg/commands/patch"
"github.com/jesseduffield/lazygit/pkg/config"
@@ -32,32 +33,32 @@ type GitCommand struct {
Repo *gogit.Repository
Tr *i18n.TranslationSet
Config config.AppConfigurer
- getGitConfigValue func(string) (string, error)
DotGitDir string
onSuccessfulContinue func() error
PatchManager *patch.PatchManager
+ GitConfig git_config.IGitConfig
// Push to current determines whether the user has configured to push to the remote branch of the same name as the current or not
PushToCurrent bool
}
// NewGitCommand it runs git commands
-func NewGitCommand(log *logrus.Entry, osCommand *oscommands.OSCommand, tr *i18n.TranslationSet, config config.AppConfigurer) (*GitCommand, error) {
+func NewGitCommand(
+ log *logrus.Entry,
+ osCommand *oscommands.OSCommand,
+ tr *i18n.TranslationSet,
+ config config.AppConfigurer,
+ gitConfig git_config.IGitConfig,
+) (*GitCommand, error) {
var repo *gogit.Repository
- // see what our default push behaviour is
- output, err := osCommand.RunCommandWithOutput("git config --get push.default")
- pushToCurrent := false
- if err != nil {
- log.Errorf("error reading git config: %v", err)
- } else {
- pushToCurrent = strings.TrimSpace(output) == "current"
- }
+ pushToCurrent := gitConfig.Get("push.default") == "current"
if err := navigateToRepoRootDirectory(os.Stat, os.Chdir); err != nil {
return nil, err
}
+ var err error
if repo, err = setupRepository(gogit.PlainOpen, tr.GitconfigParseErr); err != nil {
return nil, err
}
@@ -68,14 +69,14 @@ func NewGitCommand(log *logrus.Entry, osCommand *oscommands.OSCommand, tr *i18n.
}
gitCommand := &GitCommand{
- Log: log,
- OSCommand: osCommand,
- Tr: tr,
- Repo: repo,
- Config: config,
- getGitConfigValue: getGitConfigValue,
- DotGitDir: dotGitDir,
- PushToCurrent: pushToCurrent,
+ Log: log,
+ OSCommand: osCommand,
+ Tr: tr,
+ Repo: repo,
+ Config: config,
+ DotGitDir: dotGitDir,
+ PushToCurrent: pushToCurrent,
+ GitConfig: gitConfig,
}
gitCommand.PatchManager = patch.NewPatchManager(log, gitCommand.ApplyPatch, gitCommand.ShowFileDiff)
diff --git a/pkg/commands/git_config/cached_git_config.go b/pkg/commands/git_config/cached_git_config.go
new file mode 100644
index 000000000..e2b83bad8
--- /dev/null
+++ b/pkg/commands/git_config/cached_git_config.go
@@ -0,0 +1,59 @@
+package git_config
+
+import (
+ "strings"
+
+ "github.com/sirupsen/logrus"
+)
+
+type IGitConfig interface {
+ Get(string) string
+ GetBool(string) bool
+}
+
+type CachedGitConfig struct {
+ cache map[string]string
+ getKey func(string) (string, error)
+ log *logrus.Entry
+}
+
+func NewStdCachedGitConfig(log *logrus.Entry) *CachedGitConfig {
+ return NewCachedGitConfig(getGitConfigValue, log)
+}
+
+func NewCachedGitConfig(getKey func(string) (string, error), log *logrus.Entry) *CachedGitConfig {
+ return &CachedGitConfig{
+ cache: make(map[string]string),
+ getKey: getKey,
+ log: log,
+ }
+}
+
+func (self *CachedGitConfig) Get(key string) string {
+ if value, ok := self.cache[key]; ok {
+ self.log.Debugf("using cache for key " + key)
+ return value
+ }
+
+ value := self.getAux(key)
+ self.cache[key] = value
+ return value
+}
+
+func (self *CachedGitConfig) getAux(key string) string {
+ value, err := self.getKey(key)
+ if err != nil {
+ self.log.Debugf("Error getting git config value for key: " + key + ". Error: " + err.Error())
+ return ""
+ }
+ return strings.TrimSpace(value)
+}
+
+func (self *CachedGitConfig) GetBool(key string) bool {
+ return isTruthy(self.Get(key))
+}
+
+func isTruthy(value string) bool {
+ lcValue := strings.ToLower(value)
+ return lcValue == "true" || lcValue == "1" || lcValue == "yes" || lcValue == "on"
+}
diff --git a/pkg/commands/git_config/cached_git_config_test.go b/pkg/commands/git_config/cached_git_config_test.go
new file mode 100644
index 000000000..f03535a6e
--- /dev/null
+++ b/pkg/commands/git_config/cached_git_config_test.go
@@ -0,0 +1,116 @@
+package git_config
+
+import (
+ "testing"
+
+ "github.com/jesseduffield/lazygit/pkg/utils"
+ "github.com/stretchr/testify/assert"
+)
+
+func TestGetBool(t *testing.T) {
+ type scenario struct {
+ testName string
+ mockResponses map[string]string
+ expected bool
+ }
+
+ scenarios := []scenario{
+ {
+ "Option global and local config commit.gpgsign is not set",
+ map[string]string{},
+ false,
+ },
+ {
+ "Some other random key is set",
+ map[string]string{"blah": "blah"},
+ false,
+ },
+ {
+ "Option commit.gpgsign is true",
+ map[string]string{"commit.gpgsign": "True"},
+ true,
+ },
+ {
+ "Option commit.gpgsign is on",
+ map[string]string{"commit.gpgsign": "ON"},
+ true,
+ },
+ {
+ "Option commit.gpgsign is yes",
+ map[string]string{"commit.gpgsign": "YeS"},
+ true,
+ },
+ {
+ "Option commit.gpgsign is 1",
+ map[string]string{"commit.gpgsign": "1"},
+ true,
+ },
+ }
+
+ for _, s := range scenarios {
+ s := s
+ t.Run(s.testName, func(t *testing.T) {
+ fake := NewFakeGitConfig(s.mockResponses)
+ real := NewCachedGitConfig(
+ func(key string) (string, error) {
+ return fake.Get(key), nil
+ },
+ utils.NewDummyLog(),
+ )
+ result := real.GetBool("commit.gpgsign")
+ assert.Equal(t, s.expected, result)
+ })
+ }
+}
+
+func TestGet(t *testing.T) {
+ type scenario struct {
+ testName string
+ mockResponses map[string]string
+ expected string
+ }
+
+ scenarios := []scenario{
+ {
+ "not set",
+ map[string]string{},
+ "",
+ },
+ {
+ "is set",
+ map[string]string{"commit.gpgsign": "blah"},
+ "blah",
+ },
+ }
+
+ for _, s := range scenarios {
+ s := s
+ t.Run(s.testName, func(t *testing.T) {
+ fake := NewFakeGitConfig(s.mockResponses)
+ real := NewCachedGitConfig(
+ func(key string) (string, error) {
+ return fake.Get(key), nil
+ },
+ utils.NewDummyLog(),
+ )
+ result := real.Get("commit.gpgsign")
+ assert.Equal(t, s.expected, result)
+ })
+ }
+
+ // verifying that the cache is used
+ count := 0
+ real := NewCachedGitConfig(
+ func(key string) (string, error) {
+ count++
+ assert.Equal(t, "commit.gpgsign", key)
+ return "blah", nil
+ },
+ utils.NewDummyLog(),
+ )
+ result := real.Get("commit.gpgsign")
+ assert.Equal(t, "blah", result)
+ result = real.Get("commit.gpgsign")
+ assert.Equal(t, "blah", result)
+ assert.Equal(t, 1, count)
+}
diff --git a/pkg/commands/git_config/fake_git_config.go b/pkg/commands/git_config/fake_git_config.go
new file mode 100644
index 000000000..f010efd8c
--- /dev/null
+++ b/pkg/commands/git_config/fake_git_config.go
@@ -0,0 +1,22 @@
+package git_config
+
+type FakeGitConfig struct {
+ mockResponses map[string]string
+}
+
+func NewFakeGitConfig(mockResponses map[string]string) *FakeGitConfig {
+ return &FakeGitConfig{
+ mockResponses: mockResponses,
+ }
+}
+
+func (self *FakeGitConfig) Get(key string) string {
+ if self.mockResponses == nil {
+ return ""
+ }
+ return self.mockResponses[key]
+}
+
+func (self *FakeGitConfig) GetBool(key string) bool {
+ return isTruthy(self.Get(key))
+}
diff --git a/pkg/commands/gitconfig.go b/pkg/commands/git_config/get_key.go
index dbe72c570..85892ea2d 100644
--- a/pkg/commands/gitconfig.go
+++ b/pkg/commands/git_config/get_key.go
@@ -1,4 +1,4 @@
-package commands
+package git_config
import (
"bytes"
diff --git a/pkg/commands/git_test.go b/pkg/commands/git_test.go
index 6891fdc53..19eabd583 100644
--- a/pkg/commands/git_test.go
+++ b/pkg/commands/git_test.go
@@ -8,6 +8,7 @@ import (
"github.com/go-errors/errors"
gogit "github.com/jesseduffield/go-git/v5"
+ "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/i18n"
@@ -210,7 +211,7 @@ func TestNewGitCommand(t *testing.T) {
t.Run(s.testName, func(t *testing.T) {
s.setup()
newAppConfig := config.NewDummyAppConfig()
- s.test(NewGitCommand(utils.NewDummyLog(), oscommands.NewDummyOSCommand(), i18n.NewTranslationSet(utils.NewDummyLog(), newAppConfig.GetUserConfig().Gui.Language), newAppConfig))
+ s.test(NewGitCommand(utils.NewDummyLog(), oscommands.NewDummyOSCommand(), i18n.NewTranslationSet(utils.NewDummyLog(), newAppConfig.GetUserConfig().Gui.Language), newAppConfig, git_config.NewFakeGitConfig(nil)))
})
}
}
diff --git a/pkg/commands/loading_files.go b/pkg/commands/loading_files.go
index d3638a724..098948ed4 100644
--- a/pkg/commands/loading_files.go
+++ b/pkg/commands/loading_files.go
@@ -15,7 +15,7 @@ type GetStatusFileOptions struct {
func (c *GitCommand) GetStatusFiles(opts GetStatusFileOptions) []*models.File {
// check if config wants us ignoring untracked files
- untrackedFilesSetting := c.GetConfigValue("status.showUntrackedFiles")
+ untrackedFilesSetting := c.GitConfig.Get("status.showUntrackedFiles")
if untrackedFilesSetting == "" {
untrackedFilesSetting = "all"
diff --git a/pkg/commands/pull_request_default_test.go b/pkg/commands/pull_request_default_test.go
index 7f0a1ba5d..e1ce61a5a 100644
--- a/pkg/commands/pull_request_default_test.go
+++ b/pkg/commands/pull_request_default_test.go
@@ -8,6 +8,7 @@ import (
"strings"
"testing"
+ "github.com/jesseduffield/lazygit/pkg/commands/git_config"
"github.com/jesseduffield/lazygit/pkg/secureexec"
"github.com/stretchr/testify/assert"
)
@@ -247,10 +248,7 @@ func TestCreatePullRequest(t *testing.T) {
"invalid.work.com": "noservice:invalid.work.com",
"noservice.work.com": "noservice.work.com",
}
- gitCommand.getGitConfigValue = func(path string) (string, error) {
- assert.Equal(t, path, "remote.origin.url")
- return s.remoteUrl, nil
- }
+ gitCommand.GitConfig = git_config.NewFakeGitConfig(map[string]string{"remote.origin.url": s.remoteUrl})
dummyPullRequest := NewPullRequest(gitCommand)
s.test(dummyPullRequest.Create(s.from, s.to))
})
diff --git a/pkg/commands/pull_request_windows_test.go b/pkg/commands/pull_request_windows_test.go
index b0eee37b8..73e91f157 100644
--- a/pkg/commands/pull_request_windows_test.go
+++ b/pkg/commands/pull_request_windows_test.go
@@ -8,6 +8,7 @@ import (
"strings"
"testing"
+ "github.com/jesseduffield/lazygit/pkg/commands/git_config"
"github.com/jesseduffield/lazygit/pkg/secureexec"
"github.com/stretchr/testify/assert"
)
@@ -247,10 +248,7 @@ func TestCreatePullRequestOnWindows(t *testing.T) {
"invalid.work.com": "noservice:invalid.work.com",
"noservice.work.com": "noservice.work.com",
}
- gitCommand.getGitConfigValue = func(path string) (string, error) {
- assert.Equal(t, path, "remote.origin.url")
- return s.remoteUrl, nil
- }
+ gitCommand.GitConfig = git_config.NewFakeGitConfig(map[string]string{"remote.origin.url": s.remoteUrl})
dummyPullRequest := NewPullRequest(gitCommand)
s.test(dummyPullRequest.Create(s.from, s.to))
})
diff --git a/pkg/commands/remotes.go b/pkg/commands/remotes.go
index b56893817..0839f9583 100644
--- a/pkg/commands/remotes.go
+++ b/pkg/commands/remotes.go
@@ -38,5 +38,5 @@ func (c *GitCommand) CheckRemoteBranchExists(branchName string) bool {
// GetRemoteURL returns current repo remote url
func (c *GitCommand) GetRemoteURL() string {
- return c.GetConfigValue("remote.origin.url")
+ return c.GitConfig.Get("remote.origin.url")
}
diff --git a/pkg/commands/sync.go b/pkg/commands/sync.go
index 7051f2236..3f94c5f4e 100644
--- a/pkg/commands/sync.go
+++ b/pkg/commands/sync.go
@@ -18,10 +18,6 @@ type PushOpts struct {
func (c *GitCommand) Push(opts PushOpts) error {
cmdStr := "git push"
- if c.GetConfigValue("push.followTags") != "false" {
- cmdStr += " --follow-tags"
- }
-
if opts.Force {
cmdStr += " --force-with-lease"
}
diff --git a/pkg/commands/sync_test.go b/pkg/commands/sync_test.go
index f793639be..924bd56ef 100644
--- a/pkg/commands/sync_test.go
+++ b/pkg/commands/sync_test.go
@@ -11,11 +11,10 @@ import (
// TestGitCommandPush is a function.
func TestGitCommandPush(t *testing.T) {
type scenario struct {
- testName string
- getGitConfigValue func(string) (string, error)
- command func(string, ...string) *exec.Cmd
- opts PushOpts
- test func(error)
+ testName string
+ command func(string, ...string) *exec.Cmd
+ opts PushOpts
+ test func(error)
}
prompt := func(passOrUname string) string {
@@ -24,13 +23,10 @@ func TestGitCommandPush(t *testing.T) {
scenarios := []scenario{
{
- "Push with force disabled, follow-tags on",
- func(string) (string, error) {
- return "", nil
- },
+ "Push with force disabled",
func(cmd string, args ...string) *exec.Cmd {
assert.EqualValues(t, "git", cmd)
- assert.EqualValues(t, []string{"push", "--follow-tags"}, args)
+ assert.EqualValues(t, []string{"push"}, args)
return secureexec.Command("echo")
},
@@ -40,13 +36,10 @@ func TestGitCommandPush(t *testing.T) {
},
},
{
- "Push with force enabled, follow-tags on",
- func(string) (string, error) {
- return "", nil
- },
+ "Push with force enabled",
func(cmd string, args ...string) *exec.Cmd {
assert.EqualValues(t, "git", cmd)
- assert.EqualValues(t, []string{"push", "--follow-tags", "--force-with-lease"}, args)
+ assert.EqualValues(t, []string{"push", "--force-with-lease"}, args)
return secureexec.Command("echo")
},
@@ -56,29 +49,10 @@ func TestGitCommandPush(t *testing.T) {
},
},
{
- "Push with force disabled, follow-tags off",
- func(string) (string, error) {
- return "false", nil
- },
+ "Push with an error occurring",
func(cmd string, args ...string) *exec.Cmd {
assert.EqualValues(t, "git", cmd)
assert.EqualValues(t, []string{"push"}, args)
-
- return secureexec.Command("echo")