Skip to content

Commit 1ca5f09

Browse files
authored
Remove deprecated edit configs (#4716)
They were deprecated in April 2023 (see 046b0d9), so it's been well over a year now.
2 parents 143134f + 73bf49f commit 1ca5f09

File tree

8 files changed

+1
-337
lines changed

8 files changed

+1
-337
lines changed

pkg/commands/git_commands/file.go

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"strconv"
66
"strings"
77

8-
"github.com/go-errors/errors"
98
"github.com/jesseduffield/lazygit/pkg/config"
109
"github.com/jesseduffield/lazygit/pkg/utils"
1110
"github.com/samber/lo"
@@ -30,62 +29,7 @@ func (self *FileCommands) Cat(fileName string) (string, error) {
3029
return string(buf), nil
3130
}
3231

33-
func (self *FileCommands) GetEditCmdStrLegacy(filename string, lineNumber int) (string, error) {
34-
editor := self.UserConfig().OS.EditCommand
35-
36-
if editor == "" {
37-
editor = self.config.GetCoreEditor()
38-
}
39-
if editor == "" {
40-
editor = self.os.Getenv("GIT_EDITOR")
41-
}
42-
if editor == "" {
43-
editor = self.os.Getenv("VISUAL")
44-
}
45-
if editor == "" {
46-
editor = self.os.Getenv("EDITOR")
47-
}
48-
if editor == "" {
49-
if err := self.cmd.New([]string{"which", "vi"}).DontLog().Run(); err == nil {
50-
editor = "vi"
51-
}
52-
}
53-
if editor == "" {
54-
return "", errors.New("No editor defined in config file, $GIT_EDITOR, $VISUAL, $EDITOR, or git config")
55-
}
56-
57-
templateValues := map[string]string{
58-
"editor": editor,
59-
"filename": self.cmd.Quote(filename),
60-
"line": strconv.Itoa(lineNumber),
61-
}
62-
63-
editCmdTemplate := self.UserConfig().OS.EditCommandTemplate
64-
if len(editCmdTemplate) == 0 {
65-
switch editor {
66-
case "emacs", "nano", "vi", "vim", "nvim":
67-
editCmdTemplate = "{{editor}} +{{line}} -- {{filename}}"
68-
case "subl":
69-
editCmdTemplate = "{{editor}} -- {{filename}}:{{line}}"
70-
case "code":
71-
editCmdTemplate = "{{editor}} -r --goto -- {{filename}}:{{line}}"
72-
default:
73-
editCmdTemplate = "{{editor}} -- {{filename}}"
74-
}
75-
}
76-
return utils.ResolvePlaceholderString(editCmdTemplate, templateValues), nil
77-
}
78-
7932
func (self *FileCommands) GetEditCmdStr(filenames []string) (string, bool) {
80-
// Legacy support for old config; to be removed at some point
81-
if self.UserConfig().OS.Edit == "" && self.UserConfig().OS.EditCommandTemplate != "" {
82-
// If multiple files are selected, we'll simply edit just the first one.
83-
// It's not worth fixing this for the legacy support.
84-
if cmdStr, err := self.GetEditCmdStrLegacy(filenames[0], 1); err == nil {
85-
return cmdStr, true
86-
}
87-
}
88-
8933
template, suspend := config.GetEditTemplate(self.os.Platform.Shell, &self.UserConfig().OS, self.guessDefaultEditor)
9034
quotedFilenames := lo.Map(filenames, func(filename string, _ int) string { return self.cmd.Quote(filename) })
9135

@@ -98,13 +42,6 @@ func (self *FileCommands) GetEditCmdStr(filenames []string) (string, bool) {
9842
}
9943

10044
func (self *FileCommands) GetEditAtLineCmdStr(filename string, lineNumber int) (string, bool) {
101-
// Legacy support for old config; to be removed at some point
102-
if self.UserConfig().OS.EditAtLine == "" && self.UserConfig().OS.EditCommandTemplate != "" {
103-
if cmdStr, err := self.GetEditCmdStrLegacy(filename, lineNumber); err == nil {
104-
return cmdStr, true
105-
}
106-
}
107-
10845
template, suspend := config.GetEditAtLineTemplate(self.os.Platform.Shell, &self.UserConfig().OS, self.guessDefaultEditor)
10946

11047
templateValues := map[string]string{
@@ -117,13 +54,6 @@ func (self *FileCommands) GetEditAtLineCmdStr(filename string, lineNumber int) (
11754
}
11855

11956
func (self *FileCommands) GetEditAtLineAndWaitCmdStr(filename string, lineNumber int) string {
120-
// Legacy support for old config; to be removed at some point
121-
if self.UserConfig().OS.EditAtLineAndWait == "" && self.UserConfig().OS.EditCommandTemplate != "" {
122-
if cmdStr, err := self.GetEditCmdStrLegacy(filename, lineNumber); err == nil {
123-
return cmdStr
124-
}
125-
}
126-
12757
template := config.GetEditAtLineAndWaitTemplate(self.os.Platform.Shell, &self.UserConfig().OS, self.guessDefaultEditor)
12858

12959
templateValues := map[string]string{

pkg/commands/git_commands/file_test.go

Lines changed: 0 additions & 169 deletions
Original file line numberDiff line numberDiff line change
@@ -3,180 +3,11 @@ package git_commands
33
import (
44
"testing"
55

6-
"github.com/go-errors/errors"
76
"github.com/jesseduffield/lazygit/pkg/commands/git_config"
8-
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
97
"github.com/jesseduffield/lazygit/pkg/config"
108
"github.com/stretchr/testify/assert"
119
)
1210

13-
func TestEditFileCmdStrLegacy(t *testing.T) {
14-
type scenario struct {
15-
filename string
16-
configEditCommand string
17-
configEditCommandTemplate string
18-
runner *oscommands.FakeCmdObjRunner
19-
getenv func(string) string
20-
gitConfigMockResponses map[string]string
21-
test func(string, error)
22-
}
23-
24-
scenarios := []scenario{
25-
{
26-
filename: "test",
27-
configEditCommand: "",
28-
configEditCommandTemplate: "{{editor}} {{filename}}",
29-
runner: oscommands.NewFakeRunner(t).
30-
ExpectArgs([]string{"which", "vi"}, "", errors.New("error")),
31-
getenv: func(env string) string {
32-
return ""
33-
},
34-
gitConfigMockResponses: nil,
35-
test: func(cmdStr string, err error) {
36-
assert.EqualError(t, err, "No editor defined in config file, $GIT_EDITOR, $VISUAL, $EDITOR, or git config")
37-
},
38-
},
39-
{
40-
filename: "test",
41-
configEditCommand: "nano",
42-
configEditCommandTemplate: "{{editor}} {{filename}}",
43-
runner: oscommands.NewFakeRunner(t),
44-
getenv: func(env string) string {
45-
return ""
46-
},
47-
gitConfigMockResponses: nil,
48-
test: func(cmdStr string, err error) {
49-
assert.NoError(t, err)
50-
assert.Equal(t, `nano "test"`, cmdStr)
51-
},
52-
},
53-
{
54-
filename: "test",
55-
configEditCommand: "",
56-
configEditCommandTemplate: "{{editor}} {{filename}}",
57-
runner: oscommands.NewFakeRunner(t),
58-
getenv: func(env string) string {
59-
return ""
60-
},
61-
gitConfigMockResponses: map[string]string{"core.editor": "nano"},
62-
test: func(cmdStr string, err error) {
63-
assert.NoError(t, err)
64-
assert.Equal(t, `nano "test"`, cmdStr)
65-
},
66-
},
67-
{
68-
filename: "test",
69-
configEditCommand: "",
70-
configEditCommandTemplate: "{{editor}} {{filename}}",
71-
runner: oscommands.NewFakeRunner(t),
72-
getenv: func(env string) string {
73-
if env == "VISUAL" {
74-
return "nano"
75-
}
76-
77-
return ""
78-
},
79-
gitConfigMockResponses: nil,
80-
test: func(cmdStr string, err error) {
81-
assert.NoError(t, err)
82-
assert.Equal(t, `nano "test"`, cmdStr)
83-
},
84-
},
85-
{
86-
filename: "test",
87-
configEditCommand: "",
88-
configEditCommandTemplate: "{{editor}} {{filename}}",
89-
runner: oscommands.NewFakeRunner(t),
90-
getenv: func(env string) string {
91-
if env == "EDITOR" {
92-
return "emacs"
93-
}
94-
95-
return ""
96-
},
97-
gitConfigMockResponses: nil,
98-
test: func(cmdStr string, err error) {
99-
assert.NoError(t, err)
100-
assert.Equal(t, `emacs "test"`, cmdStr)
101-
},
102-
},
103-
{
104-
filename: "test",
105-
configEditCommand: "",
106-
configEditCommandTemplate: "{{editor}} {{filename}}",
107-
runner: oscommands.NewFakeRunner(t).
108-
ExpectArgs([]string{"which", "vi"}, "/usr/bin/vi", nil),
109-
getenv: func(env string) string {
110-
return ""
111-
},
112-
gitConfigMockResponses: nil,
113-
test: func(cmdStr string, err error) {
114-
assert.NoError(t, err)
115-
assert.Equal(t, `vi "test"`, cmdStr)
116-
},
117-
},
118-
{
119-
filename: "file/with space",
120-
configEditCommand: "",
121-
configEditCommandTemplate: "{{editor}} {{filename}}",
122-
runner: oscommands.NewFakeRunner(t).
123-
ExpectArgs([]string{"which", "vi"}, "/usr/bin/vi", nil),
124-
getenv: func(env string) string {
125-
return ""
126-
},
127-
gitConfigMockResponses: nil,
128-
test: func(cmdStr string, err error) {
129-
assert.NoError(t, err)
130-
assert.Equal(t, `vi "file/with space"`, cmdStr)
131-
},
132-
},
133-
{
134-
filename: "open file/at line",
135-
configEditCommand: "vim",
136-
configEditCommandTemplate: "{{editor}} +{{line}} {{filename}}",
137-
runner: oscommands.NewFakeRunner(t),
138-
getenv: func(env string) string {
139-
return ""
140-
},
141-
gitConfigMockResponses: nil,
142-
test: func(cmdStr string, err error) {
143-
assert.NoError(t, err)
144-
assert.Equal(t, `vim +1 "open file/at line"`, cmdStr)
145-
},
146-
},
147-
{
148-
filename: "default edit command template",
149-
configEditCommand: "vim",
150-
configEditCommandTemplate: "",
151-
runner: oscommands.NewFakeRunner(t),
152-
getenv: func(env string) string {
153-
return ""
154-
},
155-
gitConfigMockResponses: nil,
156-
test: func(cmdStr string, err error) {
157-
assert.NoError(t, err)
158-
assert.Equal(t, `vim +1 -- "default edit command template"`, cmdStr)
159-
},
160-
},
161-
}
162-
163-
for _, s := range scenarios {
164-
userConfig := config.GetDefaultConfig()
165-
userConfig.OS.EditCommand = s.configEditCommand
166-
userConfig.OS.EditCommandTemplate = s.configEditCommandTemplate
167-
168-
instance := buildFileCommands(commonDeps{
169-
runner: s.runner,
170-
userConfig: userConfig,
171-
gitConfig: git_config.NewFakeGitConfig(s.gitConfigMockResponses),
172-
getenv: s.getenv,
173-
})
174-
175-
s.test(instance.GetEditCmdStrLegacy(s.filename, 1))
176-
s.runner.CheckForMissingCalls()
177-
}
178-
}
179-
18011
func TestEditFilesCmd(t *testing.T) {
18112
type scenario struct {
18213
filenames []string

pkg/commands/oscommands/os.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,6 @@ func FileType(path string) string {
8080

8181
func (c *OSCommand) OpenFile(filename string) error {
8282
commandTemplate := c.UserConfig().OS.Open
83-
if commandTemplate == "" {
84-
// Legacy support
85-
commandTemplate = c.UserConfig().OS.OpenCommand
86-
}
8783
if commandTemplate == "" {
8884
commandTemplate = config.GetPlatformDefaultConfig().Open
8985
}
@@ -96,10 +92,6 @@ func (c *OSCommand) OpenFile(filename string) error {
9692

9793
func (c *OSCommand) OpenLink(link string) error {
9894
commandTemplate := c.UserConfig().OS.OpenLink
99-
if commandTemplate == "" {
100-
// Legacy support
101-
commandTemplate = c.UserConfig().OS.OpenLinkCommand
102-
}
10395
if commandTemplate == "" {
10496
commandTemplate = config.GetPlatformDefaultConfig().OpenLink
10597
}

pkg/commands/oscommands/os_windows_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func TestOSCommandOpenFileWindows(t *testing.T) {
7171
}
7272
oSCmd.Platform = platform
7373
oSCmd.Cmd.platform = platform
74-
oSCmd.UserConfig().OS.OpenCommand = `start "" {{filename}}`
74+
oSCmd.UserConfig().OS.Open = `start "" {{filename}}`
7575

7676
s.test(oSCmd.OpenFile(s.filename))
7777
}

pkg/config/user_config.go

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -602,29 +602,6 @@ type OSConfig struct {
602602
// 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.
603603
// See https://github.com/jesseduffield/lazygit/blob/master/docs/Config.md#using-aliases-or-functions-in-shell-commands
604604
ShellFunctionsFile string `yaml:"shellFunctionsFile"`
605-
606-
// --------
607-
608-
// The following configs are all deprecated and kept for backward
609-
// compatibility. They will be removed in the future.
610-
611-
// EditCommand is the command for editing a file.
612-
// Deprecated: use Edit instead. Note that semantics are different:
613-
// EditCommand is just the command itself, whereas Edit contains a
614-
// "{{filename}}" variable.
615-
EditCommand string `yaml:"editCommand,omitempty" jsonschema:"deprecated"`
616-
617-
// EditCommandTemplate is the command template for editing a file
618-
// Deprecated: use EditAtLine instead.
619-
EditCommandTemplate string `yaml:"editCommandTemplate,omitempty" jsonschema:"deprecated"`
620-
621-
// OpenCommand is the command for opening a file
622-
// Deprecated: use Open instead.
623-
OpenCommand string `yaml:"openCommand,omitempty" jsonschema:"deprecated"`
624-
625-
// OpenLinkCommand is the command for opening a link
626-
// Deprecated: use OpenLink instead.
627-
OpenLinkCommand string `yaml:"openLinkCommand,omitempty" jsonschema:"deprecated"`
628605
}
629606

630607
type CustomCommandAfterHook struct {

pkg/gui/gui.go

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -816,8 +816,6 @@ func (gui *Gui) Run(startArgs appTypes.StartArgs) error {
816816
return err
817817
}
818818

819-
defer gui.checkForDeprecatedEditConfigs()
820-
821819
gui.g = g
822820
defer gui.g.Close()
823821

@@ -889,37 +887,6 @@ func (gui *Gui) RunAndHandleError(startArgs appTypes.StartArgs) error {
889887
})
890888
}
891889

892-
func (gui *Gui) checkForDeprecatedEditConfigs() {
893-
osConfig := &gui.UserConfig().OS
894-
deprecatedConfigs := []struct {
895-
config string
896-
oldName string
897-
newName string
898-
}{
899-
{osConfig.EditCommand, "EditCommand", "Edit"},
900-
{osConfig.EditCommandTemplate, "EditCommandTemplate", "Edit,EditAtLine"},
901-
{osConfig.OpenCommand, "OpenCommand", "Open"},
902-
{osConfig.OpenLinkCommand, "OpenLinkCommand", "OpenLink"},
903-
}
904-
deprecatedConfigStrings := []string{}
905-
906-
for _, dc := range deprecatedConfigs {
907-
if dc.config != "" {
908-
deprecatedConfigStrings = append(deprecatedConfigStrings, fmt.Sprintf(" OS.%s -> OS.%s", dc.oldName, dc.newName))
909-
}
910-
}
911-
if len(deprecatedConfigStrings) != 0 {
912-
warningMessage := utils.ResolvePlaceholderString(
913-
gui.c.Tr.DeprecatedEditConfigWarning,
914-
map[string]string{
915-
"configs": strings.Join(deprecatedConfigStrings, "\n"),
916-
},
917-
)
918-
919-
os.Stdout.Write([]byte(warningMessage))
920-
}
921-
}
922-
923890
// returns whether command exited without error or not
924891
func (gui *Gui) runSubprocessWithSuspenseAndRefresh(subprocess *oscommands.CmdObj) error {
925892
_, err := gui.runSubprocessWithSuspense(subprocess)

0 commit comments

Comments
 (0)