diff --git a/pkg/commands/git_commands/commit_loader.go b/pkg/commands/git_commands/commit_loader.go index 6bce06360..08ee08313 100644 --- a/pkg/commands/git_commands/commit_loader.go +++ b/pkg/commands/git_commands/commit_loader.go @@ -31,7 +31,7 @@ type CommitLoader struct { *common.Common cmd oscommands.ICmdObjBuilder - getWorkingTreeState func() enums.RebaseMode + getWorkingTreeState func() enums.WorkingTreeState readFile func(filename string) ([]byte, error) walkFiles func(root string, fn filepath.WalkFunc) error dotGitDir string @@ -42,7 +42,7 @@ type CommitLoader struct { func NewCommitLoader( cmn *common.Common, cmd oscommands.ICmdObjBuilder, - getWorkingTreeState func() enums.RebaseMode, + getWorkingTreeState func() enums.WorkingTreeState, gitCommon *GitCommon, ) *CommitLoader { return &CommitLoader{ diff --git a/pkg/commands/git_commands/commit_loader_test.go b/pkg/commands/git_commands/commit_loader_test.go index 631270abc..9aac43d11 100644 --- a/pkg/commands/git_commands/commit_loader_test.go +++ b/pkg/commands/git_commands/commit_loader_test.go @@ -304,7 +304,7 @@ func TestGetCommits(t *testing.T) { builder := &CommitLoader{ Common: common, cmd: cmd, - getWorkingTreeState: func() enums.RebaseMode { return enums.REBASE_MODE_NONE }, + getWorkingTreeState: func() enums.WorkingTreeState { return enums.WORKING_TREE_STATE_NONE }, dotGitDir: ".git", readFile: func(filename string) ([]byte, error) { return []byte(""), nil @@ -487,7 +487,7 @@ func TestCommitLoader_getConflictedCommitImpl(t *testing.T) { builder := &CommitLoader{ Common: common, cmd: oscommands.NewDummyCmdObjBuilder(oscommands.NewFakeRunner(t)), - getWorkingTreeState: func() enums.RebaseMode { return enums.REBASE_MODE_REBASING }, + getWorkingTreeState: func() enums.WorkingTreeState { return enums.WORKING_TREE_STATE_REBASING }, dotGitDir: ".git", readFile: func(filename string) ([]byte, error) { return []byte(""), nil diff --git a/pkg/commands/git_commands/patch.go b/pkg/commands/git_commands/patch.go index 36e094337..daa1030d4 100644 --- a/pkg/commands/git_commands/patch.go +++ b/pkg/commands/git_commands/patch.go @@ -229,7 +229,7 @@ func (self *PatchCommands) MovePatchIntoIndex(commits []*models.Commit, commitId } if err := self.ApplyCustomPatch(true, true); err != nil { - if self.status.WorkingTreeState() == enums.REBASE_MODE_REBASING { + if self.status.WorkingTreeState() == enums.WORKING_TREE_STATE_REBASING { _ = self.rebase.AbortRebase() } return err @@ -253,7 +253,7 @@ func (self *PatchCommands) MovePatchIntoIndex(commits []*models.Commit, commitId self.rebase.onSuccessfulContinue = func() error { // add patches to index if err := self.ApplyPatch(patch, ApplyPatchOpts{Index: true, ThreeWay: true}); err != nil { - if self.status.WorkingTreeState() == enums.REBASE_MODE_REBASING { + if self.status.WorkingTreeState() == enums.WORKING_TREE_STATE_REBASING { _ = self.rebase.AbortRebase() } return err diff --git a/pkg/commands/git_commands/status.go b/pkg/commands/git_commands/status.go index ff1499ec9..ba4fdb679 100644 --- a/pkg/commands/git_commands/status.go +++ b/pkg/commands/git_commands/status.go @@ -20,16 +20,16 @@ func NewStatusCommands( } } -func (self *StatusCommands) WorkingTreeState() enums.RebaseMode { +func (self *StatusCommands) WorkingTreeState() enums.WorkingTreeState { isInRebase, _ := self.IsInRebase() if isInRebase { - return enums.REBASE_MODE_REBASING + return enums.WORKING_TREE_STATE_REBASING } merging, _ := self.IsInMergeState() if merging { - return enums.REBASE_MODE_MERGING + return enums.WORKING_TREE_STATE_MERGING } - return enums.REBASE_MODE_NONE + return enums.WORKING_TREE_STATE_NONE } func (self *StatusCommands) IsBareRepo() bool { diff --git a/pkg/commands/types/enums/enums.go b/pkg/commands/types/enums/enums.go index 790cb1f5c..8513b074e 100644 --- a/pkg/commands/types/enums/enums.go +++ b/pkg/commands/types/enums/enums.go @@ -1,18 +1,18 @@ package enums -type RebaseMode int +type WorkingTreeState int const ( // this means we're neither rebasing nor merging - REBASE_MODE_NONE RebaseMode = iota - REBASE_MODE_REBASING - REBASE_MODE_MERGING + WORKING_TREE_STATE_NONE WorkingTreeState = iota + WORKING_TREE_STATE_REBASING + WORKING_TREE_STATE_MERGING ) -func (self RebaseMode) IsMerging() bool { - return self == REBASE_MODE_MERGING +func (self WorkingTreeState) IsMerging() bool { + return self == WORKING_TREE_STATE_MERGING } -func (self RebaseMode) IsRebasing() bool { - return self == REBASE_MODE_REBASING +func (self WorkingTreeState) IsRebasing() bool { + return self == WORKING_TREE_STATE_REBASING } diff --git a/pkg/gui/context/local_commits_context.go b/pkg/gui/context/local_commits_context.go index 4f2f797e5..9f6c2f5f1 100644 --- a/pkg/gui/context/local_commits_context.go +++ b/pkg/gui/context/local_commits_context.go @@ -41,7 +41,7 @@ func NewLocalCommitsContext(c *ContextCommon) *LocalCommitsContext { } } - showYouAreHereLabel := c.Model().WorkingTreeStateAtLastCommitRefresh == enums.REBASE_MODE_REBASING + showYouAreHereLabel := c.Model().WorkingTreeStateAtLastCommitRefresh == enums.WORKING_TREE_STATE_REBASING hasRebaseUpdateRefsConfig := c.Git().Config.GetRebaseUpdateRefs() return presentation.GetCommitListDisplayStrings( diff --git a/pkg/gui/controllers/custom_patch_options_menu_action.go b/pkg/gui/controllers/custom_patch_options_menu_action.go index ced98b072..5208cfb15 100644 --- a/pkg/gui/controllers/custom_patch_options_menu_action.go +++ b/pkg/gui/controllers/custom_patch_options_menu_action.go @@ -44,7 +44,7 @@ func (self *CustomPatchOptionsMenuAction) Call() error { }, } - if self.c.Git().Patch.PatchBuilder.CanRebase && self.c.Git().Status.WorkingTreeState() == enums.REBASE_MODE_NONE { + if self.c.Git().Patch.PatchBuilder.CanRebase && self.c.Git().Status.WorkingTreeState() == enums.WORKING_TREE_STATE_NONE { menuItems = append(menuItems, []*types.MenuItem{ { Label: fmt.Sprintf(self.c.Tr.RemovePatchFromOriginalCommit, self.c.Git().Patch.PatchBuilder.To), @@ -115,7 +115,7 @@ func (self *CustomPatchOptionsMenuAction) getPatchCommitIndex() int { } func (self *CustomPatchOptionsMenuAction) validateNormalWorkingTreeState() (bool, error) { - if self.c.Git().Status.WorkingTreeState() != enums.REBASE_MODE_NONE { + if self.c.Git().Status.WorkingTreeState() != enums.WORKING_TREE_STATE_NONE { return false, errors.New(self.c.Tr.CantPatchWhileRebasingError) } return true, nil diff --git a/pkg/gui/controllers/helpers/merge_and_rebase_helper.go b/pkg/gui/controllers/helpers/merge_and_rebase_helper.go index fba0b9014..565df9226 100644 --- a/pkg/gui/controllers/helpers/merge_and_rebase_helper.go +++ b/pkg/gui/controllers/helpers/merge_and_rebase_helper.go @@ -51,7 +51,7 @@ func (self *MergeAndRebaseHelper) CreateRebaseOptionsMenu() error { {option: REBASE_OPTION_ABORT, key: 'a'}, } - if self.c.Git().Status.WorkingTreeState() == enums.REBASE_MODE_REBASING { + if self.c.Git().Status.WorkingTreeState() == enums.WORKING_TREE_STATE_REBASING { options = append(options, optionAndKey{ option: REBASE_OPTION_SKIP, key: 's', }) @@ -68,7 +68,7 @@ func (self *MergeAndRebaseHelper) CreateRebaseOptionsMenu() error { }) var title string - if self.c.Git().Status.WorkingTreeState() == enums.REBASE_MODE_MERGING { + if self.c.Git().Status.WorkingTreeState() == enums.WORKING_TREE_STATE_MERGING { title = self.c.Tr.MergeOptionsTitle } else { title = self.c.Tr.RebaseOptionsTitle @@ -84,12 +84,12 @@ func (self *MergeAndRebaseHelper) ContinueRebase() error { func (self *MergeAndRebaseHelper) genericMergeCommand(command string) error { status := self.c.Git().Status.WorkingTreeState() - if status != enums.REBASE_MODE_MERGING && status != enums.REBASE_MODE_REBASING { + if status != enums.WORKING_TREE_STATE_MERGING && status != enums.WORKING_TREE_STATE_REBASING { return errors.New(self.c.Tr.NotMergingOrRebasing) } self.c.LogAction(fmt.Sprintf("Merge/Rebase: %s", command)) - if status == enums.REBASE_MODE_REBASING { + if status == enums.WORKING_TREE_STATE_REBASING { todoFile, err := os.ReadFile( filepath.Join(self.c.Git().RepoPaths.WorktreeGitDirPath(), "rebase-merge/git-rebase-todo"), ) @@ -105,9 +105,9 @@ func (self *MergeAndRebaseHelper) genericMergeCommand(command string) error { commandType := "" switch status { - case enums.REBASE_MODE_MERGING: + case enums.WORKING_TREE_STATE_MERGING: commandType = "merge" - case enums.REBASE_MODE_REBASING: + case enums.WORKING_TREE_STATE_REBASING: commandType = "rebase" default: // shouldn't be possible to land here @@ -116,10 +116,10 @@ func (self *MergeAndRebaseHelper) genericMergeCommand(command string) error { // we should end up with a command like 'git merge --continue' // it's impossible for a rebase to require a commit so we'll use a subprocess only if it's a merge - needsSubprocess := (status == enums.REBASE_MODE_MERGING && command != REBASE_OPTION_ABORT && self.c.UserConfig().Git.Merging.ManualCommit) || + needsSubprocess := (status == enums.WORKING_TREE_STATE_MERGING && command != REBASE_OPTION_ABORT && self.c.UserConfig().Git.Merging.ManualCommit) || // but we'll also use a subprocess if we have exec todos; those are likely to be lengthy build // tasks whose output the user will want to see in the terminal - (status == enums.REBASE_MODE_REBASING && command != REBASE_OPTION_ABORT && self.hasExecTodos()) + (status == enums.WORKING_TREE_STATE_REBASING && command != REBASE_OPTION_ABORT && self.hasExecTodos()) if needsSubprocess { // TODO: see if we should be calling more of the code from self.Git.Rebase.GenericMergeOrRebaseAction @@ -239,9 +239,9 @@ func (self *MergeAndRebaseHelper) AbortMergeOrRebaseWithConfirm() error { func (self *MergeAndRebaseHelper) workingTreeStateNoun() string { workingTreeState := self.c.Git().Status.WorkingTreeState() switch workingTreeState { - case enums.REBASE_MODE_NONE: + case enums.WORKING_TREE_STATE_NONE: return "" - case enums.REBASE_MODE_MERGING: + case enums.WORKING_TREE_STATE_MERGING: return "merge" default: return "rebase" diff --git a/pkg/gui/controllers/helpers/mode_helper.go b/pkg/gui/controllers/helpers/mode_helper.go index 579862155..0259be97e 100644 --- a/pkg/gui/controllers/helpers/mode_helper.go +++ b/pkg/gui/controllers/helpers/mode_helper.go @@ -116,7 +116,7 @@ func (self *ModeHelper) Statuses() []ModeStatus { }, { IsActive: func() bool { - return !self.suppressRebasingMode && self.c.Git().Status.WorkingTreeState() != enums.REBASE_MODE_NONE + return !self.suppressRebasingMode && self.c.Git().Status.WorkingTreeState() != enums.WORKING_TREE_STATE_NONE }, Description: func() string { workingTreeState := self.c.Git().Status.WorkingTreeState() diff --git a/pkg/gui/controllers/helpers/patch_building_helper.go b/pkg/gui/controllers/helpers/patch_building_helper.go index 1cf64b3f8..2deb19d9c 100644 --- a/pkg/gui/controllers/helpers/patch_building_helper.go +++ b/pkg/gui/controllers/helpers/patch_building_helper.go @@ -22,7 +22,7 @@ func NewPatchBuildingHelper( } func (self *PatchBuildingHelper) ValidateNormalWorkingTreeState() (bool, error) { - if self.c.Git().Status.WorkingTreeState() != enums.REBASE_MODE_NONE { + if self.c.Git().Status.WorkingTreeState() != enums.WORKING_TREE_STATE_NONE { return false, errors.New(self.c.Tr.CantPatchWhileRebasingError) } return true, nil diff --git a/pkg/gui/controllers/helpers/refresh_helper.go b/pkg/gui/controllers/helpers/refresh_helper.go index 33347a363..9e6dff1dd 100644 --- a/pkg/gui/controllers/helpers/refresh_helper.go +++ b/pkg/gui/controllers/helpers/refresh_helper.go @@ -583,7 +583,7 @@ func (self *RefreshHelper) refreshStateFiles() error { } } - if self.c.Git().Status.WorkingTreeState() != enums.REBASE_MODE_NONE && conflictFileCount == 0 && prevConflictFileCount > 0 { + if self.c.Git().Status.WorkingTreeState() != enums.WORKING_TREE_STATE_NONE && conflictFileCount == 0 && prevConflictFileCount > 0 { self.c.OnUIThread(func() error { return self.mergeAndRebaseHelper.PromptToContinueRebase() }) } diff --git a/pkg/gui/controllers/local_commits_controller.go b/pkg/gui/controllers/local_commits_controller.go index 79e3a6549..4e7f652e0 100644 --- a/pkg/gui/controllers/local_commits_controller.go +++ b/pkg/gui/controllers/local_commits_controller.go @@ -682,7 +682,7 @@ func (self *LocalCommitsController) rewordEnabled(commit *models.Commit) *types. } func (self *LocalCommitsController) isRebasing() bool { - return self.c.Model().WorkingTreeStateAtLastCommitRefresh != enums.REBASE_MODE_NONE + return self.c.Model().WorkingTreeStateAtLastCommitRefresh != enums.WORKING_TREE_STATE_NONE } func (self *LocalCommitsController) moveDown(selectedCommits []*models.Commit, startIdx int, endIdx int) error { @@ -976,7 +976,7 @@ func (self *LocalCommitsController) moveFixupCommitToOwnerStackedBranch(targetCo return nil } - if self.c.Git().Status.WorkingTreeState() != enums.REBASE_MODE_NONE { + if self.c.Git().Status.WorkingTreeState() != enums.WORKING_TREE_STATE_NONE { // Can't move commits while rebasing return nil } diff --git a/pkg/gui/controllers/status_controller.go b/pkg/gui/controllers/status_controller.go index d517b870c..a0012227b 100644 --- a/pkg/gui/controllers/status_controller.go +++ b/pkg/gui/controllers/status_controller.go @@ -110,7 +110,7 @@ func (self *StatusController) onClick(opts gocui.ViewMouseBindingOpts) error { repoName := self.c.Git().RepoPaths.RepoName() workingTreeState := self.c.Git().Status.WorkingTreeState() switch workingTreeState { - case enums.REBASE_MODE_REBASING, enums.REBASE_MODE_MERGING: + case enums.WORKING_TREE_STATE_REBASING, enums.WORKING_TREE_STATE_MERGING: workingTreeStatus := fmt.Sprintf("(%s)", presentation.FormatWorkingTreeStateLower(self.c.Tr, workingTreeState)) if cursorInSubstring(opts.X, upstreamStatus+" ", workingTreeStatus) { return self.c.Helpers().MergeAndRebase.CreateRebaseOptionsMenu() diff --git a/pkg/gui/controllers/undo_controller.go b/pkg/gui/controllers/undo_controller.go index 198aa7d7b..b00eb802f 100644 --- a/pkg/gui/controllers/undo_controller.go +++ b/pkg/gui/controllers/undo_controller.go @@ -78,7 +78,7 @@ func (self *UndoController) reflogUndo() error { undoEnvVars := []string{"GIT_REFLOG_ACTION=[lazygit undo]"} undoingStatus := self.c.Tr.UndoingStatus - if self.c.Git().Status.WorkingTreeState() == enums.REBASE_MODE_REBASING { + if self.c.Git().Status.WorkingTreeState() == enums.WORKING_TREE_STATE_REBASING { return errors.New(self.c.Tr.CantUndoWhileRebasing) } @@ -142,7 +142,7 @@ func (self *UndoController) reflogRedo() error { redoEnvVars := []string{"GIT_REFLOG_ACTION=[lazygit redo]"} redoingStatus := self.c.Tr.RedoingStatus - if self.c.Git().Status.WorkingTreeState() == enums.REBASE_MODE_REBASING { + if self.c.Git().Status.WorkingTreeState() == enums.WORKING_TREE_STATE_REBASING { return errors.New(self.c.Tr.CantRedoWhileRebasing) } diff --git a/pkg/gui/presentation/status.go b/pkg/gui/presentation/status.go index b3b210067..3cc137b35 100644 --- a/pkg/gui/presentation/status.go +++ b/pkg/gui/presentation/status.go @@ -18,7 +18,7 @@ func FormatStatus( currentBranch *models.Branch, itemOperation types.ItemOperation, linkedWorktreeName string, - workingTreeState enums.RebaseMode, + workingTreeState enums.WorkingTreeState, tr *i18n.TranslationSet, userConfig *config.UserConfig, ) string { @@ -31,7 +31,7 @@ func FormatStatus( } } - if workingTreeState != enums.REBASE_MODE_NONE { + if workingTreeState != enums.WORKING_TREE_STATE_NONE { status += style.FgYellow.Sprintf("(%s) ", FormatWorkingTreeStateLower(tr, workingTreeState)) } diff --git a/pkg/gui/presentation/working_tree.go b/pkg/gui/presentation/working_tree.go index 1e1954bc9..1e2eadd1a 100644 --- a/pkg/gui/presentation/working_tree.go +++ b/pkg/gui/presentation/working_tree.go @@ -5,11 +5,11 @@ import ( "github.com/jesseduffield/lazygit/pkg/i18n" ) -func FormatWorkingTreeStateTitle(tr *i18n.TranslationSet, rebaseMode enums.RebaseMode) string { - switch rebaseMode { - case enums.REBASE_MODE_REBASING: +func FormatWorkingTreeStateTitle(tr *i18n.TranslationSet, workingTreeState enums.WorkingTreeState) string { + switch workingTreeState { + case enums.WORKING_TREE_STATE_REBASING: return tr.RebasingStatus - case enums.REBASE_MODE_MERGING: + case enums.WORKING_TREE_STATE_MERGING: return tr.MergingStatus default: // should never actually display this @@ -17,11 +17,11 @@ func FormatWorkingTreeStateTitle(tr *i18n.TranslationSet, rebaseMode enums.Rebas } } -func FormatWorkingTreeStateLower(tr *i18n.TranslationSet, rebaseMode enums.RebaseMode) string { - switch rebaseMode { - case enums.REBASE_MODE_REBASING: +func FormatWorkingTreeStateLower(tr *i18n.TranslationSet, workingTreeState enums.WorkingTreeState) string { + switch workingTreeState { + case enums.WORKING_TREE_STATE_REBASING: return tr.LowercaseRebasingStatus - case enums.REBASE_MODE_MERGING: + case enums.WORKING_TREE_STATE_MERGING: return tr.LowercaseMergingStatus default: // should never actually display this diff --git a/pkg/gui/types/common.go b/pkg/gui/types/common.go index 82a309fb1..afa0bf2a4 100644 --- a/pkg/gui/types/common.go +++ b/pkg/gui/types/common.go @@ -288,7 +288,7 @@ type Model struct { ReflogCommits []*models.Commit BisectInfo *git_commands.BisectInfo - WorkingTreeStateAtLastCommitRefresh enums.RebaseMode + WorkingTreeStateAtLastCommitRefresh enums.WorkingTreeState RemoteBranches []*models.RemoteBranch Tags []*models.Tag