diff options
Diffstat (limited to 'pkg')
43 files changed, 136 insertions, 114 deletions
diff --git a/pkg/app/app.go b/pkg/app/app.go index 0ee7e4adf..2d279936f 100644 --- a/pkg/app/app.go +++ b/pkg/app/app.go @@ -65,7 +65,7 @@ func newDevelopmentLogger() *logrus.Logger { if err != nil { log.Fatal(err) } - file, err := os.OpenFile(logPath, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666) + file, err := os.OpenFile(logPath, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0o666) if err != nil { log.Fatalf("Unable to log to log file: %v", err) } @@ -269,10 +269,9 @@ func (app *App) Rebase() error { app.Log.Info("args: ", os.Args) if strings.HasSuffix(os.Args[1], "git-rebase-todo") { - if err := ioutil.WriteFile(os.Args[1], []byte(os.Getenv("LAZYGIT_REBASE_TODO")), 0644); err != nil { + if err := ioutil.WriteFile(os.Args[1], []byte(os.Getenv("LAZYGIT_REBASE_TODO")), 0o644); err != nil { return err } - } else if strings.HasSuffix(os.Args[1], filepath.Join(gitDir(), "COMMIT_EDITMSG")) { // TODO: test // if we are rebasing and squashing, we'll see a COMMIT_EDITMSG // but in this case we don't need to edit it, so we'll just return diff --git a/pkg/app/logging_windows.go b/pkg/app/logging_windows.go index f8b3d4990..efbdfbbe1 100644 --- a/pkg/app/logging_windows.go +++ b/pkg/app/logging_windows.go @@ -5,11 +5,12 @@ package app import ( "bufio" - "github.com/aybabtme/humanlog" "log" "os" "strings" "time" + + "github.com/aybabtme/humanlog" ) func TailLogsForPlatform(logFilePath string, opts *humanlog.HandlerOptions) { diff --git a/pkg/cheatsheet/check.go b/pkg/cheatsheet/check.go index 03f65d910..ebcd0629f 100644 --- a/pkg/cheatsheet/check.go +++ b/pkg/cheatsheet/check.go @@ -19,7 +19,7 @@ func Check() { if err != nil { log.Fatalf("Error occured while checking if cheatsheets are up to date: %v", err) } - err = os.Mkdir(tmpDir, 0700) + err = os.Mkdir(tmpDir, 0o700) if err != nil { log.Fatalf("Error occured while checking if cheatsheets are up to date: %v", err) } @@ -70,7 +70,6 @@ func obtainContent(dir string) string { return nil }) - if err != nil { log.Fatalf("Error occured while checking if cheatsheets are up to date: %v", err) } diff --git a/pkg/cheatsheet/generate.go b/pkg/cheatsheet/generate.go index 804cb6b45..c7c2b0d37 100644 --- a/pkg/cheatsheet/generate.go +++ b/pkg/cheatsheet/generate.go @@ -174,7 +174,7 @@ outer: bindings []*types.Binding } - groupedBindings := make([]groupedBindingsType, len(contextAndViewBindingMap)) + groupedBindings := make([]groupedBindingsType, 0, len(contextAndViewBindingMap)) for contextAndView, contextBindings := range contextAndViewBindingMap { groupedBindings = append(groupedBindings, groupedBindingsType{contextAndView: contextAndView, bindings: contextBindings}) diff --git a/pkg/commands/git.go b/pkg/commands/git.go index 3880e0dfc..6c6a3ac7c 100644 --- a/pkg/commands/git.go +++ b/pkg/commands/git.go @@ -223,7 +223,6 @@ func setupRepository(openGitRepository func(string) (*gogit.Repository, error), } repository, err := openGitRepository(path) - if err != nil { if strings.Contains(err.Error(), `unquoted '\' must be followed by new line`) { return nil, errors.New(gitConfigParseErrorStr) diff --git a/pkg/commands/git_commands/rebase.go b/pkg/commands/git_commands/rebase.go index c726cad7e..71c8b0e63 100644 --- a/pkg/commands/git_commands/rebase.go +++ b/pkg/commands/git_commands/rebase.go @@ -185,7 +185,7 @@ func (self *RebaseCommands) EditRebaseTodo(index int, action string) error { content[contentIndex] = action + " " + strings.Join(splitLine[1:], " ") result := strings.Join(content, "\n") - return ioutil.WriteFile(fileName, []byte(result), 0644) + return ioutil.WriteFile(fileName, []byte(result), 0o644) } func (self *RebaseCommands) getTodoCommitCount(content []string) int { @@ -215,7 +215,7 @@ func (self *RebaseCommands) MoveTodoDown(index int) error { rearrangedContent = append(rearrangedContent, content[contentIndex+1:]...) result := strings.Join(rearrangedContent, "\n") - return ioutil.WriteFile(fileName, []byte(result), 0644) + return ioutil.WriteFile(fileName, []byte(result), 0o644) } // SquashAllAboveFixupCommits squashes all fixup! commits above the given one diff --git a/pkg/commands/hosting_service/hosting_service.go b/pkg/commands/hosting_service/hosting_service.go index 4a0a49681..b448e3925 100644 --- a/pkg/commands/hosting_service/hosting_service.go +++ b/pkg/commands/hosting_service/hosting_service.go @@ -9,6 +9,8 @@ import ( "github.com/jesseduffield/lazygit/pkg/i18n" "github.com/jesseduffield/lazygit/pkg/utils" "github.com/sirupsen/logrus" + + "golang.org/x/exp/slices" ) // This package is for handling logic specific to a git hosting service like github, gitlab, bitbucket, etc. @@ -94,8 +96,7 @@ func (self *HostingServiceMgr) getCandidateServiceDomains() []ServiceDomain { serviceDefinitionByProvider[serviceDefinition.provider] = serviceDefinition } - var serviceDomains = make([]ServiceDomain, len(defaultServiceDomains)) - copy(serviceDomains, defaultServiceDomains) + serviceDomains := slices.Clone(defaultServiceDomains) if len(self.configServiceDomains) > 0 { for gitDomain, typeAndDomain := range self.configServiceDomains { diff --git a/pkg/commands/oscommands/cmd_obj_runner_win.go b/pkg/commands/oscommands/cmd_obj_runner_win.go index 9e3d1fd02..9a64dfa77 100644 --- a/pkg/commands/oscommands/cmd_obj_runner_win.go +++ b/pkg/commands/oscommands/cmd_obj_runner_win.go @@ -20,6 +20,7 @@ func (b *Buffer) Read(p []byte) (n int, err error) { defer b.m.Unlock() return b.b.Read(p) } + func (b *Buffer) Write(p []byte) (n int, err error) { b.m.Lock() defer b.m.Unlock() diff --git a/pkg/commands/oscommands/fake_cmd_obj_runner.go b/pkg/commands/oscommands/fake_cmd_obj_runner.go index b542bfee3..d06861251 100644 --- a/pkg/commands/oscommands/fake_cmd_obj_runner.go +++ b/pkg/commands/oscommands/fake_cmd_obj_runner.go @@ -21,7 +21,7 @@ type FakeCmdObjRunner struct { var _ ICmdObjRunner = &FakeCmdObjRunner{} -func NewFakeRunner(t *testing.T) *FakeCmdObjRunner { +func NewFakeRunner(t *testing.T) *FakeCmdObjRunner { //nolint:thelper return &FakeCmdObjRunner{t: t} } diff --git a/pkg/commands/oscommands/os.go b/pkg/commands/oscommands/os.go index 1c4f5bf28..f3df3956f 100644 --- a/pkg/commands/oscommands/os.go +++ b/pkg/commands/oscommands/os.go @@ -103,7 +103,7 @@ func (c *OSCommand) Quote(message string) string { // AppendLineToFile adds a new line in file func (c *OSCommand) AppendLineToFile(filename, line string) error { c.LogCommand(fmt.Sprintf("Appending '%s' to file '%s'", line, filename), false) - f, err := os.OpenFile(filename, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0600) + f, err := os.OpenFile(filename, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0o600) if err != nil { return utils.WrapError(err) } @@ -145,7 +145,7 @@ func (c *OSCommand) CreateFileWithContent(path string, content string) error { return err } - if err := ioutil.WriteFile(path, []byte(content), 0644); err != nil { + if err := ioutil.WriteFile(path, []byte(content), 0o644); err != nil { c.Log.Error(err) return utils.WrapError(err) } diff --git a/pkg/commands/oscommands/os_test.go b/pkg/commands/oscommands/os_test.go index efda5a3a1..9c2d9a2a7 100644 --- a/pkg/commands/oscommands/os_test.go +++ b/pkg/commands/oscommands/os_test.go @@ -141,7 +141,7 @@ func TestOSCommandFileType(t *testing.T) { { "testDirectory", func() { - if err := os.Mkdir("testDirectory", 0644); err != nil { + if err := os.Mkdir("testDirectory", 0o644); err != nil { panic(err) } }, diff --git a/pkg/commands/patch/patch_manager.go b/pkg/commands/patch/patch_manager.go index c8e16a7fd..cbdf7b2d4 100644 --- a/pkg/commands/patch/patch_manager.go +++ b/pkg/commands/patch/patch_manager.go @@ -26,8 +26,10 @@ type fileInfo struct { diff string } -type applyPatchFunc func(patch string, flags ...string) error -type loadFileDiffFunc func(from string, to string, reverse bool, filename string, plain bool) (string, error) +type ( + applyPatchFunc func(patch string, flags ...string) error + loadFileDiffFunc func(from string, to string, reverse bool, filename string, plain bool) (string, error) +) // PatchManager manages the building of a patch for a commit to be applied to another commit (or the working tree, or removed from the current commit). We also support building patches from things like stashes, for which there is less flexibility type PatchManager struct { diff --git a/pkg/commands/patch/patch_modifier.go b/pkg/commands/patch/patch_modifier.go index 2109ad1f0..2d060ec18 100644 --- a/pkg/commands/patch/patch_modifier.go +++ b/pkg/commands/patch/patch_modifier.go @@ -8,8 +8,10 @@ import ( "github.com/sirupsen/logrus" ) -var hunkHeaderRegexp = regexp.MustCompile(`(?m)^@@ -(\d+)[^\+]+\+(\d+)[^@]+@@(.*)$`) -var patchHeaderRegexp = regexp.MustCompile(`(?ms)(^diff.*?)^@@`) +var ( + hunkHeaderRegexp = regexp.MustCompile(`(?m)^@@ -(\d+)[^\+]+\+(\d+)[^@]+@@(.*)$`) + patchHeaderRegexp = regexp.MustCompile(`(?ms)(^diff.*?)^@@`) +) func GetHeaderFromDiff(diff string) string { match := patchHeaderRegexp.FindStringSubmatch(diff) diff --git a/pkg/config/app_config.go b/pkg/config/app_config.go index 98620ad43..40509e86a 100644 --- a/pkg/config/app_config.go +++ b/pkg/config/app_config.go @@ -123,7 +123,7 @@ func configDirForVendor(vendor string) string { func findOrCreateConfigDir() (string, error) { folder := ConfigDir() - return folder, os.MkdirAll(folder, 0755) + return folder, os.MkdirAll(folder, 0o755) } func loadUserConfigWithDefaults(configFiles []string) (*UserConfig, error) { @@ -249,7 +249,7 @@ func (c *AppConfig) SaveAppState() error { return err } - err = ioutil.WriteFile(filepath, marshalledAppState, 0644) + err = ioutil.WriteFile(filepath, marshalledAppState, 0o644) if err != nil && os.IsPermission(err) { // apparently when people have read-only permissions they prefer us to fail silently return nil diff --git a/pkg/config/user_config.go b/pkg/config/user_config.go index ac8a2bbc1..51f443243 100644 --- a/pkg/config/user_config.go +++ b/pkg/config/user_config.go @@ -358,7 +358,8 @@ func GetDefaultConfig() *UserConfig { Paging: PagingConfig{ ColorArg: "always", Pager: "", - UseConfig: false}, + UseConfig: false, + }, Commit: CommitConfig{ SignOff: false, }, diff --git a/pkg/gui/context/local_commits_context.go b/pkg/gui/context/local_commits_context.go index d8d64392c..46e3be2cd 100644 --- a/pkg/gui/context/local_commits_context.go +++ b/pkg/gui/context/local_commits_context.go @@ -45,7 +45,8 @@ func NewLocalCommitsContext( viewTrait: NewViewTrait(view), getDisplayStrings: getDisplayStrings, c: c, - }}, + }, + }, } } diff --git a/pkg/gui/context/sub_commits_context.go b/pkg/gui/context/sub_commits_context.go index 0f16f1688..93a0c3593 100644 --- a/pkg/gui/context/sub_commits_context.go +++ b/pkg/gui/context/sub_commits_context.go @@ -45,7 +45,8 @@ func NewSubCommitsContext( viewTrait: NewViewTrait(view), getDisplayStrings: getDisplayStrings, c: c, - }}, + }, + }, } } diff --git a/pkg/gui/controllers/branches_controller.go b/pkg/gui/controllers/branches_controller.go index 08ea95119..c578a405b 100644 --- a/pkg/gui/controllers/branches_controller.go +++ b/pkg/gui/controllers/branches_controller.go @@ -185,7 +185,8 @@ func (self *BranchesController) checkoutByName() error { }) }, }) - }}, + }, + }, ) } @@ -377,8 +378,8 @@ func (self *BranchesController) createPullRequestMenu(selectedBranch *models.Bra FindSuggestionsFunc: self.helpers.Suggestions.GetBranchNameSuggestionsFunc(), HandleConfirm: func(targetBranchName string) error { return self.createPullRequest(branch.Name, targetBranchName) - }}, - ) + }, + }) }, }, } diff --git a/pkg/gui/controllers/commits_files_controller.go b/pkg/gui/controllers/commits_files_controller.go index 933d17321..978d6c6a7 100644 --- a/pkg/gui/controllers/commits_files_controller.go +++ b/pkg/gui/controllers/commits_files_controller.go @@ -170,7 +170,6 @@ func (self *CommitFilesController) toggleForPatch(node *filetree.CommitFileNode) return self.git.Patch.PatchManager.RemoveFile(file.Name) } }) - if err != nil { return self.c.Error(err) } diff --git a/pkg/gui/controllers/helpers/refs_helper.go b/pkg/gui/controllers/helpers/refs_helper.go index e3e050117..65c01d4a7 100644 --- a/pkg/gui/controllers/helpers/refs_helper.go +++ b/pkg/gui/controllers/helpers/refs_helper.go @@ -71,7 +71,6 @@ func (self *RefsHelper) CheckoutRef(ref string, options types.CheckoutRefOptions if strings.Contains(err.Error(), "Please commit your changes or stash them before you switch branch") { // offer to autostash changes return self.c.Ask(types.AskOpts{ - Title: self.c.Tr.AutoStashTitle, Prompt: self.c.Tr.AutoStashPrompt, HandleConfirm: func() error { diff --git a/pkg/gui/controllers/submodules_controller.go b/pkg/gui/controllers/submodules_controller.go index 83c05da4b..10b25df2b 100644 --- a/pkg/gui/controllers/submodules_controller.go +++ b/pkg/gui/controllers/submodules_controller.go @@ -90,7 +90,6 @@ func (self *SubmodulesController) add() error { Title: self.c.Tr.LcNewSubmoduleName, InitialContent: nameSuggestion, HandleConfirm: func(submoduleName string) error { - return self.c.Prompt(types.PromptOpts{ Title: self.c.Tr.LcNewSubmodulePath, InitialContent: submoduleName, diff --git a/pkg/gui/controllers/sync_controller.go b/pkg/gui/controllers/sync_controller.go index 74db3d527..8501c5484 100644 --- a/pkg/gui/controllers/sync_controller.go +++ b/pkg/gui/controllers/sync_controller.go @@ -194,7 +194,6 @@ func (self *SyncController) pushAux(opts pushOpts) error { UpstreamBranch: opts.upstreamBranch, SetUpstream: opts.setUpstream, }) - if err != nil { if !opts.force && strings.Contains(err.Error(), "Updates were rejected") { forcePushDisabled := self.c.UserConfig.Git.DisableForcePushing diff --git a/pkg/gui/filetree/commit_file_node.go b/pkg/gui/filetree/commit_file_node.go index 98428348e..a8f7d0a95 100644 --- a/pkg/gui/filetree/commit_file_node.go +++ b/pkg/gui/filetree/commit_file_node.go @@ -12,8 +12,10 @@ type CommitFileNode struct { CompressionLevel int // equal to the number of forward slashes you'll see in the path when it's rendered in tree mode } -var _ INode = &CommitFileNode{} -var _ types.ListItem = &CommitFileNode{} +var ( + _ INode = &CommitFileNode{} + _ types.ListItem = &CommitFileNode{} +) func (s *CommitFileNode) ID() string { return s.GetPath() diff --git a/pkg/gui/filetree/file_node.go b/pkg/gui/filetree/file_node.go index 5a99b3e12..841f723fc 100644 --- a/pkg/gui/filetree/file_node.go +++ b/pkg/gui/filetree/file_node.go @@ -12,8 +12,10 @@ type FileNode struct { CompressionLevel int // equal to the number of forward slashes you'll see in the path when it's rendered in tree mode } -var _ INode = &FileNode{} -var _ types.ListItem = &FileNode{} +var ( + _ INode = &FileNode{} + _ types.ListItem = &FileNode{} +) func (s *FileNode) ID() string { return s.GetPath() diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go index b65493d49..144be8df5 100644 --- a/pkg/gui/gui.go +++ b/pkg/gui/gui.go @@ -5,9 +5,8 @@ import ( "io/ioutil" "log" "os" - "sync" - "strings" + "sync" "time" "github.com/jesseduffield/gocui" diff --git a/pkg/gui/gui_test.go b/pkg/gui/gui_test.go index e35ab1896..58f0b0958 100644 --- a/pkg/gui/gui_test.go +++ b/pkg/gui/gui_test.go @@ -55,6 +55,7 @@ func Test(t *testing.T) { mode, speedEnv, func(t *testing.T, expected string, actual string, prefix string) { + t.Helper() assert.Equal(t, expected, actual, fmt.Sprintf("Unexpected %s. Expected:\n%s\nActual:\n%s\n", prefix, expected, actual)) }, includeSkipped, diff --git a/pkg/gui/keybindings.go b/pkg/gui/keybindings.go index 2bf2b9815..13fdf7d26 100644 --- a/pkg/gui/keybindings.go +++ b/pkg/gui/keybindings.go @@ -4,7 +4,6 @@ import ( "fmt" "log" "strings" - "unicode/utf8" "github.com/jesseduffield/gocui" @@ -1021,7 +1020,8 @@ func (self *Gui) GetInitialKeybindings() ([]*types.Binding, []*gocui.ViewMouseBi ViewName: "", Key: opts.GetKey(opts.Config.Universal.JumpToBlock[i]), Modifier: gocui.ModNone, - Handler: self.goToSideWindow(window)}) + Handler: self.goToSideWindow(window), + }) } } diff --git a/pkg/gui/merge_panel.go b/pkg/gui/merge_panel.go index 60aa93a17..b9a00eaa2 100644 --- a/pkg/gui/merge_panel.go +++ b/pkg/gui/merge_panel.go @@ -54,7 +54,7 @@ func (gui *Gui) handleMergeConflictUndo() error { gui.c.LogAction("Restoring file to previous state") gui.LogCommand("Undoing last conflict resolution", false) - if err := ioutil.WriteFile(state.GetPath(), []byte(state.GetContent()), 0644); err != nil { + if err := ioutil.WriteFile(state.GetPath(), []byte(state.GetContent()), 0o644); err != nil { return err } @@ -127,7 +127,7 @@ func (gui *Gui) resolveConflict(selection mergeconflicts.Selection) (bool, error gui.c.LogAction("Resolve merge conflict") gui.LogCommand(logStr, false) state.PushContent(content) - return true, ioutil.WriteFile(state.GetPath(), []byte(content), 0644) + return true, ioutil.WriteFile(state.GetPath(), []byte(content), 0o644) } // precondition: we actually have conflicts to render diff --git a/pkg/gui/mergeconflicts/find_conflicts.go b/pkg/gui/mergeconflicts/find_conflicts.go index 14a08fd68..3802a66b7 100644 --- a/pkg/gui/mergeconflicts/find_conflicts.go +++ b/pkg/gui/mergeconflicts/find_conflicts.go @@ -57,10 +57,12 @@ func findConflicts(content string) []*mergeConflict { return conflicts } -var CONFLICT_START = "<<<<<<< " -var CONFLICT_END = ">>>>>>> " -var CONFLICT_START_BYTES = []byte(CONFLICT_START) -var CONFLICT_END_BYTES = []byte(CONFLICT_END) +var ( + CONFLICT_START = "<<<<<<< " + CONFLICT_END = ">>>>>>> " + CONFLICT_START_BYTES = []byte(CONFLICT_START) + CONFLICT_END_BYTES = []byte(CONFLICT_END) +) func determineLineType(line string) LineType { // TODO: find out whether we ever actually get this prefix diff --git a/pkg/gui/mergeconflicts/state.go b/pkg/gui/mergeconflicts/state.go index b40b979e9..3d0254e15 100644 --- a/pkg/gui/mergeconflicts/state.go +++ b/pkg/gui/mergeconflicts/state.go @@ -176,7 +176,6 @@ func (s *State) ContentAfterConflictResolve(selection Selection) (bool, string, content += line } }) |