1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-05-17 22:32:58 +02:00

Read pull mode from gitconfig lazily

This commit is contained in:
Emiliano Ruiz Carletti 2021-04-18 18:07:13 -03:00 committed by Jesse Duffield
parent 46e500dc28
commit c57a0077d0
2 changed files with 31 additions and 2 deletions

View File

@ -323,7 +323,7 @@ func GetDefaultConfig() *UserConfig {
Args: "", Args: "",
}, },
Pull: PullConfig{ Pull: PullConfig{
Mode: "merge", Mode: "auto",
}, },
SkipHookPrefix: "WIP", SkipHookPrefix: "WIP",
AutoFetch: true, AutoFetch: true,

View File

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
"regexp" "regexp"
"strings" "strings"
"sync"
"github.com/jesseduffield/gocui" "github.com/jesseduffield/gocui"
"github.com/jesseduffield/lazygit/pkg/commands" "github.com/jesseduffield/lazygit/pkg/commands"
@ -659,7 +660,7 @@ func (gui *Gui) pullFiles(opts PullFilesOptions) error {
return err return err
} }
mode := gui.Config.GetUserConfig().Git.Pull.Mode mode := gui.getPullMode()
// TODO: this doesn't look like a good idea. Why the goroutine? // TODO: this doesn't look like a good idea. Why the goroutine?
go utils.Safe(func() { _ = gui.pullWithMode(mode, opts) }) go utils.Safe(func() { _ = gui.pullWithMode(mode, opts) })
@ -667,6 +668,34 @@ func (gui *Gui) pullFiles(opts PullFilesOptions) error {
return nil return nil
} }
func (gui *Gui) getPullMode() string {
mode := &gui.Config.GetUserConfig().Git.Pull.Mode
if *mode == "auto" {
var isRebase bool
var isFf bool
var wg sync.WaitGroup
wg.Add(2)
go func() {
isRebase = gui.GitCommand.GetConfigValue("pull.rebase") == "true"
wg.Done()
}()
go func() {
isFf = gui.GitCommand.GetConfigValue("pull.ff") == "true"
wg.Done()
}()
wg.Wait()
if isRebase {
*mode = "rebase"
} else if isFf {
*mode = "ff-only"
} else {
*mode = "merge"
}
}
return *mode
}
func (gui *Gui) pullWithMode(mode string, opts PullFilesOptions) error { func (gui *Gui) pullWithMode(mode string, opts PullFilesOptions) error {
gui.Mutexes.FetchMutex.Lock() gui.Mutexes.FetchMutex.Lock()
defer gui.Mutexes.FetchMutex.Unlock() defer gui.Mutexes.FetchMutex.Unlock()