From d7865b38827809c011f7d81025b80162506e70de Mon Sep 17 00:00:00 2001 From: Emiliano Ruiz Carletti Date: Mon, 12 Apr 2021 23:56:25 -0300 Subject: [PATCH] Read pull mode from git configuration --- pkg/config/user_config.go | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/pkg/config/user_config.go b/pkg/config/user_config.go index 1312e4bd8..e4a10e10b 100644 --- a/pkg/config/user_config.go +++ b/pkg/config/user_config.go @@ -1,5 +1,9 @@ package config +import ( + "github.com/jesseduffield/lazygit/pkg/secureexec" +) + type UserConfig struct { Gui GuiConfig `yaml:"gui"` Git GitConfig `yaml:"git"` @@ -323,7 +327,7 @@ func GetDefaultConfig() *UserConfig { Args: "", }, Pull: PullConfig{ - Mode: "merge", + Mode: getPullModeFromGitConfig(), }, SkipHookPrefix: "WIP", AutoFetch: true, @@ -485,3 +489,17 @@ func GetDefaultConfig() *UserConfig { NotARepository: "prompt", } } + +func getPullModeFromGitConfig() string { + rebaseOut, rebaseErr := secureexec.Command("git config --get pull.rebase").Output() + if rebaseErr == nil && rebaseOut[0] == 't' { + return "rebase" + } + + ffOut, ffErr := secureexec.Command("git config --get pull.ff").Output() + if ffErr == nil && ffOut[0] == 't' { + return "ff-only" + } + + return "merge" +}