summaryrefslogtreecommitdiffstats
path: root/pkg
diff options
context:
space:
mode:
authorRyooooooga <eial5q265e5@gmail.com>2021-08-04 18:43:34 +0900
committerRyooooooga <eial5q265e5@gmail.com>2021-08-04 18:43:34 +0900
commitac609bd37c0b879ce08f0fcff7b1c7ef09d37333 (patch)
treee402ef4ca8af9929d0c9e1f9caa18ea25d34bb18 /pkg
parent67cc65930ae62346fcc522f56da59fba5eef1dbe (diff)
fix backward compatibility
Diffstat (limited to 'pkg')
-rw-r--r--pkg/commands/files.go6
-rw-r--r--pkg/commands/files_test.go16
-rw-r--r--pkg/commands/patch/patch_modifier.go10
-rw-r--r--pkg/commands/patch/patch_modifier_test.go2
-rw-r--r--pkg/config/config_default_platform.go8
-rw-r--r--pkg/config/config_linux.go8
-rw-r--r--pkg/config/config_windows.go8
-rw-r--r--pkg/config/user_config.go8
-rw-r--r--pkg/gui/lbl/state.go2
-rw-r--r--pkg/gui/line_by_line_panel.go12
10 files changed, 37 insertions, 43 deletions
diff --git a/pkg/commands/files.go b/pkg/commands/files.go
index 1d4ad5fe6..fed1e795c 100644
--- a/pkg/commands/files.go
+++ b/pkg/commands/files.go
@@ -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
}
diff --git a/pkg/commands/files_test.go b/pkg/commands/files_test.go
index 46ccda947..f12067e55 100644
--- a/pkg/commands/files_test.go
+++ b/pkg/commands/files_test.go
@@ -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
diff --git a/pkg/commands/patch/patch_modifier.go b/pkg/commands/patch/patch_modifier.go
index e5c6d061f..3ab13931b 100644
--- a/pkg/commands/patch/patch_modifier.go
+++ b/pkg/commands/patch/patch_modifier.go
@@ -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 {
diff --git a/pkg/commands/patch/patch_modifier_test.go b/pkg/commands/patch/patch_modifier_test.go
index 1f1eeb114..8b866019b 100644
--- a/pkg/commands/patch/patch_modifier_test.go
+++ b/pkg/commands/patch/patch_modifier_test.go
@@ -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)
}
diff --git a/pkg/config/config_default_platform.go b/pkg/config/config_default_platform.go
index cb6e338df..0f56297d3 100644
--- a/pkg/config/config_default_platform.go
+++ b/pkg/config/config_default_platform.go
@@ -5,9 +5,9 @@ package config
// GetPlatformDefaultConfig gets the defaults for the platform
func GetPlatformDefaultConfig() OSConfig {
return OSConfig{
- Editor: ``,
- EditCommand: `{{editor}} {{filename}}`,
- OpenCommand: "open {{filename}}",
- OpenLinkCommand: "open {{link}}",
+ EditCommand: ``,
+ EditCommandTemplate: `{{editor}} {{filename}}`,
+ OpenCommand: "open {{filename}}",
+ OpenLinkCommand: "open {{link}}",
}
}
diff --git a/pkg/config/config_linux.go b/pkg/config/config_linux.go
index 1eed335f0..fe75b7322 100644
--- a/pkg/config/config_linux.go
+++ b/pkg/config/config_linux.go
@@ -3,9 +3,9 @@ package config
// GetPlatformDefaultConfig gets the defaults for the platform
func GetPlatformDefaultConfig() OSConfig {
return OSConfig{
- Editor: ``,
- EditCommand: `{{editor}} {{filename}}`,
- OpenCommand: `sh -c "xdg-open {{filename}} >/dev/null"`,
- OpenLinkCommand: `sh -c "xdg-open {{link}} >/dev/null"`,
+ EditCommand: ``,
+ EditCommandTemplate: `{{editor}} {{filename}}`,
+ OpenCommand: `sh -c "xdg-open {{filename}} >/dev/null"`,
+ OpenLinkCommand: `sh -c "xdg-open {{link}} >/dev/null"`,
}
}
diff --git a/pkg/config/config_windows.go b/pkg/config/config_windows.go
index 1bc919848..71124808b 100644
--- a/pkg/config/config_windows.go
+++ b/pkg/config/config_windows.go
@@ -3,9 +3,9 @@ package config
// GetPlatformDefaultConfig gets the defaults for the platform
func GetPlatformDefaultConfig() OSConfig {
return OSConfig{
- Editor: ``,
- EditCommand: `{{editor}} {{filename}}`,
- OpenCommand: `cmd /c "start "" {{filename}}"`,
- OpenLinkCommand: `cmd /c "start "" {{link}}"`,
+ EditCommand: ``,
+ EditCommandTemplate: `{{editor}} {{filename}}`,
+ OpenCommand: `cmd /c "start "" {{filename}}"`,
+ OpenLinkCommand: `cmd /c "start "" {{link}}"`,
}
}
diff --git a/pkg/config/user_config.go b/pkg/config/user_config.go
index ea079948e..e7f952890 100644
--- a/pkg/config/user_config.go
+++ b/pkg/config/user_config.go
@@ -252,12 +252,12 @@ type KeybindingSubmodulesConfig struct {
// OSConfig contains config on the level of the os
type OSConfig struct {
- // Editor is the command for editing a file
- Editor string `yaml:"editor,omitempty"`
-
- // EditCommand is the command template for editing a file
+ // EditCommand is the command for editing a file
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 string `yaml:"openCommand,omitempty"`
diff --git a/pkg/gui/lbl/state.go b/pkg/gui/lbl/state.go
index 6adb03a54..8ae828923 100644
--- a/pkg/gui/lbl/state.go
+++ b/pkg/gui/lbl/state.go
@@ -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)
}
diff --git a/pkg/gui/line_by_line_panel.go b/pkg/gui/line_by_line_panel.go
index 6f93c36b9..8121b6ed3 100644
--- a/pkg/gui/line_by_line_panel.go
+++ b/pkg/gui/line_by_line_panel.go
@@ -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
- lineNumber, err := state.CurrentLineNumber()
- if err != nil {
- lineNumber = 1
- }
-
+ lineNumber := state.CurrentLineNumber()
filenameWithLineNum := fmt.Sprintf("%s:%d", filename, lineNumber)
if err := gui.OSCommand.OpenFile(filenameWithLineNum); err != nil {
return err
@@ -283,10 +279,6 @@ func (gui *Gui) handleLineByLineEdit() error {
return nil
}
- lineNumber, err := gui.State.Panels.LineByLine.CurrentLineNumber()
- if err != nil {
- lineNumber = 1
- }
-
+ lineNumber := gui.State.Panels.LineByLine.CurrentLineNumber()
return gui.editFileAtLine(file.Name, lineNumber)
}