1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-07-28 16:02:01 +03:00

Remove deprecated edit configs

They were deprecated in April 2023 (see 046b0d9daa), so it's been well over a
year now.
This commit is contained in:
Stefan Haller
2025-07-08 16:07:46 +02:00
parent 41efd9a027
commit 73bf49f8d8
7 changed files with 0 additions and 336 deletions

View File

@ -5,7 +5,6 @@ import (
"strconv" "strconv"
"strings" "strings"
"github.com/go-errors/errors"
"github.com/jesseduffield/lazygit/pkg/config" "github.com/jesseduffield/lazygit/pkg/config"
"github.com/jesseduffield/lazygit/pkg/utils" "github.com/jesseduffield/lazygit/pkg/utils"
"github.com/samber/lo" "github.com/samber/lo"
@ -30,62 +29,7 @@ func (self *FileCommands) Cat(fileName string) (string, error) {
return string(buf), nil return string(buf), nil
} }
func (self *FileCommands) GetEditCmdStrLegacy(filename string, lineNumber int) (string, error) {
editor := self.UserConfig().OS.EditCommand
if editor == "" {
editor = self.config.GetCoreEditor()
}
if editor == "" {
editor = self.os.Getenv("GIT_EDITOR")
}
if editor == "" {
editor = self.os.Getenv("VISUAL")
}
if editor == "" {
editor = self.os.Getenv("EDITOR")
}
if editor == "" {
if err := self.cmd.New([]string{"which", "vi"}).DontLog().Run(); err == nil {
editor = "vi"
}
}
if editor == "" {
return "", errors.New("No editor defined in config file, $GIT_EDITOR, $VISUAL, $EDITOR, or git config")
}
templateValues := map[string]string{
"editor": editor,
"filename": self.cmd.Quote(filename),
"line": strconv.Itoa(lineNumber),
}
editCmdTemplate := self.UserConfig().OS.EditCommandTemplate
if len(editCmdTemplate) == 0 {
switch editor {
case "emacs", "nano", "vi", "vim", "nvim":
editCmdTemplate = "{{editor}} +{{line}} -- {{filename}}"
case "subl":
editCmdTemplate = "{{editor}} -- {{filename}}:{{line}}"
case "code":
editCmdTemplate = "{{editor}} -r --goto -- {{filename}}:{{line}}"
default:
editCmdTemplate = "{{editor}} -- {{filename}}"
}
}
return utils.ResolvePlaceholderString(editCmdTemplate, templateValues), nil
}
func (self *FileCommands) GetEditCmdStr(filenames []string) (string, bool) { func (self *FileCommands) GetEditCmdStr(filenames []string) (string, bool) {
// Legacy support for old config; to be removed at some point
if self.UserConfig().OS.Edit == "" && self.UserConfig().OS.EditCommandTemplate != "" {
// If multiple files are selected, we'll simply edit just the first one.
// It's not worth fixing this for the legacy support.
if cmdStr, err := self.GetEditCmdStrLegacy(filenames[0], 1); err == nil {
return cmdStr, true
}
}
template, suspend := config.GetEditTemplate(self.os.Platform.Shell, &self.UserConfig().OS, self.guessDefaultEditor) template, suspend := config.GetEditTemplate(self.os.Platform.Shell, &self.UserConfig().OS, self.guessDefaultEditor)
quotedFilenames := lo.Map(filenames, func(filename string, _ int) string { return self.cmd.Quote(filename) }) quotedFilenames := lo.Map(filenames, func(filename string, _ int) string { return self.cmd.Quote(filename) })
@ -98,13 +42,6 @@ func (self *FileCommands) GetEditCmdStr(filenames []string) (string, bool) {
} }
func (self *FileCommands) GetEditAtLineCmdStr(filename string, lineNumber int) (string, bool) { func (self *FileCommands) GetEditAtLineCmdStr(filename string, lineNumber int) (string, bool) {
// Legacy support for old config; to be removed at some point
if self.UserConfig().OS.EditAtLine == "" && self.UserConfig().OS.EditCommandTemplate != "" {
if cmdStr, err := self.GetEditCmdStrLegacy(filename, lineNumber); err == nil {
return cmdStr, true
}
}
template, suspend := config.GetEditAtLineTemplate(self.os.Platform.Shell, &self.UserConfig().OS, self.guessDefaultEditor) template, suspend := config.GetEditAtLineTemplate(self.os.Platform.Shell, &self.UserConfig().OS, self.guessDefaultEditor)
templateValues := map[string]string{ templateValues := map[string]string{
@ -117,13 +54,6 @@ func (self *FileCommands) GetEditAtLineCmdStr(filename string, lineNumber int) (
} }
func (self *FileCommands) GetEditAtLineAndWaitCmdStr(filename string, lineNumber int) string { func (self *FileCommands) GetEditAtLineAndWaitCmdStr(filename string, lineNumber int) string {
// Legacy support for old config; to be removed at some point
if self.UserConfig().OS.EditAtLineAndWait == "" && self.UserConfig().OS.EditCommandTemplate != "" {
if cmdStr, err := self.GetEditCmdStrLegacy(filename, lineNumber); err == nil {
return cmdStr
}
}
template := config.GetEditAtLineAndWaitTemplate(self.os.Platform.Shell, &self.UserConfig().OS, self.guessDefaultEditor) template := config.GetEditAtLineAndWaitTemplate(self.os.Platform.Shell, &self.UserConfig().OS, self.guessDefaultEditor)
templateValues := map[string]string{ templateValues := map[string]string{

View File

@ -3,180 +3,11 @@ package git_commands
import ( import (
"testing" "testing"
"github.com/go-errors/errors"
"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/config" "github.com/jesseduffield/lazygit/pkg/config"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
func TestEditFileCmdStrLegacy(t *testing.T) {
type scenario struct {
filename string
configEditCommand string
configEditCommandTemplate string
runner *oscommands.FakeCmdObjRunner
getenv func(string) string
gitConfigMockResponses map[string]string
test func(string, error)
}
scenarios := []scenario{
{
filename: "test",
configEditCommand: "",
configEditCommandTemplate: "{{editor}} {{filename}}",
runner: oscommands.NewFakeRunner(t).
ExpectArgs([]string{"which", "vi"}, "", errors.New("error")),
getenv: func(env string) string {
return ""
},
gitConfigMockResponses: nil,
test: func(cmdStr string, err error) {
assert.EqualError(t, err, "No editor defined in config file, $GIT_EDITOR, $VISUAL, $EDITOR, or git config")
},
},
{
filename: "test",
configEditCommand: "nano",
configEditCommandTemplate: "{{editor}} {{filename}}",
runner: oscommands.NewFakeRunner(t),
getenv: func(env string) string {
return ""
},
gitConfigMockResponses: nil,
test: func(cmdStr string, err error) {
assert.NoError(t, err)
assert.Equal(t, `nano "test"`, cmdStr)
},
},
{
filename: "test",
configEditCommand: "",
configEditCommandTemplate: "{{editor}} {{filename}}",
runner: oscommands.NewFakeRunner(t),
getenv: func(env string) string {
return ""
},
gitConfigMockResponses: map[string]string{"core.editor": "nano"},
test: func(cmdStr string, err error) {
assert.NoError(t, err)
assert.Equal(t, `nano "test"`, cmdStr)
},
},
{
filename: "test",
configEditCommand: "",
configEditCommandTemplate: "{{editor}} {{filename}}",
runner: oscommands.NewFakeRunner(t),
getenv: func(env string) string {
if env == "VISUAL" {
return "nano"
}
return ""
},
gitConfigMockResponses: nil,
test: func(cmdStr string, err error) {
assert.NoError(t, err)
assert.Equal(t, `nano "test"`, cmdStr)
},
},
{
filename: "test",
configEditCommand: "",
configEditCommandTemplate: "{{editor}} {{filename}}",
runner: oscommands.NewFakeRunner(t),
getenv: func(env string) string {
if env == "EDITOR" {
return "emacs"
}
return ""
},
gitConfigMockResponses: nil,
test: func(cmdStr string, err error) {
assert.NoError(t, err)
assert.Equal(t, `emacs "test"`, cmdStr)
},
},
{
filename: "test",
configEditCommand: "",
configEditCommandTemplate: "{{editor}} {{filename}}",
runner: oscommands.NewFakeRunner(t).
ExpectArgs([]string{"which", "vi"}, "/usr/bin/vi", nil),
getenv: func(env string) string {
return ""
},
gitConfigMockResponses: nil,
test: func(cmdStr string, err error) {
assert.NoError(t, err)
assert.Equal(t, `vi "test"`, cmdStr)
},
},
{
filename: "file/with space",
configEditCommand: "",
configEditCommandTemplate: "{{editor}} {{filename}}",
runner: oscommands.NewFakeRunner(t).
ExpectArgs([]string{"which", "vi"}, "/usr/bin/vi", nil),
getenv: func(env string) string {
return ""
},
gitConfigMockResponses: nil,
test: func(cmdStr string, err error) {
assert.NoError(t, err)
assert.Equal(t, `vi "file/with space"`, cmdStr)
},
},
{
filename: "open file/at line",
configEditCommand: "vim",
configEditCommandTemplate: "{{editor}} +{{line}} {{filename}}",
runner: oscommands.NewFakeRunner(t),
getenv: func(env string) string {
return ""
},
gitConfigMockResponses: nil,
test: func(cmdStr string, err error) {
assert.NoError(t, err)
assert.Equal(t, `vim +1 "open file/at line"`, cmdStr)
},
},
{
filename: "default edit command template",
configEditCommand: "vim",
configEditCommandTemplate: "",
runner: oscommands.NewFakeRunner(t),
getenv: func(env string) string {
return ""
},
gitConfigMockResponses: nil,
test: func(cmdStr string, err error) {
assert.NoError(t, err)
assert.Equal(t, `vim +1 -- "default edit command template"`, cmdStr)
},
},
}
for _, s := range scenarios {
userConfig := config.GetDefaultConfig()
userConfig.OS.EditCommand = s.configEditCommand
userConfig.OS.EditCommandTemplate = s.configEditCommandTemplate
instance := buildFileCommands(commonDeps{
runner: s.runner,
userConfig: userConfig,
gitConfig: git_config.NewFakeGitConfig(s.gitConfigMockResponses),
getenv: s.getenv,
})
s.test(instance.GetEditCmdStrLegacy(s.filename, 1))
s.runner.CheckForMissingCalls()
}
}
func TestEditFilesCmd(t *testing.T) { func TestEditFilesCmd(t *testing.T) {
type scenario struct { type scenario struct {
filenames []string filenames []string

View File

@ -80,10 +80,6 @@ func FileType(path string) string {
func (c *OSCommand) OpenFile(filename string) error { func (c *OSCommand) OpenFile(filename string) error {
commandTemplate := c.UserConfig().OS.Open commandTemplate := c.UserConfig().OS.Open
if commandTemplate == "" {
// Legacy support
commandTemplate = c.UserConfig().OS.OpenCommand
}
if commandTemplate == "" { if commandTemplate == "" {
commandTemplate = config.GetPlatformDefaultConfig().Open commandTemplate = config.GetPlatformDefaultConfig().Open
} }
@ -96,10 +92,6 @@ func (c *OSCommand) OpenFile(filename string) error {
func (c *OSCommand) OpenLink(link string) error { func (c *OSCommand) OpenLink(link string) error {
commandTemplate := c.UserConfig().OS.OpenLink commandTemplate := c.UserConfig().OS.OpenLink
if commandTemplate == "" {
// Legacy support
commandTemplate = c.UserConfig().OS.OpenLinkCommand
}
if commandTemplate == "" { if commandTemplate == "" {
commandTemplate = config.GetPlatformDefaultConfig().OpenLink commandTemplate = config.GetPlatformDefaultConfig().OpenLink
} }

View File

@ -602,29 +602,6 @@ type OSConfig struct {
// A shell startup file containing shell aliases or shell functions. This will be sourced before running any shell commands, so that shell functions are available in the `:` command prompt or even in custom commands. // A shell startup file containing shell aliases or shell functions. This will be sourced before running any shell commands, so that shell functions are available in the `:` command prompt or even in custom commands.
// See https://github.com/jesseduffield/lazygit/blob/master/docs/Config.md#using-aliases-or-functions-in-shell-commands // See https://github.com/jesseduffield/lazygit/blob/master/docs/Config.md#using-aliases-or-functions-in-shell-commands
ShellFunctionsFile string `yaml:"shellFunctionsFile"` ShellFunctionsFile string `yaml:"shellFunctionsFile"`
// --------
// The following configs are all deprecated and kept for backward
// compatibility. They will be removed in the future.
// EditCommand is the command for editing a file.
// Deprecated: use Edit instead. Note that semantics are different:
// EditCommand is just the command itself, whereas Edit contains a
// "{{filename}}" variable.
EditCommand string `yaml:"editCommand,omitempty" jsonschema:"deprecated"`
// EditCommandTemplate is the command template for editing a file
// Deprecated: use EditAtLine instead.
EditCommandTemplate string `yaml:"editCommandTemplate,omitempty" jsonschema:"deprecated"`
// OpenCommand is the command for opening a file
// Deprecated: use Open instead.
OpenCommand string `yaml:"openCommand,omitempty" jsonschema:"deprecated"`
// OpenLinkCommand is the command for opening a link
// Deprecated: use OpenLink instead.
OpenLinkCommand string `yaml:"openLinkCommand,omitempty" jsonschema:"deprecated"`
} }
type CustomCommandAfterHook struct { type CustomCommandAfterHook struct {

View File

@ -816,8 +816,6 @@ func (gui *Gui) Run(startArgs appTypes.StartArgs) error {
return err return err
} }
defer gui.checkForDeprecatedEditConfigs()
gui.g = g gui.g = g
defer gui.g.Close() defer gui.g.Close()
@ -889,37 +887,6 @@ func (gui *Gui) RunAndHandleError(startArgs appTypes.StartArgs) error {
}) })
} }
func (gui *Gui) checkForDeprecatedEditConfigs() {
osConfig := &gui.UserConfig().OS
deprecatedConfigs := []struct {
config string
oldName string
newName string
}{
{osConfig.EditCommand, "EditCommand", "Edit"},
{osConfig.EditCommandTemplate, "EditCommandTemplate", "Edit,EditAtLine"},
{osConfig.OpenCommand, "OpenCommand", "Open"},
{osConfig.OpenLinkCommand, "OpenLinkCommand", "OpenLink"},
}
deprecatedConfigStrings := []string{}
for _, dc := range deprecatedConfigs {
if dc.config != "" {
deprecatedConfigStrings = append(deprecatedConfigStrings, fmt.Sprintf(" OS.%s -> OS.%s", dc.oldName, dc.newName))
}
}
if len(deprecatedConfigStrings) != 0 {
warningMessage := utils.ResolvePlaceholderString(
gui.c.Tr.DeprecatedEditConfigWarning,
map[string]string{
"configs": strings.Join(deprecatedConfigStrings, "\n"),
},
)
os.Stdout.Write([]byte(warningMessage))
}
}
// returns whether command exited without error or not // returns whether command exited without error or not
func (gui *Gui) runSubprocessWithSuspenseAndRefresh(subprocess *oscommands.CmdObj) error { func (gui *Gui) runSubprocessWithSuspenseAndRefresh(subprocess *oscommands.CmdObj) error {
_, err := gui.runSubprocessWithSuspense(subprocess) _, err := gui.runSubprocessWithSuspense(subprocess)

View File

@ -254,7 +254,6 @@ type TranslationSet struct {
MergeToolTitle string MergeToolTitle string
MergeToolPrompt string MergeToolPrompt string
IntroPopupMessage string IntroPopupMessage string
DeprecatedEditConfigWarning string
NonReloadableConfigWarningTitle string NonReloadableConfigWarningTitle string
NonReloadableConfigWarning string NonReloadableConfigWarning string
GitconfigParseErr string GitconfigParseErr string
@ -1046,21 +1045,6 @@ Thanks for using lazygit! Seriously you rock. Three things to share with you:
Press {{confirmationKey}} to get started. Press {{confirmationKey}} to get started.
` `
const englishDeprecatedEditConfigWarning = `
### Deprecated config warning ###
The following config settings are deprecated and will be removed in a future
version:
{{configs}}
Please refer to
https://github.com/jesseduffield/lazygit/blob/master/docs/Config.md#configuring-file-editing
for up-to-date information how to configure your editor.
`
const englishNonReloadableConfigWarning = `The following config settings were changed, but the change doesn't take effect immediately. Please quit and restart lazygit for changes to take effect: const englishNonReloadableConfigWarning = `The following config settings were changed, but the change doesn't take effect immediately. Please quit and restart lazygit for changes to take effect:
{{configs}}` {{configs}}`
@ -1308,7 +1292,6 @@ func EnglishTranslationSet() *TranslationSet {
MergeToolTitle: "Merge tool", MergeToolTitle: "Merge tool",
MergeToolPrompt: "Are you sure you want to open `git mergetool`?", MergeToolPrompt: "Are you sure you want to open `git mergetool`?",
IntroPopupMessage: englishIntroPopupMessage, IntroPopupMessage: englishIntroPopupMessage,
DeprecatedEditConfigWarning: englishDeprecatedEditConfigWarning,
NonReloadableConfigWarningTitle: "Config changed", NonReloadableConfigWarningTitle: "Config changed",
NonReloadableConfigWarning: englishNonReloadableConfigWarning, NonReloadableConfigWarning: englishNonReloadableConfigWarning,
GitconfigParseErr: `Gogit failed to parse your gitconfig file due to the presence of unquoted '\' characters. Removing these should fix the issue.`, GitconfigParseErr: `Gogit failed to parse your gitconfig file due to the presence of unquoted '\' characters. Removing these should fix the issue.`,

View File

@ -1601,22 +1601,6 @@
"shellFunctionsFile": { "shellFunctionsFile": {
"type": "string", "type": "string",
"description": "A shell startup file containing shell aliases or shell functions. This will be sourced before running any shell commands, so that shell functions are available in the `:` command prompt or even in custom commands.\nSee https://github.com/jesseduffield/lazygit/blob/master/docs/Config.md#using-aliases-or-functions-in-shell-commands" "description": "A shell startup file containing shell aliases or shell functions. This will be sourced before running any shell commands, so that shell functions are available in the `:` command prompt or even in custom commands.\nSee https://github.com/jesseduffield/lazygit/blob/master/docs/Config.md#using-aliases-or-functions-in-shell-commands"
},
"editCommand": {
"type": "string",
"description": "EditCommand is the command for editing a file.\nDeprecated: use Edit instead. Note that semantics are different:\nEditCommand is just the command itself, whereas Edit contains a\n\"{{filename}}\" variable."
},
"editCommandTemplate": {
"type": "string",
"description": "EditCommandTemplate is the command template for editing a file\nDeprecated: use EditAtLine instead."
},
"openCommand": {
"type": "string",
"description": "OpenCommand is the command for opening a file\nDeprecated: use Open instead."
},
"openLinkCommand": {
"type": "string",
"description": "OpenLinkCommand is the command for opening a link\nDeprecated: use OpenLink instead."
} }
}, },
"additionalProperties": false, "additionalProperties": false,