mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-06-25 00:46:54 +02:00
fix backward compatibility
This commit is contained in:
@ -64,8 +64,8 @@ git:
|
|||||||
disableForcePushing: false
|
disableForcePushing: false
|
||||||
parseEmoji: false
|
parseEmoji: false
|
||||||
os:
|
os:
|
||||||
editor: '' # see 'Configuring File Editing' section
|
editCommand: '' # see 'Configuring File Editing' section
|
||||||
editCommand: '{{editor}} {{filename}}'
|
editCommandTemplate: '{{editor}} {{filename}}'
|
||||||
openCommand: ''
|
openCommand: ''
|
||||||
refresher:
|
refresher:
|
||||||
refreshInterval: 10 # file/submodule refresh interval in seconds
|
refreshInterval: 10 # file/submodule refresh interval in seconds
|
||||||
@ -231,7 +231,7 @@ Lazygit will edit a file with the first set editor in the following:
|
|||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
os:
|
os:
|
||||||
editor: 'vim' # as an example
|
editCommand: 'vim' # as an example
|
||||||
```
|
```
|
||||||
|
|
||||||
2. \$(git config core.editor)
|
2. \$(git config core.editor)
|
||||||
|
@ -323,7 +323,7 @@ func (c *GitCommand) ResetAndClean() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *GitCommand) EditFileCmdStr(filename string, lineNumber int) (string, error) {
|
func (c *GitCommand) EditFileCmdStr(filename string, lineNumber int) (string, error) {
|
||||||
editor := c.Config.GetUserConfig().OS.Editor
|
editor := c.Config.GetUserConfig().OS.EditCommand
|
||||||
|
|
||||||
if editor == "" {
|
if editor == "" {
|
||||||
editor = c.GetConfigValue("core.editor")
|
editor = c.GetConfigValue("core.editor")
|
||||||
@ -353,6 +353,6 @@ func (c *GitCommand) EditFileCmdStr(filename string, lineNumber int) (string, er
|
|||||||
"line": strconv.Itoa(lineNumber),
|
"line": strconv.Itoa(lineNumber),
|
||||||
}
|
}
|
||||||
|
|
||||||
editTemplate := c.Config.GetUserConfig().OS.EditCommand
|
editCmdTemplate := c.Config.GetUserConfig().OS.EditCommandTemplate
|
||||||
return utils.ResolvePlaceholderString(editTemplate, templateValues), nil
|
return utils.ResolvePlaceholderString(editCmdTemplate, templateValues), nil
|
||||||
}
|
}
|
||||||
|
@ -741,13 +741,13 @@ func TestGitCommandRemoveUntrackedFiles(t *testing.T) {
|
|||||||
// TestEditFileCmdStr is a function.
|
// TestEditFileCmdStr is a function.
|
||||||
func TestEditFileCmdStr(t *testing.T) {
|
func TestEditFileCmdStr(t *testing.T) {
|
||||||
type scenario struct {
|
type scenario struct {
|
||||||
filename string
|
filename string
|
||||||
configEditor string
|
configEditCommand string
|
||||||
configEditCommand string
|
configEditCommandTemplate string
|
||||||
command func(string, ...string) *exec.Cmd
|
command func(string, ...string) *exec.Cmd
|
||||||
getenv func(string) string
|
getenv func(string) string
|
||||||
getGitConfigValue func(string) (string, error)
|
getGitConfigValue func(string) (string, error)
|
||||||
test func(string, error)
|
test func(string, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
scenarios := []scenario{
|
scenarios := []scenario{
|
||||||
@ -912,8 +912,8 @@ func TestEditFileCmdStr(t *testing.T) {
|
|||||||
|
|
||||||
for _, s := range scenarios {
|
for _, s := range scenarios {
|
||||||
gitCmd := NewDummyGitCommand()
|
gitCmd := NewDummyGitCommand()
|
||||||
gitCmd.Config.GetUserConfig().OS.Editor = s.configEditor
|
|
||||||
gitCmd.Config.GetUserConfig().OS.EditCommand = s.configEditCommand
|
gitCmd.Config.GetUserConfig().OS.EditCommand = s.configEditCommand
|
||||||
|
gitCmd.Config.GetUserConfig().OS.EditCommandTemplate = s.configEditCommandTemplate
|
||||||
gitCmd.OSCommand.Command = s.command
|
gitCmd.OSCommand.Command = s.command
|
||||||
gitCmd.OSCommand.Getenv = s.getenv
|
gitCmd.OSCommand.Getenv = s.getenv
|
||||||
gitCmd.getGitConfigValue = s.getGitConfigValue
|
gitCmd.getGitConfigValue = s.getGitConfigValue
|
||||||
|
@ -137,17 +137,19 @@ func ModifiedPatchForLines(log *logrus.Entry, filename string, diffText string,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// I want to know, given a hunk, what line a given index is on
|
// I want to know, given a hunk, what line a given index is on
|
||||||
func (hunk *PatchHunk) LineNumberOfLine(idx int) (int, error) {
|
func (hunk *PatchHunk) LineNumberOfLine(idx int) int {
|
||||||
n := idx - hunk.FirstLineIdx - 1
|
n := idx - hunk.FirstLineIdx - 1
|
||||||
if n < 0 || len(hunk.bodyLines) <= n {
|
if n < 0 {
|
||||||
return -1, fmt.Errorf("line index out of range")
|
n = 0
|
||||||
|
} else if n >= len(hunk.bodyLines) {
|
||||||
|
n = len(hunk.bodyLines) - 1
|
||||||
}
|
}
|
||||||
|
|
||||||
lines := hunk.bodyLines[0:n]
|
lines := hunk.bodyLines[0:n]
|
||||||
|
|
||||||
offset := nLinesWithPrefix(lines, []string{"+", " "})
|
offset := nLinesWithPrefix(lines, []string{"+", " "})
|
||||||
|
|
||||||
return hunk.newStart + offset, nil
|
return hunk.newStart + offset
|
||||||
}
|
}
|
||||||
|
|
||||||
func nLinesWithPrefix(lines []string, chars []string) int {
|
func nLinesWithPrefix(lines []string, chars []string) int {
|
||||||
|
@ -539,7 +539,7 @@ func TestLineNumberOfLine(t *testing.T) {
|
|||||||
|
|
||||||
for _, s := range scenarios {
|
for _, s := range scenarios {
|
||||||
t.Run(s.testName, func(t *testing.T) {
|
t.Run(s.testName, func(t *testing.T) {
|
||||||
result, _ := s.hunk.LineNumberOfLine(s.idx)
|
result := s.hunk.LineNumberOfLine(s.idx)
|
||||||
if !assert.Equal(t, s.expected, result) {
|
if !assert.Equal(t, s.expected, result) {
|
||||||
fmt.Println(result)
|
fmt.Println(result)
|
||||||
}
|
}
|
||||||
|
@ -5,9 +5,9 @@ package config
|
|||||||
// GetPlatformDefaultConfig gets the defaults for the platform
|
// GetPlatformDefaultConfig gets the defaults for the platform
|
||||||
func GetPlatformDefaultConfig() OSConfig {
|
func GetPlatformDefaultConfig() OSConfig {
|
||||||
return OSConfig{
|
return OSConfig{
|
||||||
Editor: ``,
|
EditCommand: ``,
|
||||||
EditCommand: `{{editor}} {{filename}}`,
|
EditCommandTemplate: `{{editor}} {{filename}}`,
|
||||||
OpenCommand: "open {{filename}}",
|
OpenCommand: "open {{filename}}",
|
||||||
OpenLinkCommand: "open {{link}}",
|
OpenLinkCommand: "open {{link}}",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,9 +3,9 @@ package config
|
|||||||
// GetPlatformDefaultConfig gets the defaults for the platform
|
// GetPlatformDefaultConfig gets the defaults for the platform
|
||||||
func GetPlatformDefaultConfig() OSConfig {
|
func GetPlatformDefaultConfig() OSConfig {
|
||||||
return OSConfig{
|
return OSConfig{
|
||||||
Editor: ``,
|
EditCommand: ``,
|
||||||
EditCommand: `{{editor}} {{filename}}`,
|
EditCommandTemplate: `{{editor}} {{filename}}`,
|
||||||
OpenCommand: `sh -c "xdg-open {{filename}} >/dev/null"`,
|
OpenCommand: `sh -c "xdg-open {{filename}} >/dev/null"`,
|
||||||
OpenLinkCommand: `sh -c "xdg-open {{link}} >/dev/null"`,
|
OpenLinkCommand: `sh -c "xdg-open {{link}} >/dev/null"`,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,9 +3,9 @@ package config
|
|||||||
// GetPlatformDefaultConfig gets the defaults for the platform
|
// GetPlatformDefaultConfig gets the defaults for the platform
|
||||||
func GetPlatformDefaultConfig() OSConfig {
|
func GetPlatformDefaultConfig() OSConfig {
|
||||||
return OSConfig{
|
return OSConfig{
|
||||||
Editor: ``,
|
EditCommand: ``,
|
||||||
EditCommand: `{{editor}} {{filename}}`,
|
EditCommandTemplate: `{{editor}} {{filename}}`,
|
||||||
OpenCommand: `cmd /c "start "" {{filename}}"`,
|
OpenCommand: `cmd /c "start "" {{filename}}"`,
|
||||||
OpenLinkCommand: `cmd /c "start "" {{link}}"`,
|
OpenLinkCommand: `cmd /c "start "" {{link}}"`,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -252,12 +252,12 @@ type KeybindingSubmodulesConfig struct {
|
|||||||
|
|
||||||
// OSConfig contains config on the level of the os
|
// OSConfig contains config on the level of the os
|
||||||
type OSConfig struct {
|
type OSConfig struct {
|
||||||
// Editor is the command for editing a file
|
// EditCommand is the command for editing a file
|
||||||
Editor string `yaml:"editor,omitempty"`
|
|
||||||
|
|
||||||
// EditCommand is the command template for editing a file
|
|
||||||
EditCommand string `yaml:"editCommand,omitempty"`
|
EditCommand string `yaml:"editCommand,omitempty"`
|
||||||
|
|
||||||
|
// EditCommandTemplate is the command template for editing a file
|
||||||
|
EditCommandTemplate string `yaml:"editCommandTemplate,omitempty"`
|
||||||
|
|
||||||
// OpenCommand is the command for opening a file
|
// OpenCommand is the command for opening a file
|
||||||
OpenCommand string `yaml:"openCommand,omitempty"`
|
OpenCommand string `yaml:"openCommand,omitempty"`
|
||||||
|
|
||||||
|
@ -167,7 +167,7 @@ func (s *State) SelectedRange() (int, int) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *State) CurrentLineNumber() (int, error) {
|
func (s *State) CurrentLineNumber() int {
|
||||||
return s.CurrentHunk().LineNumberOfLine(s.selectedLineIdx)
|
return s.CurrentHunk().LineNumberOfLine(s.selectedLineIdx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -208,11 +208,7 @@ func (gui *Gui) handleOpenFileAtLine() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// need to look at current index, then work out what my hunk's header information is, and see how far my line is away from the hunk header
|
// need to look at current index, then work out what my hunk's header information is, and see how far my line is away from the hunk header
|
||||||
lineNumber, err := state.CurrentLineNumber()
|
lineNumber := state.CurrentLineNumber()
|
||||||
if err != nil {
|
|
||||||
lineNumber = 1
|
|
||||||
}
|
|
||||||
|
|
||||||
filenameWithLineNum := fmt.Sprintf("%s:%d", filename, lineNumber)
|
filenameWithLineNum := fmt.Sprintf("%s:%d", filename, lineNumber)
|
||||||
if err := gui.OSCommand.OpenFile(filenameWithLineNum); err != nil {
|
if err := gui.OSCommand.OpenFile(filenameWithLineNum); err != nil {
|
||||||
return err
|
return err
|
||||||
@ -283,10 +279,6 @@ func (gui *Gui) handleLineByLineEdit() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
lineNumber, err := gui.State.Panels.LineByLine.CurrentLineNumber()
|
lineNumber := gui.State.Panels.LineByLine.CurrentLineNumber()
|
||||||
if err != nil {
|
|
||||||
lineNumber = 1
|
|
||||||
}
|
|
||||||
|
|
||||||
return gui.editFileAtLine(file.Name, lineNumber)
|
return gui.editFileAtLine(file.Name, lineNumber)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user