Skip to content

Commit 8af8f77

Browse files
committed
Move types/enums/enums.go to working_tree_state.go
It looks like enums.go was supposed to be file that collects a bunch of enums, but actually there's only one in there, and since it has methods, it deserves to be in a file of its own, named after the type.
1 parent e1eb95b commit 8af8f77

16 files changed

+36
-45
lines changed

pkg/commands/git_commands/commit_loader.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313

1414
"github.com/jesseduffield/lazygit/pkg/commands/models"
1515
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
16-
"github.com/jesseduffield/lazygit/pkg/commands/types/enums"
1716
"github.com/jesseduffield/lazygit/pkg/common"
1817
"github.com/jesseduffield/lazygit/pkg/utils"
1918
"github.com/samber/lo"
@@ -31,7 +30,7 @@ type CommitLoader struct {
3130
*common.Common
3231
cmd oscommands.ICmdObjBuilder
3332

34-
getWorkingTreeState func() enums.WorkingTreeState
33+
getWorkingTreeState func() models.WorkingTreeState
3534
readFile func(filename string) ([]byte, error)
3635
walkFiles func(root string, fn filepath.WalkFunc) error
3736
dotGitDir string
@@ -42,7 +41,7 @@ type CommitLoader struct {
4241
func NewCommitLoader(
4342
cmn *common.Common,
4443
cmd oscommands.ICmdObjBuilder,
45-
getWorkingTreeState func() enums.WorkingTreeState,
44+
getWorkingTreeState func() models.WorkingTreeState,
4645
gitCommon *GitCommon,
4746
) *CommitLoader {
4847
return &CommitLoader{

pkg/commands/git_commands/commit_loader_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"github.com/go-errors/errors"
99
"github.com/jesseduffield/lazygit/pkg/commands/models"
1010
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
11-
"github.com/jesseduffield/lazygit/pkg/commands/types/enums"
1211
"github.com/jesseduffield/lazygit/pkg/config"
1312
"github.com/jesseduffield/lazygit/pkg/utils"
1413
"github.com/stefanhaller/git-todo-parser/todo"
@@ -304,7 +303,7 @@ func TestGetCommits(t *testing.T) {
304303
builder := &CommitLoader{
305304
Common: common,
306305
cmd: cmd,
307-
getWorkingTreeState: func() enums.WorkingTreeState { return enums.WORKING_TREE_STATE_NONE },
306+
getWorkingTreeState: func() models.WorkingTreeState { return models.WORKING_TREE_STATE_NONE },
308307
dotGitDir: ".git",
309308
readFile: func(filename string) ([]byte, error) {
310309
return []byte(""), nil
@@ -487,7 +486,7 @@ func TestCommitLoader_getConflictedCommitImpl(t *testing.T) {
487486
builder := &CommitLoader{
488487
Common: common,
489488
cmd: oscommands.NewDummyCmdObjBuilder(oscommands.NewFakeRunner(t)),
490-
getWorkingTreeState: func() enums.WorkingTreeState { return enums.WORKING_TREE_STATE_REBASING },
489+
getWorkingTreeState: func() models.WorkingTreeState { return models.WORKING_TREE_STATE_REBASING },
491490
dotGitDir: ".git",
492491
readFile: func(filename string) ([]byte, error) {
493492
return []byte(""), nil

pkg/commands/git_commands/patch.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"github.com/jesseduffield/lazygit/pkg/app/daemon"
99
"github.com/jesseduffield/lazygit/pkg/commands/models"
1010
"github.com/jesseduffield/lazygit/pkg/commands/patch"
11-
"github.com/jesseduffield/lazygit/pkg/commands/types/enums"
1211
"github.com/stefanhaller/git-todo-parser/todo"
1312
)
1413

@@ -229,7 +228,7 @@ func (self *PatchCommands) MovePatchIntoIndex(commits []*models.Commit, commitId
229228
}
230229

231230
if err := self.ApplyCustomPatch(true, true); err != nil {
232-
if self.status.WorkingTreeState() == enums.WORKING_TREE_STATE_REBASING {
231+
if self.status.WorkingTreeState() == models.WORKING_TREE_STATE_REBASING {
233232
_ = self.rebase.AbortRebase()
234233
}
235234
return err
@@ -253,7 +252,7 @@ func (self *PatchCommands) MovePatchIntoIndex(commits []*models.Commit, commitId
253252
self.rebase.onSuccessfulContinue = func() error {
254253
// add patches to index
255254
if err := self.ApplyPatch(patch, ApplyPatchOpts{Index: true, ThreeWay: true}); err != nil {
256-
if self.status.WorkingTreeState() == enums.WORKING_TREE_STATE_REBASING {
255+
if self.status.WorkingTreeState() == models.WORKING_TREE_STATE_REBASING {
257256
_ = self.rebase.AbortRebase()
258257
}
259258
return err

pkg/commands/git_commands/status.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"path/filepath"
66
"strings"
77

8-
"github.com/jesseduffield/lazygit/pkg/commands/types/enums"
8+
"github.com/jesseduffield/lazygit/pkg/commands/models"
99
)
1010

1111
type StatusCommands struct {
@@ -20,16 +20,16 @@ func NewStatusCommands(
2020
}
2121
}
2222

23-
func (self *StatusCommands) WorkingTreeState() enums.WorkingTreeState {
23+
func (self *StatusCommands) WorkingTreeState() models.WorkingTreeState {
2424
isInRebase, _ := self.IsInRebase()
2525
if isInRebase {
26-
return enums.WORKING_TREE_STATE_REBASING
26+
return models.WORKING_TREE_STATE_REBASING
2727
}
2828
merging, _ := self.IsInMergeState()
2929
if merging {
30-
return enums.WORKING_TREE_STATE_MERGING
30+
return models.WORKING_TREE_STATE_MERGING
3131
}
32-
return enums.WORKING_TREE_STATE_NONE
32+
return models.WORKING_TREE_STATE_NONE
3333
}
3434

3535
func (self *StatusCommands) IsBareRepo() bool {

pkg/commands/types/enums/enums.go renamed to pkg/commands/models/working_tree_state.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package enums
1+
package models
22

33
import "github.com/jesseduffield/lazygit/pkg/i18n"
44

pkg/gui/context/local_commits_context.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77

88
"github.com/jesseduffield/gocui"
99
"github.com/jesseduffield/lazygit/pkg/commands/models"
10-
"github.com/jesseduffield/lazygit/pkg/commands/types/enums"
1110
"github.com/jesseduffield/lazygit/pkg/gui/presentation"
1211
"github.com/jesseduffield/lazygit/pkg/gui/types"
1312
"github.com/samber/lo"
@@ -41,7 +40,7 @@ func NewLocalCommitsContext(c *ContextCommon) *LocalCommitsContext {
4140
}
4241
}
4342

44-
showYouAreHereLabel := c.Model().WorkingTreeStateAtLastCommitRefresh == enums.WORKING_TREE_STATE_REBASING
43+
showYouAreHereLabel := c.Model().WorkingTreeStateAtLastCommitRefresh == models.WORKING_TREE_STATE_REBASING
4544
hasRebaseUpdateRefsConfig := c.Git().Config.GetRebaseUpdateRefs()
4645

4746
return presentation.GetCommitListDisplayStrings(

pkg/gui/controllers/custom_patch_options_menu_action.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"fmt"
66

77
"github.com/jesseduffield/gocui"
8-
"github.com/jesseduffield/lazygit/pkg/commands/types/enums"
8+
"github.com/jesseduffield/lazygit/pkg/commands/models"
99
"github.com/jesseduffield/lazygit/pkg/gui/controllers/helpers"
1010
"github.com/jesseduffield/lazygit/pkg/gui/types"
1111
)
@@ -44,7 +44,7 @@ func (self *CustomPatchOptionsMenuAction) Call() error {
4444
},
4545
}
4646

47-
if self.c.Git().Patch.PatchBuilder.CanRebase && self.c.Git().Status.WorkingTreeState() == enums.WORKING_TREE_STATE_NONE {
47+
if self.c.Git().Patch.PatchBuilder.CanRebase && self.c.Git().Status.WorkingTreeState() == models.WORKING_TREE_STATE_NONE {
4848
menuItems = append(menuItems, []*types.MenuItem{
4949
{
5050
Label: fmt.Sprintf(self.c.Tr.RemovePatchFromOriginalCommit, self.c.Git().Patch.PatchBuilder.To),
@@ -115,7 +115,7 @@ func (self *CustomPatchOptionsMenuAction) getPatchCommitIndex() int {
115115
}
116116

117117
func (self *CustomPatchOptionsMenuAction) validateNormalWorkingTreeState() (bool, error) {
118-
if self.c.Git().Status.WorkingTreeState() != enums.WORKING_TREE_STATE_NONE {
118+
if self.c.Git().Status.WorkingTreeState() != models.WORKING_TREE_STATE_NONE {
119119
return false, errors.New(self.c.Tr.CantPatchWhileRebasingError)
120120
}
121121
return true, nil

pkg/gui/controllers/helpers/merge_and_rebase_helper.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"github.com/jesseduffield/gocui"
1111
"github.com/jesseduffield/lazygit/pkg/commands/git_commands"
1212
"github.com/jesseduffield/lazygit/pkg/commands/models"
13-
"github.com/jesseduffield/lazygit/pkg/commands/types/enums"
1413
"github.com/jesseduffield/lazygit/pkg/gui/types"
1514
"github.com/jesseduffield/lazygit/pkg/utils"
1615
"github.com/samber/lo"
@@ -51,7 +50,7 @@ func (self *MergeAndRebaseHelper) CreateRebaseOptionsMenu() error {
5150
{option: REBASE_OPTION_ABORT, key: 'a'},
5251
}
5352

54-
if self.c.Git().Status.WorkingTreeState() == enums.WORKING_TREE_STATE_REBASING {
53+
if self.c.Git().Status.WorkingTreeState() == models.WORKING_TREE_STATE_REBASING {
5554
options = append(options, optionAndKey{
5655
option: REBASE_OPTION_SKIP, key: 's',
5756
})
@@ -78,12 +77,12 @@ func (self *MergeAndRebaseHelper) ContinueRebase() error {
7877
func (self *MergeAndRebaseHelper) genericMergeCommand(command string) error {
7978
status := self.c.Git().Status.WorkingTreeState()
8079

81-
if status != enums.WORKING_TREE_STATE_MERGING && status != enums.WORKING_TREE_STATE_REBASING {
80+
if status != models.WORKING_TREE_STATE_MERGING && status != models.WORKING_TREE_STATE_REBASING {
8281
return errors.New(self.c.Tr.NotMergingOrRebasing)
8382
}
8483

8584
self.c.LogAction(fmt.Sprintf("Merge/Rebase: %s", command))
86-
if status == enums.WORKING_TREE_STATE_REBASING {
85+
if status == models.WORKING_TREE_STATE_REBASING {
8786
todoFile, err := os.ReadFile(
8887
filepath.Join(self.c.Git().RepoPaths.WorktreeGitDirPath(), "rebase-merge/git-rebase-todo"),
8988
)
@@ -102,10 +101,10 @@ func (self *MergeAndRebaseHelper) genericMergeCommand(command string) error {
102101
// we should end up with a command like 'git merge --continue'
103102

104103
// it's impossible for a rebase to require a commit so we'll use a subprocess only if it's a merge
105-
needsSubprocess := (status == enums.WORKING_TREE_STATE_MERGING && command != REBASE_OPTION_ABORT && self.c.UserConfig().Git.Merging.ManualCommit) ||
104+
needsSubprocess := (status == models.WORKING_TREE_STATE_MERGING && command != REBASE_OPTION_ABORT && self.c.UserConfig().Git.Merging.ManualCommit) ||
106105
// but we'll also use a subprocess if we have exec todos; those are likely to be lengthy build
107106
// tasks whose output the user will want to see in the terminal
108-
(status == enums.WORKING_TREE_STATE_REBASING && command != REBASE_OPTION_ABORT && self.hasExecTodos())
107+
(status == models.WORKING_TREE_STATE_REBASING && command != REBASE_OPTION_ABORT && self.hasExecTodos())
109108

110109
if needsSubprocess {
111110
// TODO: see if we should be calling more of the code from self.Git.Rebase.GenericMergeOrRebaseAction

pkg/gui/controllers/helpers/mode_helper.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"fmt"
55
"strings"
66

7-
"github.com/jesseduffield/lazygit/pkg/commands/types/enums"
7+
"github.com/jesseduffield/lazygit/pkg/commands/models"
88
"github.com/jesseduffield/lazygit/pkg/gui/style"
99
"github.com/jesseduffield/lazygit/pkg/gui/types"
1010
"github.com/samber/lo"
@@ -115,7 +115,7 @@ func (self *ModeHelper) Statuses() []ModeStatus {
115115
},
116116
{
117117
IsActive: func() bool {
118-
return !self.suppressRebasingMode && self.c.Git().Status.WorkingTreeState() != enums.WORKING_TREE_STATE_NONE
118+
return !self.suppressRebasingMode && self.c.Git().Status.WorkingTreeState() != models.WORKING_TREE_STATE_NONE
119119
},
120120
Description: func() string {
121121
workingTreeState := self.c.Git().Status.WorkingTreeState()

pkg/gui/controllers/helpers/patch_building_helper.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ package helpers
33
import (
44
"errors"
55

6+
"github.com/jesseduffield/lazygit/pkg/commands/models"
67
"github.com/jesseduffield/lazygit/pkg/commands/patch"
7-
"github.com/jesseduffield/lazygit/pkg/commands/types/enums"
88
"github.com/jesseduffield/lazygit/pkg/gui/patch_exploring"
99
"github.com/jesseduffield/lazygit/pkg/gui/types"
1010
)
@@ -22,7 +22,7 @@ func NewPatchBuildingHelper(
2222
}
2323

2424
func (self *PatchBuildingHelper) ValidateNormalWorkingTreeState() (bool, error) {
25-
if self.c.Git().Status.WorkingTreeState() != enums.WORKING_TREE_STATE_NONE {
25+
if self.c.Git().Status.WorkingTreeState() != models.WORKING_TREE_STATE_NONE {
2626
return false, errors.New(self.c.Tr.CantPatchWhileRebasingError)
2727
}
2828
return true, nil

0 commit comments

Comments
 (0)