mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-07-30 03:23:08 +03:00
fix backward compatibility
This commit is contained in:
@ -323,7 +323,7 @@ func (c *GitCommand) ResetAndClean() 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 == "" {
|
||||
editor = c.GetConfigValue("core.editor")
|
||||
@ -353,6 +353,6 @@ func (c *GitCommand) EditFileCmdStr(filename string, lineNumber int) (string, er
|
||||
"line": strconv.Itoa(lineNumber),
|
||||
}
|
||||
|
||||
editTemplate := c.Config.GetUserConfig().OS.EditCommand
|
||||
return utils.ResolvePlaceholderString(editTemplate, templateValues), nil
|
||||
editCmdTemplate := c.Config.GetUserConfig().OS.EditCommandTemplate
|
||||
return utils.ResolvePlaceholderString(editCmdTemplate, templateValues), nil
|
||||
}
|
||||
|
@ -741,13 +741,13 @@ func TestGitCommandRemoveUntrackedFiles(t *testing.T) {
|
||||
// TestEditFileCmdStr is a function.
|
||||
func TestEditFileCmdStr(t *testing.T) {
|
||||
type scenario struct {
|
||||
filename string
|
||||
configEditor string
|
||||
configEditCommand string
|
||||
command func(string, ...string) *exec.Cmd
|
||||
getenv func(string) string
|
||||
getGitConfigValue func(string) (string, error)
|
||||
test func(string, error)
|
||||
filename string
|
||||
configEditCommand string
|
||||
configEditCommandTemplate string
|
||||
command func(string, ...string) *exec.Cmd
|
||||
getenv func(string) string
|
||||
getGitConfigValue func(string) (string, error)
|
||||
test func(string, error)
|
||||
}
|
||||
|
||||
scenarios := []scenario{
|
||||
@ -912,8 +912,8 @@ func TestEditFileCmdStr(t *testing.T) {
|
||||
|
||||
for _, s := range scenarios {
|
||||
gitCmd := NewDummyGitCommand()
|
||||
gitCmd.Config.GetUserConfig().OS.Editor = s.configEditor
|
||||
gitCmd.Config.GetUserConfig().OS.EditCommand = s.configEditCommand
|
||||
gitCmd.Config.GetUserConfig().OS.EditCommandTemplate = s.configEditCommandTemplate
|
||||
gitCmd.OSCommand.Command = s.command
|
||||
gitCmd.OSCommand.Getenv = s.getenv
|
||||
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
|
||||
func (hunk *PatchHunk) LineNumberOfLine(idx int) (int, error) {
|
||||
func (hunk *PatchHunk) LineNumberOfLine(idx int) int {
|
||||
n := idx - hunk.FirstLineIdx - 1
|
||||
if n < 0 || len(hunk.bodyLines) <= n {
|
||||
return -1, fmt.Errorf("line index out of range")
|
||||
if n < 0 {
|
||||
n = 0
|
||||
} else if n >= len(hunk.bodyLines) {
|
||||
n = len(hunk.bodyLines) - 1
|
||||
}
|
||||
|
||||
lines := hunk.bodyLines[0:n]
|
||||
|
||||
offset := nLinesWithPrefix(lines, []string{"+", " "})
|
||||
|
||||
return hunk.newStart + offset, nil
|
||||
return hunk.newStart + offset
|
||||
}
|
||||
|
||||
func nLinesWithPrefix(lines []string, chars []string) int {
|
||||
|
@ -539,7 +539,7 @@ func TestLineNumberOfLine(t *testing.T) {
|
||||
|
||||
for _, s := range scenarios {
|
||||
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) {
|
||||
fmt.Println(result)
|
||||
}
|
||||
|
Reference in New Issue
Block a user