diff --git a/pkg/commands/git_commands/commit_loader_test.go b/pkg/commands/git_commands/commit_loader_test.go index cc959b4ea..fcbc825d9 100644 --- a/pkg/commands/git_commands/commit_loader_test.go +++ b/pkg/commands/git_commands/commit_loader_test.go @@ -16,16 +16,16 @@ import ( "github.com/stretchr/testify/assert" ) -var commitsOutput = strings.Replace(`0eea75e8c631fba6b58135697835d58ba4c18dbc|1640826609|Jesse Duffield|jessedduffield@gmail.com|HEAD -> better-tests|b21997d6b4cbdf84b149|>|better typing for rebase mode +var commitsOutput = strings.ReplaceAll(`0eea75e8c631fba6b58135697835d58ba4c18dbc|1640826609|Jesse Duffield|jessedduffield@gmail.com|HEAD -> better-tests|b21997d6b4cbdf84b149|>|better typing for rebase mode b21997d6b4cbdf84b149d8e6a2c4d06a8e9ec164|1640824515|Jesse Duffield|jessedduffield@gmail.com|origin/better-tests|e94e8fc5b6fab4cb755f|>|fix logging e94e8fc5b6fab4cb755f29f1bdb3ee5e001df35c|1640823749|Jesse Duffield|jessedduffield@gmail.com|tag: 123, tag: 456|d8084cd558925eb7c9c3|>|refactor d8084cd558925eb7c9c38afeed5725c21653ab90|1640821426|Jesse Duffield|jessedduffield@gmail.com||65f910ebd85283b5cce9|>|WIP 65f910ebd85283b5cce9bf67d03d3f1a9ea3813a|1640821275|Jesse Duffield|jessedduffield@gmail.com||26c07b1ab33860a1a759|>|WIP 26c07b1ab33860a1a7591a0638f9925ccf497ffa|1640750752|Jesse Duffield|jessedduffield@gmail.com||3d4470a6c072208722e5|>|WIP 3d4470a6c072208722e5ae9a54bcb9634959a1c5|1640748818|Jesse Duffield|jessedduffield@gmail.com||053a66a7be3da43aacdc|>|WIP -053a66a7be3da43aacdc7aa78e1fe757b82c4dd2|1640739815|Jesse Duffield|jessedduffield@gmail.com||985fe482e806b172aea4|>|refactoring the config struct`, "|", "\x00", -1) +053a66a7be3da43aacdc7aa78e1fe757b82c4dd2|1640739815|Jesse Duffield|jessedduffield@gmail.com||985fe482e806b172aea4|>|refactoring the config struct`, "|", "\x00") -var singleCommitOutput = strings.Replace(`0eea75e8c631fba6b58135697835d58ba4c18dbc|1640826609|Jesse Duffield|jessedduffield@gmail.com|HEAD -> better-tests|b21997d6b4cbdf84b149|>|better typing for rebase mode`, "|", "\x00", -1) +var singleCommitOutput = strings.ReplaceAll(`0eea75e8c631fba6b58135697835d58ba4c18dbc|1640826609|Jesse Duffield|jessedduffield@gmail.com|HEAD -> better-tests|b21997d6b4cbdf84b149|>|better typing for rebase mode`, "|", "\x00") func TestGetCommits(t *testing.T) { type scenario struct { diff --git a/pkg/commands/git_commands/reflog_commit_loader_test.go b/pkg/commands/git_commands/reflog_commit_loader_test.go index 5cc7395c0..01e479e5c 100644 --- a/pkg/commands/git_commands/reflog_commit_loader_test.go +++ b/pkg/commands/git_commands/reflog_commit_loader_test.go @@ -14,12 +14,12 @@ import ( "github.com/stretchr/testify/assert" ) -var reflogOutput = strings.Replace(`c3c4b66b64c97ffeecde|1643150483|checkout: moving from A to B|51baa8c1 +var reflogOutput = strings.ReplaceAll(`c3c4b66b64c97ffeecde|1643150483|checkout: moving from A to B|51baa8c1 c3c4b66b64c97ffeecde|1643150483|checkout: moving from B to A|51baa8c1 c3c4b66b64c97ffeecde|1643150483|checkout: moving from A to B|51baa8c1 c3c4b66b64c97ffeecde|1643150483|checkout: moving from master to A|51baa8c1 f4ddf2f0d4be4ccc7efa|1643149435|checkout: moving from A to master|51baa8c1 -`, "|", "\x00", -1) +`, "|", "\x00") func TestGetReflogCommits(t *testing.T) { type scenario struct { diff --git a/pkg/commands/oscommands/os.go b/pkg/commands/oscommands/os.go index 042af3f92..2443e8c35 100644 --- a/pkg/commands/oscommands/os.go +++ b/pkg/commands/oscommands/os.go @@ -283,7 +283,7 @@ func PrepareForChildren(cmd *exec.Cmd) { } func (c *OSCommand) CopyToClipboard(str string) error { - escaped := strings.Replace(str, "\n", "\\n", -1) + escaped := strings.ReplaceAll(str, "\n", "\\n") truncated := utils.TruncateWithEllipsis(escaped, 40) msg := utils.ResolvePlaceholderString( diff --git a/pkg/gui/command_log_panel.go b/pkg/gui/command_log_panel.go index 8c1daa4c7..c0319f5c0 100644 --- a/pkg/gui/command_log_panel.go +++ b/pkg/gui/command_log_panel.go @@ -48,7 +48,7 @@ func (gui *Gui) LogCommand(cmdStr string, commandLine bool) { textStyle = style.FgMagenta } gui.GuiLog = append(gui.GuiLog, cmdStr) - indentedCmdStr := " " + strings.Replace(cmdStr, "\n", "\n ", -1) + indentedCmdStr := " " + strings.ReplaceAll(cmdStr, "\n", "\n ") fmt.Fprint(gui.Views.Extras, "\n"+textStyle.Sprint(indentedCmdStr)) } diff --git a/pkg/gui/controllers/helpers/refs_helper.go b/pkg/gui/controllers/helpers/refs_helper.go index 8936a1d61..7a7f29d8e 100644 --- a/pkg/gui/controllers/helpers/refs_helper.go +++ b/pkg/gui/controllers/helpers/refs_helper.go @@ -563,7 +563,7 @@ func (self *RefsHelper) CanMoveCommitsToNewBranch() *types.DisabledReason { // SanitizedBranchName will remove all spaces in favor of a dash "-" to meet // git's branch naming requirement. func SanitizedBranchName(input string) string { - return strings.Replace(input, " ", "-", -1) + return strings.ReplaceAll(input, " ", "-") } // Checks if the given branch name is a remote branch, and returns the name of diff --git a/pkg/gui/global_handlers.go b/pkg/gui/global_handlers.go index 62f9311ea..9abadf4e0 100644 --- a/pkg/gui/global_handlers.go +++ b/pkg/gui/global_handlers.go @@ -185,7 +185,7 @@ func (gui *Gui) handleCopySelectedSideContextItemToClipboardWithTruncation(maxWi return err } - truncatedItemId := utils.TruncateWithEllipsis(strings.Replace(itemId, "\n", " ", -1), 50) + truncatedItemId := utils.TruncateWithEllipsis(strings.ReplaceAll(itemId, "\n", " "), 50) gui.c.Toast(fmt.Sprintf("'%s' %s", truncatedItemId, gui.c.Tr.CopiedToClipboard)) diff --git a/pkg/utils/lines.go b/pkg/utils/lines.go index c601bb806..576f48371 100644 --- a/pkg/utils/lines.go +++ b/pkg/utils/lines.go @@ -11,7 +11,7 @@ import ( // currently we are also stripping \r's which may have adverse effects for // windows users (but no issues have been raised yet) func SplitLines(multilineString string) []string { - multilineString = strings.Replace(multilineString, "\r", "", -1) + multilineString = strings.ReplaceAll(multilineString, "\r", "") if multilineString == "" || multilineString == "\n" { return make([]string, 0) } @@ -32,8 +32,8 @@ func SplitNul(str string) []string { // NormalizeLinefeeds - Removes all Windows and Mac style line feeds func NormalizeLinefeeds(str string) string { - str = strings.Replace(str, "\r\n", "\n", -1) - str = strings.Replace(str, "\r", "", -1) + str = strings.ReplaceAll(str, "\r\n", "\n") + str = strings.ReplaceAll(str, "\r", "") return str }