diff --git a/.golangci.yml b/.golangci.yml index b2329171f..6a02b1dc5 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -11,6 +11,7 @@ linters: - nakedret - nolintlint - prealloc + - revive - thelper - tparallel - unconvert @@ -76,6 +77,20 @@ linters: dot-import-whitelist: - github.com/jesseduffield/lazygit/pkg/integration/components + revive: + severity: warning + rules: + - name: atomic + - name: context-as-argument + - name: context-keys-type + - name: error-naming + - name: var-declaration + - name: package-comments + - name: range + - name: time-naming + - name: indent-error-flow + - name: errorf + - name: superfluous-else exclusions: generated: lax presets: diff --git a/pkg/app/app.go b/pkg/app/app.go index 8d1d1568c..ad0d487ec 100644 --- a/pkg/app/app.go +++ b/pkg/app/app.go @@ -86,9 +86,9 @@ func newLogger(cfg config.AppConfigurer) *logrus.Entry { log.Fatal(err) } return logs.NewDevelopmentLogger(logPath) - } else { - return logs.NewProductionLogger() } + + return logs.NewProductionLogger() } // NewApp bootstrap a new application diff --git a/pkg/app/daemon/rebase.go b/pkg/app/daemon/rebase.go index 30740d09c..1cb3b844f 100644 --- a/pkg/app/daemon/rebase.go +++ b/pkg/app/daemon/rebase.go @@ -21,9 +21,8 @@ type TodoLine struct { func (self *TodoLine) ToString() string { if self.Action == "break" { return self.Action + "\n" - } else { - return self.Action + " " + self.Commit.Hash() + " " + self.Commit.Name + "\n" } + return self.Action + " " + self.Commit.Hash() + " " + self.Commit.Name + "\n" } func TodoLinesToString(todoLines []TodoLine) string { diff --git a/pkg/commands/git_commands/branch_loader.go b/pkg/commands/git_commands/branch_loader.go index 798a2ebef..73127ae63 100644 --- a/pkg/commands/git_commands/branch_loader.go +++ b/pkg/commands/git_commands/branch_loader.go @@ -356,9 +356,8 @@ func parseDifference(track string, regexStr string) string { match := re.FindStringSubmatch(track) if len(match) > 1 { return match[1] - } else { - return "0" } + return "0" } // TODO: only look at the new reflog commits, and otherwise store the recencies in diff --git a/pkg/commands/git_commands/commit.go b/pkg/commands/git_commands/commit.go index adf7dcf19..3568dbb33 100644 --- a/pkg/commands/git_commands/commit.go +++ b/pkg/commands/git_commands/commit.go @@ -149,9 +149,8 @@ func (self *CommitCommands) CommitEditorCmdObj() *oscommands.CmdObj { func (self *CommitCommands) signoffFlag() string { if self.UserConfig().Git.Commit.SignOff { return "--signoff" - } else { - return "" } + return "" } func (self *CommitCommands) GetCommitMessage(commitHash string) (string, error) { diff --git a/pkg/commands/git_commands/deps_test.go b/pkg/commands/git_commands/deps_test.go index bb079c063..a8fff5edd 100644 --- a/pkg/commands/git_commands/deps_test.go +++ b/pkg/commands/git_commands/deps_test.go @@ -97,7 +97,7 @@ func buildGitCommon(deps commonDeps) *GitCommon { func buildRepo() *gogit.Repository { // TODO: think of a way to actually mock this out - var repo *gogit.Repository = nil + var repo *gogit.Repository return repo } diff --git a/pkg/commands/git_commands/git_command_builder.go b/pkg/commands/git_commands/git_command_builder.go index a7edc144c..5e9c3b258 100644 --- a/pkg/commands/git_commands/git_command_builder.go +++ b/pkg/commands/git_commands/git_command_builder.go @@ -32,9 +32,8 @@ func (self *GitCommandBuilder) ArgIf(condition bool, ifTrue ...string) *GitComma func (self *GitCommandBuilder) ArgIfElse(condition bool, ifTrue string, ifFalse string) *GitCommandBuilder { if condition { return self.Arg(ifTrue) - } else { - return self.Arg(ifFalse) } + return self.Arg(ifFalse) } func (self *GitCommandBuilder) Config(value string) *GitCommandBuilder { diff --git a/pkg/commands/git_commands/rebase.go b/pkg/commands/git_commands/rebase.go index f6302fc28..8c52dc62f 100644 --- a/pkg/commands/git_commands/rebase.go +++ b/pkg/commands/git_commands/rebase.go @@ -327,9 +327,8 @@ func (self *RebaseCommands) MoveFixupCommitDown(commits []*models.Commit, target func todoFromCommit(commit *models.Commit) utils.Todo { if commit.Action == todo.UpdateRef { return utils.Todo{Ref: commit.Name} - } else { - return utils.Todo{Hash: commit.Hash()} } + return utils.Todo{Hash: commit.Hash()} } // Sets the action for the given commits in the git-rebase-todo file @@ -412,9 +411,9 @@ func (self *RebaseCommands) BeginInteractiveRebaseForCommit( instruction: daemon.NewInsertBreakInstruction(), keepCommitsThatBecomeEmpty: keepCommitsThatBecomeEmpty, }).Run() - } else { - return self.BeginInteractiveRebaseForCommitRange(commits, commitIndex, commitIndex, keepCommitsThatBecomeEmpty) } + + return self.BeginInteractiveRebaseForCommitRange(commits, commitIndex, commitIndex, keepCommitsThatBecomeEmpty) } func (self *RebaseCommands) BeginInteractiveRebaseForCommitRange( @@ -574,7 +573,7 @@ func getBaseHashOrRoot(commits []*models.Commit, index int) string { // at time of writing) if index < len(commits) { return commits[index].Hash() - } else { - return "--root" } + + return "--root" } diff --git a/pkg/commands/git_commands/repo_paths.go b/pkg/commands/git_commands/repo_paths.go index a355a45ba..543ab5cd0 100644 --- a/pkg/commands/git_commands/repo_paths.go +++ b/pkg/commands/git_commands/repo_paths.go @@ -21,7 +21,7 @@ type RepoPaths struct { isBareRepo bool } -var gitPathFormatVersion GitVersion = GitVersion{2, 31, 0, ""} +var gitPathFormatVersion = GitVersion{2, 31, 0, ""} // Path to the current worktree. If we're in the main worktree, this will // be the same as RepoPath() diff --git a/pkg/commands/git_commands/repo_paths_test.go b/pkg/commands/git_commands/repo_paths_test.go index 77f451671..2d02a9ed3 100644 --- a/pkg/commands/git_commands/repo_paths_test.go +++ b/pkg/commands/git_commands/repo_paths_test.go @@ -184,9 +184,7 @@ func TestGetRepoPaths(t *testing.T) { Expected: nil, Err: func(getRevParseArgs argFn) error { args := strings.Join(getRevParseArgs(), " ") - return errors.New( - fmt.Sprintf("'git %v --show-toplevel --absolute-git-dir --git-common-dir --is-bare-repository --show-superproject-working-tree' failed: fatal: invalid gitfile format: /path/to/repo/worktree2/.git", args), - ) + return fmt.Errorf("'git %v --show-toplevel --absolute-git-dir --git-common-dir --is-bare-repository --show-superproject-working-tree' failed: fatal: invalid gitfile format: /path/to/repo/worktree2/.git", args) }, }, } diff --git a/pkg/commands/git_commands/submodule.go b/pkg/commands/git_commands/submodule.go index fbe4802c4..f06e10134 100644 --- a/pkg/commands/git_commands/submodule.go +++ b/pkg/commands/git_commands/submodule.go @@ -49,9 +49,8 @@ func (self *SubmoduleCommands) GetConfigs(parentModule *models.SubmoduleConfig) if len(matches) > 0 { return matches[1], true - } else { - return "", false } + return "", false } configs := []*models.SubmoduleConfig{} diff --git a/pkg/commands/git_commands/working_tree.go b/pkg/commands/git_commands/working_tree.go index 8ba9b196d..a5faa801b 100644 --- a/pkg/commands/git_commands/working_tree.go +++ b/pkg/commands/git_commands/working_tree.go @@ -66,9 +66,8 @@ func (self *WorkingTreeCommands) UnstageAll() error { func (self *WorkingTreeCommands) UnStageFile(paths []string, tracked bool) error { if tracked { return self.UnstageTrackedFiles(paths) - } else { - return self.UnstageUntrackedFiles(paths) } + return self.UnstageUntrackedFiles(paths) } func (self *WorkingTreeCommands) UnstageTrackedFiles(paths []string) error { diff --git a/pkg/commands/hosting_service/hosting_service.go b/pkg/commands/hosting_service/hosting_service.go index 2e913b654..1c328fd0d 100644 --- a/pkg/commands/hosting_service/hosting_service.go +++ b/pkg/commands/hosting_service/hosting_service.go @@ -46,9 +46,8 @@ func (self *HostingServiceMgr) GetPullRequestURL(from string, to string) (string if to == "" { return gitService.getPullRequestURLIntoDefaultBranch(url.QueryEscape(from)), nil - } else { - return gitService.getPullRequestURLIntoTargetBranch(url.QueryEscape(from), url.QueryEscape(to)), nil } + return gitService.getPullRequestURLIntoTargetBranch(url.QueryEscape(from), url.QueryEscape(to)), nil } func (self *HostingServiceMgr) GetCommitURL(commitHash string) (string, error) { diff --git a/pkg/commands/patch/patch_builder.go b/pkg/commands/patch/patch_builder.go index 1c6fe286e..3fc8ebcf7 100644 --- a/pkg/commands/patch/patch_builder.go +++ b/pkg/commands/patch/patch_builder.go @@ -211,9 +211,8 @@ func (p *PatchBuilder) RenderPatchForFile(opts RenderPatchForFileOpts) string { if opts.Plain { return patch.FormatPlain() - } else { - return patch.FormatView(FormatViewOpts{}) } + return patch.FormatView(FormatViewOpts{}) } func (p *PatchBuilder) renderEachFilePatch(plain bool) []string { diff --git a/pkg/commands/patch/transform.go b/pkg/commands/patch/transform.go index db35bb4a1..4cd4c0207 100644 --- a/pkg/commands/patch/transform.go +++ b/pkg/commands/patch/transform.go @@ -84,9 +84,9 @@ func (self *patchTransformer) transformHeader() []string { result = append(result, line) } return result - } else { - return self.patch.header } + + return self.patch.header } func (self *patchTransformer) transformHunks() []*Hunk { diff --git a/pkg/gui/context/menu_context.go b/pkg/gui/context/menu_context.go index 26425af3d..3d5937a9d 100644 --- a/pkg/gui/context/menu_context.go +++ b/pkg/gui/context/menu_context.go @@ -144,7 +144,7 @@ func (self *MenuViewModel) GetNonModelItems() []*NonModelItem { } menuItems := self.FilteredListViewModel.GetItems() - var prevSection *types.MenuSection = nil + var prevSection *types.MenuSection for i, menuItem := range menuItems { if menuItem.Section != nil && menuItem.Section != prevSection { if prevSection != nil { diff --git a/pkg/gui/context/suggestions_context.go b/pkg/gui/context/suggestions_context.go index 9e3b8ba95..45364b3b5 100644 --- a/pkg/gui/context/suggestions_context.go +++ b/pkg/gui/context/suggestions_context.go @@ -79,9 +79,8 @@ func (self *SuggestionsContext) RefreshSuggestions() { if findSuggestionsFn != nil { suggestions := findSuggestionsFn(self.c.GetPromptInput()) return func() { self.SetSuggestions(suggestions) } - } else { - return func() {} } + return func() {} }) } diff --git a/pkg/gui/context/traits/list_cursor.go b/pkg/gui/context/traits/list_cursor.go index a8ff89716..c471d9a0f 100644 --- a/pkg/gui/context/traits/list_cursor.go +++ b/pkg/gui/context/traits/list_cursor.go @@ -77,9 +77,8 @@ func (self *ListCursor) SetSelectionRangeAndMode(selectedIdx, rangeStartIdx int, func (self *ListCursor) GetSelectionRangeAndMode() (int, int, RangeSelectMode) { if self.IsSelectingRange() { return self.selectedIdx, self.rangeStartIdx, self.rangeSelectMode - } else { - return self.selectedIdx, self.selectedIdx, self.rangeSelectMode } + return self.selectedIdx, self.selectedIdx, self.rangeSelectMode } func (self *ListCursor) clampValue(value int) int { diff --git a/pkg/gui/context_config.go b/pkg/gui/context_config.go index 748482a35..e1b35c492 100644 --- a/pkg/gui/context_config.go +++ b/pkg/gui/context_config.go @@ -24,7 +24,7 @@ func OnFocusWrapper(f func() error) func(opts types.OnFocusOpts) error { func (gui *Gui) defaultSideContext() types.Context { if gui.State.Modes.Filtering.Active() { return gui.State.Contexts.LocalCommits - } else { - return gui.State.Contexts.Files } + + return gui.State.Contexts.Files } diff --git a/pkg/gui/controllers/bisect_controller.go b/pkg/gui/controllers/bisect_controller.go index 0cd8d1d0b..401550c98 100644 --- a/pkg/gui/controllers/bisect_controller.go +++ b/pkg/gui/controllers/bisect_controller.go @@ -54,9 +54,8 @@ func (self *BisectController) openMenu(commit *models.Commit) error { info := self.c.Git().Bisect.GetInfo() if info.Started() { return self.openMidBisectMenu(info, commit) - } else { - return self.openStartBisectMenu(info, commit) } + return self.openStartBisectMenu(info, commit) } func (self *BisectController) openMidBisectMenu(info *git_commands.BisectInfo, commit *models.Commit) error { @@ -280,11 +279,11 @@ func (self *BisectController) afterBisectMarkRefresh(selectCurrent bool, waitToR if waitToReselect { return self.c.Refresh(types.RefreshOptions{Mode: types.SYNC, Scope: []types.RefreshableView{}, Then: selectFn}) - } else { - _ = selectFn() - - return self.c.Helpers().Bisect.PostBisectCommandRefresh() } + + _ = selectFn() + + return self.c.Helpers().Bisect.PostBisectCommandRefresh() } func (self *BisectController) selectCurrentBisectCommit() { diff --git a/pkg/gui/controllers/branches_controller.go b/pkg/gui/controllers/branches_controller.go index 4b5318dcb..528bfcf49 100644 --- a/pkg/gui/controllers/branches_controller.go +++ b/pkg/gui/controllers/branches_controller.go @@ -657,15 +657,15 @@ func (self *BranchesController) fastForward(branch *models.Branch) error { ) _ = self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC}) return err - } else { - self.c.LogAction(action) - - err := self.c.Git().Sync.FastForward( - task, branch.Name, branch.UpstreamRemote, branch.UpstreamBranch, - ) - _ = self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.BRANCHES}}) - return err } + + self.c.LogAction(action) + + err := self.c.Git().Sync.FastForward( + task, branch.Name, branch.UpstreamRemote, branch.UpstreamBranch, + ) + _ = self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.BRANCHES}}) + return err }) } diff --git a/pkg/gui/controllers/custom_patch_options_menu_action.go b/pkg/gui/controllers/custom_patch_options_menu_action.go index 92b77f514..d83228793 100644 --- a/pkg/gui/controllers/custom_patch_options_menu_action.go +++ b/pkg/gui/controllers/custom_patch_options_menu_action.go @@ -189,9 +189,9 @@ func (self *CustomPatchOptionsMenuAction) handleMovePatchIntoWorkingTree() error }) return nil - } else { - return pull(false) } + + return pull(false) } func (self *CustomPatchOptionsMenuAction) handlePullPatchIntoNewCommit() error { diff --git a/pkg/gui/controllers/files_controller.go b/pkg/gui/controllers/files_controller.go index 0c8db786f..ab5b6e277 100644 --- a/pkg/gui/controllers/files_controller.go +++ b/pkg/gui/controllers/files_controller.go @@ -901,11 +901,10 @@ func (self *FilesController) setStatusFiltering(filter filetree.FileTreeDisplayF // because the untracked files filter applies when running `git status`. if previousFilter != filter && (previousFilter == filetree.DisplayUntracked || filter == filetree.DisplayUntracked) { return self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.FILES}, Mode: types.ASYNC}) - } else { - self.c.PostRefreshUpdate(self.context()) - - return nil } + + self.c.PostRefreshUpdate(self.context()) + return nil } func (self *FilesController) edit(nodes []*filetree.FileNode) error { diff --git a/pkg/gui/controllers/helpers/gpg_helper.go b/pkg/gui/controllers/helpers/gpg_helper.go index 65f226067..aabd6964a 100644 --- a/pkg/gui/controllers/helpers/gpg_helper.go +++ b/pkg/gui/controllers/helpers/gpg_helper.go @@ -37,9 +37,9 @@ func (self *GpgHelper) WithGpgHandling(cmdObj *oscommands.CmdObj, configKey git_ } return err - } else { - return self.runAndStream(cmdObj, waitingStatus, onSuccess, refreshScope) } + + return self.runAndStream(cmdObj, waitingStatus, onSuccess, refreshScope) } func (self *GpgHelper) runAndStream(cmdObj *oscommands.CmdObj, waitingStatus string, onSuccess func() error, refreshScope []types.RefreshableView) error { diff --git a/pkg/gui/controllers/helpers/merge_and_rebase_helper.go b/pkg/gui/controllers/helpers/merge_and_rebase_helper.go index 079e2ab68..bd3cee7b7 100644 --- a/pkg/gui/controllers/helpers/merge_and_rebase_helper.go +++ b/pkg/gui/controllers/helpers/merge_and_rebase_helper.go @@ -162,9 +162,8 @@ func (self *MergeAndRebaseHelper) CheckMergeOrRebaseWithRefreshOptions(result er } else if strings.Contains(result.Error(), "No rebase in progress?") { // assume in this case that we're already done return nil - } else { - return self.CheckForConflicts(result) } + return self.CheckForConflicts(result) } func (self *MergeAndRebaseHelper) CheckMergeOrRebase(result error) error { diff --git a/pkg/gui/controllers/helpers/refs_helper.go b/pkg/gui/controllers/helpers/refs_helper.go index 7a7f29d8e..0222f575c 100644 --- a/pkg/gui/controllers/helpers/refs_helper.go +++ b/pkg/gui/controllers/helpers/refs_helper.go @@ -56,9 +56,9 @@ func (self *RefsHelper) CheckoutRef(ref string, options types.CheckoutRefOptions withCheckoutStatus := func(f func(gocui.Task) error) error { if found { return self.c.WithInlineStatus(localBranch, types.ItemOperationCheckingOut, context.LOCAL_BRANCHES_CONTEXT_KEY, f) - } else { - return self.c.WithWaitingStatus(waitingStatus, f) } + + return self.c.WithWaitingStatus(waitingStatus, f) } return withCheckoutStatus(func(gocui.Task) error { diff --git a/pkg/gui/controllers/helpers/window_arrangement_helper.go b/pkg/gui/controllers/helpers/window_arrangement_helper.go index 393b0ffb1..51c5cf37a 100644 --- a/pkg/gui/controllers/helpers/window_arrangement_helper.go +++ b/pkg/gui/controllers/helpers/window_arrangement_helper.go @@ -385,9 +385,8 @@ func splitMainPanelSideBySide(args WindowArrangementArgs) bool { default: if args.Width < 200 && args.Height > 30 { // 2 80 character width panels + 40 width for side panel return false - } else { - return true } + return true } } @@ -431,11 +430,11 @@ func sidePanelChildren(args WindowArrangementArgs) func(width int, height int) [ Window: window, Weight: 1, } - } else { - return &boxlayout.Box{ - Window: window, - Size: 0, - } + } + + return &boxlayout.Box{ + Window: window, + Size: 0, } } @@ -469,33 +468,33 @@ func sidePanelChildren(args WindowArrangementArgs) func(width int, height int) [ accordionBox(&boxlayout.Box{Window: "commits", Weight: 1}), accordionBox(getDefaultStashWindowBox(args)), } - } else { - squashedHeight := 1 - if height >= 21 { - squashedHeight = 3 - } + } - squashedSidePanelBox := func(window string) *boxlayout.Box { - if window == args.CurrentSideWindow { - return &boxlayout.Box{ - Window: window, - Weight: 1, - } - } else { - return &boxlayout.Box{ - Window: window, - Size: squashedHeight, - } + squashedHeight := 1 + if height >= 21 { + squashedHeight = 3 + } + + squashedSidePanelBox := func(window string) *boxlayout.Box { + if window == args.CurrentSideWindow { + return &boxlayout.Box{ + Window: window, + Weight: 1, } } - return []*boxlayout.Box{ - squashedSidePanelBox("status"), - squashedSidePanelBox("files"), - squashedSidePanelBox("branches"), - squashedSidePanelBox("commits"), - squashedSidePanelBox("stash"), + return &boxlayout.Box{ + Window: window, + Size: squashedHeight, } } + + return []*boxlayout.Box{ + squashedSidePanelBox("status"), + squashedSidePanelBox("files"), + squashedSidePanelBox("branches"), + squashedSidePanelBox("commits"), + squashedSidePanelBox("stash"), + } } } diff --git a/pkg/gui/controllers/helpers/working_tree_helper.go b/pkg/gui/controllers/helpers/working_tree_helper.go index 9bff3dbc7..1e8226363 100644 --- a/pkg/gui/controllers/helpers/working_tree_helper.go +++ b/pkg/gui/controllers/helpers/working_tree_helper.go @@ -245,7 +245,7 @@ func (self *WorkingTreeHelper) commitPrefixConfigsForRepo() []config.CommitPrefi cfg, ok := self.c.UserConfig().Git.CommitPrefixes[self.c.Git().RepoPaths.RepoName()] if ok { return append(cfg, self.c.UserConfig().Git.CommitPrefix...) - } else { - return self.c.UserConfig().Git.CommitPrefix } + + return self.c.UserConfig().Git.CommitPrefix } diff --git a/pkg/gui/controllers/helpers/worktree_helper.go b/pkg/gui/controllers/helpers/worktree_helper.go index 2d6460dcb..ac4e01cf6 100644 --- a/pkg/gui/controllers/helpers/worktree_helper.go +++ b/pkg/gui/controllers/helpers/worktree_helper.go @@ -132,24 +132,24 @@ func (self *WorktreeHelper) NewWorktreeCheckout(base string, canCheckoutBase boo }, }) - return nil - } else { - // prompt for the new branch name where a blank means we just check out the branch - self.c.Prompt(types.PromptOpts{ - Title: self.c.Tr.NewBranchName, - HandleConfirm: func(branchName string) error { - if branchName == "" { - return errors.New(self.c.Tr.BranchNameCannotBeBlank) - } - - opts.Branch = branchName - - return f() - }, - }) - return nil } + + // prompt for the new branch name where a blank means we just check out the branch + self.c.Prompt(types.PromptOpts{ + Title: self.c.Tr.NewBranchName, + HandleConfirm: func(branchName string) error { + if branchName == "" { + return errors.New(self.c.Tr.BranchNameCannotBeBlank) + } + + opts.Branch = branchName + + return f() + }, + }) + + return nil }, }) diff --git a/pkg/gui/controllers/sync_controller.go b/pkg/gui/controllers/sync_controller.go index 66c480b93..c1c79fa35 100644 --- a/pkg/gui/controllers/sync_controller.go +++ b/pkg/gui/controllers/sync_controller.go @@ -92,27 +92,27 @@ func (self *SyncController) push(currentBranch *models.Branch) error { opts := pushOpts{remoteBranchStoredLocally: currentBranch.RemoteBranchStoredLocally()} if currentBranch.IsBehindForPush() { return self.requestToForcePush(currentBranch, opts) - } else { - return self.pushAux(currentBranch, opts) } - } else { - if self.c.Git().Config.GetPushToCurrent() { - return self.pushAux(currentBranch, pushOpts{setUpstream: true}) - } else { - return self.c.Helpers().Upstream.PromptForUpstreamWithInitialContent(currentBranch, func(upstream string) error { - upstreamRemote, upstreamBranch, err := self.c.Helpers().Upstream.ParseUpstream(upstream) - if err != nil { - return err - } - return self.pushAux(currentBranch, pushOpts{ - setUpstream: true, - upstreamRemote: upstreamRemote, - upstreamBranch: upstreamBranch, - }) - }) - } + return self.pushAux(currentBranch, opts) } + + if self.c.Git().Config.GetPushToCurrent() { + return self.pushAux(currentBranch, pushOpts{setUpstream: true}) + } + + return self.c.Helpers().Upstream.PromptForUpstreamWithInitialContent(currentBranch, func(upstream string) error { + upstreamRemote, upstreamBranch, err := self.c.Helpers().Upstream.ParseUpstream(upstream) + if err != nil { + return err + } + + return self.pushAux(currentBranch, pushOpts{ + setUpstream: true, + upstreamRemote: upstreamRemote, + upstreamBranch: upstreamBranch, + }) + }) } func (self *SyncController) pull(currentBranch *models.Branch) error { diff --git a/pkg/gui/filetree/file_tree_view_model.go b/pkg/gui/filetree/file_tree_view_model.go index 470c2ca1c..3db39d0a1 100644 --- a/pkg/gui/filetree/file_tree_view_model.go +++ b/pkg/gui/filetree/file_tree_view_model.go @@ -138,9 +138,8 @@ func (self *FileTreeViewModel) findNewSelectedIdx(prevNodes []*FileNode, currNod } if node.File != nil && node.File.IsRename() { return node.File.Names() - } else { - return []string{node.path} } + return []string{node.path} } for _, prevNode := range prevNodes { diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go index 2f65cde8c..f2ea43156 100644 --- a/pkg/gui/gui.go +++ b/pkg/gui/gui.go @@ -611,9 +611,9 @@ func initialScreenMode(startArgs appTypes.StartArgs, config config.AppConfigurer return parseScreenModeArg(startArgs.ScreenMode) } else if startArgs.FilterPath != "" || startArgs.GitArg != appTypes.GitArgNone { return types.SCREEN_HALF - } else { - return parseScreenModeArg(config.GetUserConfig().Gui.ScreenMode) } + + return parseScreenModeArg(config.GetUserConfig().Gui.ScreenMode) } func parseScreenModeArg(screenModeArg string) types.ScreenMode { diff --git a/pkg/gui/information_panel.go b/pkg/gui/information_panel.go index f94ed785a..ab2f3512d 100644 --- a/pkg/gui/information_panel.go +++ b/pkg/gui/information_panel.go @@ -17,9 +17,9 @@ func (gui *Gui) informationStr() string { donate := style.FgMagenta.Sprint(style.PrintHyperlink(gui.c.Tr.Donate, constants.Links.Donate)) askQuestion := style.FgYellow.Sprint(style.PrintHyperlink(gui.c.Tr.AskQuestion, constants.Links.Discussions)) return fmt.Sprintf("%s %s %s", donate, askQuestion, gui.Config.GetVersion()) - } else { - return gui.Config.GetVersion() } + + return gui.Config.GetVersion() } func (gui *Gui) handleInfoClick() error { diff --git a/pkg/gui/keybindings/keybindings.go b/pkg/gui/keybindings/keybindings.go index 923a30c3b..0db3e8a61 100644 --- a/pkg/gui/keybindings/keybindings.go +++ b/pkg/gui/keybindings/keybindings.go @@ -41,9 +41,8 @@ func GetKey(key string) types.Key { binding, ok := config.KeyByLabel[strings.ToLower(key)] if !ok { log.Fatalf("Unrecognized key %s for keybinding. For permitted values see %s", strings.ToLower(key), constants.Links.Docs.CustomKeybindings) - } else { - return binding } + return binding } else if runeCount == 1 { return []rune(key)[0] } diff --git a/pkg/gui/mergeconflicts/merge_conflict.go b/pkg/gui/mergeconflicts/merge_conflict.go index e6b617f57..9b9b72f55 100644 --- a/pkg/gui/mergeconflicts/merge_conflict.go +++ b/pkg/gui/mergeconflicts/merge_conflict.go @@ -50,9 +50,8 @@ func (s Selection) bounds(c *mergeConflict) (int, int) { case TOP: if c.hasAncestor() { return c.start, c.ancestor - } else { - return c.start, c.target } + return c.start, c.target case MIDDLE: return c.ancestor, c.target case BOTTOM: @@ -72,7 +71,6 @@ func (s Selection) selected(c *mergeConflict, idx int) bool { func availableSelections(c *mergeConflict) []Selection { if c.hasAncestor() { return []Selection{TOP, MIDDLE, BOTTOM} - } else { - return []Selection{TOP, BOTTOM} } + return []Selection{TOP, BOTTOM} } diff --git a/pkg/gui/patch_exploring/focus.go b/pkg/gui/patch_exploring/focus.go index c2b43c4a3..3548f09d4 100644 --- a/pkg/gui/patch_exploring/focus.go +++ b/pkg/gui/patch_exploring/focus.go @@ -25,9 +25,8 @@ func calculateNewOriginWithNeededAndWantedIdx(currentOrigin int, bufferHeight in requiredChange := wantToSeeIdx - bottom allowedChange := needToSeeIdx - origin return origin + min(requiredChange, allowedChange) - } else { - return origin } + return origin } func getNeedAndWantLineIdx(firstLineIdx int, lastLineIdx int, selectedLineIdx int, mode selectMode) (int, int) { @@ -37,9 +36,8 @@ func getNeedAndWantLineIdx(firstLineIdx int, lastLineIdx int, selectedLineIdx in case RANGE: if selectedLineIdx == firstLineIdx { return firstLineIdx, lastLineIdx - } else { - return lastLineIdx, firstLineIdx } + return lastLineIdx, firstLineIdx case HUNK: return firstLineIdx, lastLineIdx default: diff --git a/pkg/gui/patch_exploring/state.go b/pkg/gui/patch_exploring/state.go index 73ce0a756..53e120849 100644 --- a/pkg/gui/patch_exploring/state.go +++ b/pkg/gui/patch_exploring/state.go @@ -267,9 +267,8 @@ func (s *State) SelectedViewRange() (int, int) { case RANGE: if s.rangeStartLineIdx > s.selectedLineIdx { return s.selectedLineIdx, s.rangeStartLineIdx - } else { - return s.rangeStartLineIdx, s.selectedLineIdx } + return s.rangeStartLineIdx, s.selectedLineIdx case LINE: return s.selectedLineIdx, s.selectedLineIdx default: diff --git a/pkg/gui/presentation/commits.go b/pkg/gui/presentation/commits.go index 63c2b3c9b..a5799bcb3 100644 --- a/pkg/gui/presentation/commits.go +++ b/pkg/gui/presentation/commits.go @@ -145,9 +145,8 @@ func GetCommitListDisplayStrings( getGraphLine = func(idx int) string { if idx >= graphOffset { return graphLines[idx-graphOffset] - } else { - return "" } + return "" } } } else { @@ -305,9 +304,8 @@ func getBisectStatus(index int, commitHash string, bisectInfo *git_commands.Bise } else { if bisectBounds != nil && index >= bisectBounds.newIndex && index <= bisectBounds.oldIndex { return BisectStatusCandidate - } else { - return BisectStatusNone } + return BisectStatusNone } // should never land here diff --git a/pkg/gui/presentation/files.go b/pkg/gui/presentation/files.go index 4222fb68d..cc0a93889 100644 --- a/pkg/gui/presentation/files.go +++ b/pkg/gui/presentation/files.go @@ -63,9 +63,8 @@ func commitFilePatchStatus(node *filetree.Node[models.CommitFile], tree *filetre return patchBuilder.GetFileStatus(file.Path, tree.GetRef().RefName()) == patch.UNSELECTED }) { return patch.UNSELECTED - } else { - return patch.PART } + return patch.PART } func renderAux[T any]( diff --git a/pkg/gui/presentation/graph/cell.go b/pkg/gui/presentation/graph/cell.go index a890613f0..be039a018 100644 --- a/pkg/gui/presentation/graph/cell.go +++ b/pkg/gui/presentation/graph/cell.go @@ -177,7 +177,7 @@ func getBoxDrawingChars(up, down, left, right bool) (string, string) { return "╶", "─" } else if !up && !down && !left && !right { return " ", " " - } else { - panic("should not be possible") } + + panic("should not be possible") } diff --git a/pkg/gui/presentation/graph/graph.go b/pkg/gui/presentation/graph/graph.go index fc33f3135..1639a62e6 100644 --- a/pkg/gui/presentation/graph/graph.go +++ b/pkg/gui/presentation/graph/graph.go @@ -246,9 +246,8 @@ func getNextPipes(prevPipes []Pipe, commit *models.Commit, getStyle func(c *mode for i := pipe.toPos; i > pos; i-- { if takenSpots.Includes(int(i)) || traversedSpots.Includes(int(i)) { break - } else { - last = i } + last = i } newPipes = append(newPipes, Pipe{ fromPos: pipe.toPos, diff --git a/pkg/tasks/tasks.go b/pkg/tasks/tasks.go index 8de96b249..5de7fb232 100644 --- a/pkg/tasks/tasks.go +++ b/pkg/tasks/tasks.go @@ -260,7 +260,7 @@ func (self *ViewBufferManager) NewCmdTask(start func() (*exec.Cmd, io.Reader), p callThen() break outer case line, ok = <-lineChan: - break + // process line below } loadingMutex.Lock() diff --git a/pkg/tasks/tasks_test.go b/pkg/tasks/tasks_test.go index 72da6d83c..c7a499d46 100644 --- a/pkg/tasks/tasks_test.go +++ b/pkg/tasks/tasks_test.go @@ -167,7 +167,7 @@ func (d *BlankLineReader) Read(p []byte) (n int, err error) { return 0, io.EOF } - d.linesYielded += 1 + d.linesYielded++ p[0] = '\n' return 1, nil } diff --git a/pkg/utils/formatting.go b/pkg/utils/formatting.go index 08cc7d49a..0e5a6ee03 100644 --- a/pkg/utils/formatting.go +++ b/pkg/utils/formatting.go @@ -44,9 +44,8 @@ func WithPadding(str string, padding int, alignment Alignment) string { space := strings.Repeat(" ", padding-width) if alignment == AlignLeft { return str + space - } else { - return space + str } + return space + str } // defaults to left-aligning each column. If you want to set the alignment of @@ -187,9 +186,8 @@ func TruncateWithEllipsis(str string, limit int) string { func SafeTruncate(str string, limit int) string { if len(str) > limit { return str[0:limit] - } else { - return str } + return str } const COMMIT_HASH_SHORT_SIZE = 8 diff --git a/pkg/utils/once_writer_test.go b/pkg/utils/once_writer_test.go index 47f64bb61..aa57ff163 100644 --- a/pkg/utils/once_writer_test.go +++ b/pkg/utils/once_writer_test.go @@ -9,7 +9,7 @@ func TestOnceWriter(t *testing.T) { innerWriter := bytes.NewBuffer(nil) counter := 0 onceWriter := NewOnceWriter(innerWriter, func() { - counter += 1 + counter++ }) _, _ = onceWriter.Write([]byte("hello")) _, _ = onceWriter.Write([]byte("hello")) diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go index 5eecc6e70..950555512 100644 --- a/pkg/utils/utils.go +++ b/pkg/utils/utils.go @@ -45,9 +45,8 @@ func ModuloWithWrap(n, max int) int { return n % max } else if n < 0 { return max + n - } else { - return n } + return n } func FindStringSubmatch(str string, regexpStr string) (bool, []string) { diff --git a/pkg/utils/yaml_utils/yaml_utils_test.go b/pkg/utils/yaml_utils/yaml_utils_test.go index 9ae099396..d4d1fe074 100644 --- a/pkg/utils/yaml_utils/yaml_utils_test.go +++ b/pkg/utils/yaml_utils/yaml_utils_test.go @@ -224,12 +224,10 @@ func TestTransformNode(t *testing.T) { } else if node.ShortTag() == "!!str" { // We have already transformed it, return nil - } else { - return fmt.Errorf("Node was of bad type") } - } else { - return fmt.Errorf("Node was not a scalar") + return fmt.Errorf("Node was of bad type") } + return fmt.Errorf("Node was not a scalar") } tests := []struct {