summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2021-12-30 13:35:10 +1100
committerJesse Duffield <jessedduffield@gmail.com>2022-01-04 09:07:15 +1100
commit66e840bc3f83903852408ed8db0be0c6153b5487 (patch)
tree2e3578e0ceff2fb44b8a7060f87400808eedaef7
parent5b3572424380418f86df88d201347b54634be530 (diff)
more refactoring
-rw-r--r--pkg/commands/loader_adapters.go28
-rw-r--r--pkg/commands/loaders/commits.go (renamed from pkg/commands/loading_commits.go)72
-rw-r--r--pkg/commands/loaders/commits_test.go (renamed from pkg/commands/loading_commits_test.go)19
-rw-r--r--pkg/commands/loading_branches.go2
-rw-r--r--pkg/commands/oscommands/fake_cmd_obj_runner.go (renamed from pkg/commands/oscommands/fake_runner.go)2
-rw-r--r--pkg/commands/patch_rebases.go5
-rw-r--r--pkg/commands/status.go34
-rw-r--r--pkg/commands/types/enums/enums.go14
-rw-r--r--pkg/gui/commits_panel.go11
-rw-r--r--pkg/gui/merge_panel.go4
-rw-r--r--pkg/gui/modes.go4
-rw-r--r--pkg/gui/patch_options_panel.go6
-rw-r--r--pkg/gui/rebase_options_panel.go18
-rw-r--r--pkg/gui/status_panel.go6
-rw-r--r--pkg/gui/sub_commits_panel.go7
-rw-r--r--pkg/gui/undoing.go6
16 files changed, 140 insertions, 98 deletions
diff --git a/pkg/commands/loader_adapters.go b/pkg/commands/loader_adapters.go
new file mode 100644
index 000000000..166bf012d
--- /dev/null
+++ b/pkg/commands/loader_adapters.go
@@ -0,0 +1,28 @@
+package commands
+
+import (
+ "io/ioutil"
+ "path/filepath"
+
+ "github.com/jesseduffield/lazygit/pkg/commands/loaders"
+ "github.com/jesseduffield/lazygit/pkg/commands/oscommands"
+ "github.com/jesseduffield/lazygit/pkg/common"
+)
+
+// this file defines constructors for loaders, passing in all the dependencies required based on a smaller set of arguments passed in by the client.
+
+func NewCommitLoader(
+ cmn *common.Common,
+ gitCommand *GitCommand,
+ osCommand *oscommands.OSCommand,
+) *loaders.CommitLoader {
+ return loaders.NewCommitLoader(
+ cmn,
+ gitCommand.Cmd,
+ gitCommand.CurrentBranchName,
+ gitCommand.RebaseMode,
+ ioutil.ReadFile,
+ filepath.Walk,
+ gitCommand.DotGitDir,
+ )
+}
diff --git a/pkg/commands/loading_commits.go b/pkg/commands/loaders/commits.go
index af93509c5..5fc2caa98 100644
--- a/pkg/commands/loading_commits.go
+++ b/pkg/commands/loaders/commits.go
@@ -1,8 +1,7 @@
-package commands
+package loaders
import (
"fmt"
- "io/ioutil"
"os"
"path/filepath"
"regexp"
@@ -11,6 +10,7 @@ import (
"github.com/jesseduffield/lazygit/pkg/commands/models"
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
+ "github.com/jesseduffield/lazygit/pkg/commands/types/enums"
"github.com/jesseduffield/lazygit/pkg/common"
"github.com/jesseduffield/lazygit/pkg/gui/style"
)
@@ -23,31 +23,35 @@ import (
const SEPARATION_CHAR = "|"
-// CommitListBuilder returns a list of Commit objects for the current repo
-type CommitListBuilder struct {
+// CommitLoader returns a list of Commit objects for the current repo
+type CommitLoader struct {
*common.Common
cmd oscommands.ICmdObjBuilder
getCurrentBranchName func() (string, string, error)
- getRebaseMode func() (RebaseMode, error)
+ getRebaseMode func() (enums.RebaseMode, error)
readFile func(filename string) ([]byte, error)
walkFiles func(root string, fn filepath.WalkFunc) error
dotGitDir string
}
-func NewCommitListBuilder(
- cmn *common.Common,
- gitCommand *GitCommand,
- osCommand *oscommands.OSCommand,
-) *CommitListBuilder {
- return &CommitListBuilder{
- Common: cmn,
- cmd: gitCommand.Cmd,
- getCurrentBranchName: gitCommand.CurrentBranchName,
- getRebaseMode: gitCommand.RebaseMode,
- dotGitDir: gitCommand.DotGitDir,
- readFile: ioutil.ReadFile,
- walkFiles: filepath.Walk,
+func NewCommitLoader(
+ common *common.Common,
+ cmd oscommands.ICmdObjBuilder,
+ getCurrentBranchName func() (string, string, error),
+ getRebaseMode func() (enums.RebaseMode, error),
+ readFile func(filename string) ([]byte, error),
+ walkFiles func(root string, fn filepath.WalkFunc) error,
+ dotGitDir string,
+) *CommitLoader {
+ return &CommitLoader{
+ Common: common,
+ cmd: cmd,
+ getCurrentBranchName: getCurrentBranchName,
+ getRebaseMode: getRebaseMode,
+ readFile: readFile,
+ walkFiles: walkFiles,
+ dotGitDir: dotGitDir,
}
}
@@ -61,7 +65,7 @@ type GetCommitsOptions struct {
}
// GetCommits obtains the commits of the current branch
-func (self *CommitListBuilder) GetCommits(opts GetCommitsOptions) ([]*models.Commit, error) {
+func (self *CommitLoader) GetCommits(opts GetCommitsOptions) ([]*models.Commit, error) {
commits := []*models.Commit{}
var rebasingCommits []*models.Commit
rebaseMode, err := self.getRebaseMode()
@@ -104,7 +108,7 @@ func (self *CommitListBuilder) GetCommits(opts GetCommitsOptions) ([]*models.Com
return commits, nil
}
- if rebaseMode != REBASE_MODE_NONE {
+ if rebaseMode != enums.REBASE_MODE_NONE {
currentCommit := commits[len(rebasingCommits)]
youAreHere := style.FgYellow.Sprintf("<-- %s ---", self.Tr.YouAreHere)
currentCommit.Name = fmt.Sprintf("%s %s", youAreHere, currentCommit.Name)
@@ -118,7 +122,7 @@ func (self *CommitListBuilder) GetCommits(opts GetCommitsOptions) ([]*models.Com
return commits, nil
}
-func (self *CommitListBuilder) MergeRebasingCommits(commits []*models.Commit) ([]*models.Commit, error) {
+func (self *CommitLoader) MergeRebasingCommits(commits []*models.Commit) ([]*models.Commit, error) {
// chances are we have as many commits as last time so we'll set the capacity to be the old length
result := make([]*models.Commit, 0, len(commits))
for i, commit := range commits {
@@ -133,7 +137,7 @@ func (self *CommitListBuilder) MergeRebasingCommits(commits []*models.Commit) ([
return nil, err
}
- if rebaseMode == REBASE_MODE_NONE {
+ if rebaseMode == enums.REBASE_MODE_NONE {
// not in rebase mode so return original commits
return result, nil
}
@@ -153,7 +157,7 @@ func (self *CommitListBuilder) MergeRebasingCommits(commits []*models.Commit) ([
// then puts them into a commit object
// example input:
// 8ad01fe32fcc20f07bc6693f87aa4977c327f1e1|10 hours ago|Jesse Duffield| (HEAD -> master, tag: v0.15.2)|refresh commits when adding a tag
-func (self *CommitListBuilder) extractCommitFromLine(line string) *models.Commit {
+func (self *CommitLoader) extractCommitFromLine(line string) *models.Commit {
split := strings.Split(line, SEPARATION_CHAR)
sha := split[0]
@@ -186,7 +190,7 @@ func (self *CommitListBuilder) extractCommitFromLine(line string) *models.Commit
}
}
-func (self *CommitListBuilder) getHydratedRebasingCommits(rebaseMode RebaseMode) ([]*models.Commit, error) {
+func (self *CommitLoader) getHydratedRebasingCommits(rebaseMode enums.RebaseMode) ([]*models.Commit, error) {
commits, err := self.getRebasingCommits(rebaseMode)
if err != nil {
return nil, err
@@ -232,18 +236,18 @@ func (self *CommitListBuilder) getHydratedRebasingCommits(rebaseMode RebaseMode)
}
// getRebasingCommits obtains the commits that we're in the process of rebasing
-func (self *CommitListBuilder) getRebasingCommits(rebaseMode RebaseMode) ([]*models.Commit, error) {
+func (self *CommitLoader) getRebasingCommits(rebaseMode enums.RebaseMode) ([]*models.Commit, error) {
switch rebaseMode {
- case REBASE_MODE_MERGING:
+ case enums.REBASE_MODE_MERGING:
return self.getNormalRebasingCommits()
- case REBASE_MODE_INTERACTIVE:
+ case enums.REBASE_MODE_INTERACTIVE:
return self.getInteractiveRebasingCommits()
default:
return nil, nil
}
}
-func (self *CommitListBuilder) getNormalRebasingCommits() ([]*models.Commit, error) {
+func (self *CommitLoader) getNormalRebasingCommits() ([]*models.Commit, error) {
rewrittenCount := 0
bytesContent, err := self.readFile(filepath.Join(self.dotGitDir, "rebase-apply/rewritten"))
if err == nil {
@@ -296,7 +300,7 @@ func (self *CommitListBuilder) getNormalRebasingCommits() ([]*models.Commit, err
// getInteractiveRebasingCommits takes our git-rebase-todo and our git-rebase-todo.backup files
// and extracts out the sha and names of commits that we still have to go
// in the rebase:
-func (self *CommitListBuilder) getInteractiveRebasingCommits() ([]*models.Commit, error) {
+func (self *CommitLoader) getInteractiveRebasingCommits() ([]*models.Commit, error) {
bytesContent, err := self.readFile(filepath.Join(self.dotGitDir, "rebase-merge/git-rebase-todo"))
if err != nil {
self.Log.Error(fmt.Sprintf("error occurred reading git-rebase-todo: %s", err.Error()))
@@ -330,7 +334,7 @@ func (self *CommitListBuilder) getInteractiveRebasingCommits() ([]*models.Commit
// From: Lazygit Tester <test@example.com>
// Date: Wed, 5 Dec 2018 21:03:23 +1100
// Subject: second commit on master
-func (self *CommitListBuilder) commitFromPatch(content string) (*models.Commit, error) {
+func (self *CommitLoader) commitFromPatch(content string) (*models.Commit, error) {
lines := strings.Split(content, "\n")
sha := strings.Split(lines[0], " ")[1]
name := strings.TrimPrefix(lines[3], "Subject: ")
@@ -341,7 +345,7 @@ func (self *CommitListBuilder) commitFromPatch(content string) (*models.Commit,
}, nil
}
-func (self *CommitListBuilder) setCommitMergedStatuses(refName string, commits []*models.Commit) ([]*models.Commit, error) {
+func (self *CommitLoader) setCommitMergedStatuses(refName string, commits []*models.Commit) ([]*models.Commit, error) {
ancestor, err := self.getMergeBase(refName)
if err != nil {
return nil, err
@@ -364,7 +368,7 @@ func (self *CommitListBuilder) setCommitMergedStatuses(refName string, commits [
return commits, nil
}
-func (self *CommitListBuilder) getMergeBase(refName string) (string, error) {
+func (self *CommitLoader) getMergeBase(refName string) (string, error) {
currentBranch, _, err := self.getCurrentBranchName()
if err != nil {
return "", err
@@ -392,7 +396,7 @@ func ignoringWarnings(commandOutput string) string {
// getFirstPushedCommit returns the first commit SHA which has been pushed to the ref's upstream.
// all commits above this are deemed unpushed and marked as such.
-func (self *CommitListBuilder) getFirstPushedCommit(refName string) (string, error) {
+func (self *CommitLoader) getFirstPushedCommit(refName string) (string, error) {
output, err := self.cmd.
New(
fmt.Sprintf("git merge-base %s %s@{u}", self.cmd.Quote(refName), self.cmd.Quote(refName)),
@@ -406,7 +410,7 @@ func (self *CommitListBuilder) getFirstPushedCommit(refName string) (string, err
}
// getLog gets the git log.
-func (self *CommitListBuilder) getLogCmd(opts GetCommitsOptions) oscommands.ICmdObj {
+func (self *CommitLoader) getLogCmd(opts GetCommitsOptions) oscommands.ICmdObj {
limitFlag := ""
if opts.Limit {
limitFlag = " -300"
diff --git a/pkg/commands/loading_commits_test.go b/pkg/commands/loaders/commits_test.go
index 29f8ef992..f793567f7 100644
--- a/pkg/commands/loading_commits_test.go
+++ b/pkg/commands/loaders/commits_test.go
@@ -1,4 +1,4 @@
-package commands
+package loaders
import (
"path/filepath"
@@ -6,18 +6,19 @@ import (
"github.com/jesseduffield/lazygit/pkg/commands/models"
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
+ "github.com/jesseduffield/lazygit/pkg/commands/types/enums"
"github.com/jesseduffield/lazygit/pkg/utils"
"github.com/stretchr/testify/assert"
)
-func NewDummyCommitListBuilder() *CommitListBuilder {
+func NewDummyCommitLoader() *CommitLoader {
cmn := utils.NewDummyCommon()
- return &CommitListBuilder{
+ return &CommitLoader{
Common: cmn,
cmd: nil,
getCurrentBranchName: func() (string, string, error) { return "master", "master", nil },
- getRebaseMode: func() (RebaseMode, error) { return REBASE_MODE_NONE, nil },
+ getRebaseMode: func() (enums.RebaseMode, error) { return enums.REBASE_MODE_NONE, nil },
dotGitDir: ".git",
readFile: func(filename string) ([]byte, error) {
return []byte(""), nil
@@ -43,7 +44,7 @@ func TestGetCommits(t *testing.T) {
runner oscommands.ICmdObjRunner
expectedCommits []*models.Commit
expectedError error
- rebaseMode RebaseMode
+ rebaseMode enums.RebaseMode
currentBranchName string
opts GetCommitsOptions
}
@@ -51,7 +52,7 @@ func TestGetCommits(t *testing.T) {
scenarios := []scenario{
{
testName: "should return no commits if there are none",
- rebaseMode: REBASE_MODE_NONE,
+ rebaseMode: enums.REBASE_MODE_NONE,
currentBranchName: "master",
opts: GetCommitsOptions{RefName: "HEAD", IncludeRebaseCommits: false},
runner: oscommands.NewFakeRunner(t).
@@ -63,7 +64,7 @@ func TestGetCommits(t *testing.T) {
},
{
testName: "should return commits if they are present",
- rebaseMode: REBASE_MODE_NONE,
+ rebaseMode: enums.REBASE_MODE_NONE,
currentBranchName: "master",
opts: GetCommitsOptions{RefName: "HEAD", IncludeRebaseCommits: false},
runner: oscommands.NewFakeRunner(t).
@@ -186,13 +187,13 @@ func TestGetCommits(t *testing.T) {
for _, scenario := range scenarios {
t.Run(scenario.testName, func(t *testing.T) {
- builder := &CommitListBuilder{
+ builder := &CommitLoader{
Common: utils.NewDummyCommon(),
cmd: oscommands.NewCmdObjBuilderDummy(scenario.runner),
getCurrentBranchName: func() (string, string, error) {
return scenario.currentBranchName, scenario.currentBranchName, nil
},
- getRebaseMode: func() (RebaseMode, error) { return scenario.rebaseMode, nil },
+ getRebaseMode: func() (enums.RebaseMode, error) { return scenario.rebaseMode, nil },
dotGitDir: ".git",
readFile: func(filename string) ([]byte, error) {
return []byte(""), nil
diff --git a/pkg/commands/loading_branches.go b/pkg/commands/loading_branches.go
index 802bdb30e..62f758bcd 100644
--- a/pkg/commands/loading_branches.go
+++ b/pkg/commands/loading_branches.go
@@ -20,6 +20,8 @@ import (
// if we find out we need to use one of these functions in the git.go file, we
// can just pull them out of here and put them there and then call them from in here
+const SEPARATION_CHAR = "|"
+
// BranchListBuilder returns a list of Branch objects for the current repo
type BranchListBuilder struct {
*common.Common
diff --git a/pkg/commands/oscommands/fake_runner.go b/pkg/commands/oscommands/fake_cmd_obj_runner.go
index c18378c8f..09431bb20 100644
--- a/pkg/commands/oscommands/fake_runner.go
+++ b/pkg/commands/oscommands/fake_cmd_obj_runner.go
@@ -10,6 +10,8 @@ import (
"github.com/stretchr/testify/assert"
)
+// for use in testing
+
type FakeCmdObjRunner struct {
t *testing.T
expectedCmds []func(ICmdObj) (string, error)
diff --git a/pkg/commands/patch_rebases.go b/pkg/commands/patch_rebases.go
index 8f33479bf..c03c8d0a4 100644
--- a/pkg/commands/patch_rebases.go
+++ b/pkg/commands/patch_rebases.go
@@ -6,6 +6,7 @@ import (
"github.com/go-errors/errors"
"github.com/jesseduffield/lazygit/pkg/commands/models"
"github.com/jesseduffield/lazygit/pkg/commands/patch"
+ "github.com/jesseduffield/lazygit/pkg/commands/types/enums"
)
// DeletePatchesFromCommit applies a patch in reverse for a commit
@@ -149,7 +150,7 @@ func (c *GitCommand) MovePatchIntoIndex(commits []*models.Commit, commitIdx int,
}
if err := p.ApplyPatches(true); err != nil {
- if c.WorkingTreeState() == REBASE_MODE_REBASING {
+ if c.WorkingTreeState() == enums.REBASE_MODE_REBASING {
if err := c.GenericMergeOrRebaseAction("rebase", "abort"); err != nil {
return err
}
@@ -169,7 +170,7 @@ func (c *GitCommand) MovePatchIntoIndex(commits []*models.Commit, commitIdx int,
c.onSuccessfulContinue = func() error {
// add patches to index
if err := p.ApplyPatches(false); err != nil {
- if c.WorkingTreeState() == REBASE_MODE_REBASING {
+ if c.WorkingTreeState() == enums.REBASE_MODE_REBASING {
if err := c.GenericMergeOrRebaseAction("rebase", "abort"); err != nil {
return err
}
diff --git a/pkg/commands/status.go b/pkg/commands/status.go
index 0d7259572..392ce3797 100644
--- a/pkg/commands/status.go
+++ b/pkg/commands/status.go
@@ -4,49 +4,37 @@ import (
"path/filepath"
gogit "github.com/jesseduffield/go-git/v5"
-)
-
-type RebaseMode int
-
-const (
- // this means we're neither rebasing nor merging
- REBASE_MODE_NONE RebaseMode = iota
- // this means normal rebase as opposed to interactive rebase
- REBASE_MODE_NORMAL
- REBASE_MODE_INTERACTIVE
- // REBASE_MODE_REBASING is a general state that captures both REBASE_MODE_NORMAL and REBASE_MODE_INTERACTIVE
- REBASE_MODE_REBASING
- REBASE_MODE_MERGING
+ "github.com/jesseduffield/lazygit/pkg/commands/types/enums"
)
// RebaseMode returns "" for non-rebase mode, "normal" for normal rebase
// and "interactive" for interactive rebase
-func (c *GitCommand) RebaseMode() (RebaseMode, error) {
+func (c *GitCommand) RebaseMode() (enums.RebaseMode, error) {
exists, err := c.OSCommand.FileExists(filepath.Join(c.DotGitDir, "rebase-apply"))
if err != nil {
- return REBASE_MODE_NONE, err
+ return enums.REBASE_MODE_NONE, err
}
if exists {
- return REBASE_MODE_NORMAL, nil
+ return enums.REBASE_MODE_NORMAL, nil
}
exists, err = c.OSCommand.FileExists(filepath.Join(c.DotGitDir, "rebase-merge"))
if exists {
- return REBASE_MODE_INTERACTIVE, err
+ return enums.REBASE_MODE_INTERACTIVE, err
} else {
- return REBASE_MODE_NONE, err
+ return enums.REBASE_MODE_NONE, err
}
}
-func (c *GitCommand) WorkingTreeState() RebaseMode {
+func (c *GitCommand) WorkingTreeState() enums.RebaseMode {
rebaseMode, _ := c.RebaseMode()
- if rebaseMode != REBASE_MODE_NONE {
- return REBASE_MODE_REBASING
+ if rebaseMode != enums.REBASE_MODE_NONE {
+ return enums.REBASE_MODE_REBASING
}
merging, _ := c.IsInMergeState()
if merging {
- return REBASE_MODE_MERGING
+ return enums.REBASE_MODE_MERGING
}
- return REBASE_MODE_NONE
+ return enums.REBASE_MODE_NONE
}
// IsInMergeState states whether we are still mid-merge
diff --git a/pkg/commands/types/enums/enums.go b/pkg/commands/types/enums/enums.go
new file mode 100644
index 000000000..7e8a81798
--- /dev/null
+++ b/pkg/commands/types/enums/enums.go
@@ -0,0 +1,14 @@
+package enums
+
+type RebaseMode int
+
+const (
+ // this means we're neither rebasing nor merging
+ REBASE_MODE_NONE RebaseMode = iota
+ // this means normal rebase as opposed to interactive rebase
+ REBASE_MODE_NORMAL
+ REBASE_MODE_INTERACTIVE
+ // REBASE_MODE_REBASING is a general state that captures both REBASE_MODE_NORMAL and REBASE_MODE_INTERACTIVE
+ REBASE_MODE_REBASING
+ REBASE_MODE_MERGING
+)
diff --git a/pkg/gui/commits_panel.go b/pkg/gui/commits_panel.go
index f88557cdd..cd85dafd5 100644
--- a/pkg/gui/commits_panel.go
+++ b/pkg/gui/commits_panel.go
@@ -5,6 +5,7 @@ import (
"sync"
"github.com/jesseduffield/lazygit/pkg/commands"
+ "github.com/jesseduffield/lazygit/pkg/commands/loaders"
"github.com/jesseduffield/lazygit/pkg/commands/models"
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
"github.com/jesseduffield/lazygit/pkg/utils"
@@ -119,10 +120,10 @@ func (gui *Gui) refreshCommitsWithLimit() error {
gui.Mutexes.BranchCommitsMutex.Lock()
defer gui.Mutexes.BranchCommitsMutex.Unlock()
- builder := commands.NewCommitListBuilder(gui.Common, gui.GitCommand, gui.OSCommand)
+ loader := commands.NewCommitLoader(gui.Common, gui.GitCommand, gui.OSCommand)
- commits, err := builder.GetCommits(
- commands.GetCommitsOptions{
+ commits, err := loader.GetCommits(
+ loaders.GetCommitsOptions{
Limit: gui.State.Panels.Commits.LimitCommits,
FilterPath: gui.State.Modes.Filtering.GetPath(),
IncludeRebaseCommits: true,
@@ -142,9 +143,9 @@ func (gui *Gui) refreshRebaseCommits() error {
gui.Mutexes.BranchCommitsMutex.Lock()
defer gui.Mutexes.BranchCommitsMutex.Unlock()
- builder := commands.NewCommitListBuilder(gui.Common, gui.GitCommand, gui.OSCommand)
+ loader := commands.NewCommitLoader(gui.Common, gui.GitCommand, gui.OSCommand)
- updatedCommits, err := builder.MergeRebasingCommits(gui.State.Commits)
+ updatedCommits, err := loader.MergeRebasingCommits(gui.State.Commits)
if err != nil {
return err
}
diff --git a/pkg/gui/merge_panel.go b/pkg/gui/merge_panel.go
index 8054a0348..5afbd64b2 100644
--- a/pkg/gui/merge_panel.go
+++ b/pkg/gui/merge_panel.go
@@ -9,8 +9,8 @@ import (
"github.com/go-errors/errors"
"github.com/jesseduffield/gocui"
- "github.com/jesseduffield/lazygit/pkg/commands"
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
+ "github.com/jesseduffield/lazygit/pkg/commands/types/enums"
"github.com/jesseduffield/lazygit/pkg/gui/mergeconflicts"
)
@@ -262,7 +262,7 @@ func (gui *Gui) handleCompleteMerge() error {
}
// if we got conflicts after unstashing, we don't want to call any git
// commands to continue rebasing/merging here
- if gui.GitCommand.WorkingTreeState() == commands.REBASE_MODE_NONE {
+ if gui.GitCommand.WorkingTreeState() == enums.REBASE_MODE_NONE {
return gui.handleEscapeMerge()
}
// if there are no more files with merge conflicts, we should ask whether the user wants to continue
diff --git a/pkg/gui/modes.go b/pkg/gui/modes.go
index 025767b82..c8e2749e3 100644
--- a/pkg/gui/modes.go
+++ b/pkg/gui/modes.go
@@ -1,7 +1,7 @@
package gui
import (
- "github.com/jesseduffield/lazygit/pkg/commands"
+ "github.com/jesseduffield/lazygit/pkg/commands/types/enums"
"github.com/jesseduffield/lazygit/pkg/gui/style"
)
@@ -61,7 +61,7 @@ func (gui *Gui) modeStatuses() []modeStatus {
},
{
isActive: func() bool {
- return gui.GitCommand.WorkingTreeState() != commands.REBASE_MODE_NONE
+ return gui.GitCommand.WorkingTreeState() != enums.REBASE_MODE_NONE
},
description: func() string {
workingTreeState := gui.GitCommand.WorkingTreeState()
diff --git a/pkg/gui/patch_options_panel.go b/pkg/gui/patch_options_panel.go
index 8a57e9244..facaa08db 100644
--- a/pkg/gui/patch_options_panel.go
+++ b/pkg/gui/patch_options_panel.go
@@ -3,7 +3,7 @@ package gui
import (
"fmt"
- "github.com/jesseduffield/lazygit/pkg/commands"
+ "github.com/jesseduffield/lazygit/pkg/commands/types/enums"
)
func (gui *Gui) handleCreatePatchOptionsMenu() error {
@@ -26,7 +26,7 @@ func (gui *Gui) handleCreatePatchOptionsMenu() error {
},
}
- if gui.GitCommand.PatchManager.CanRebase && gui.GitCommand.WorkingTreeState() == commands.REBASE_MODE_NONE {
+ if gui.GitCommand.PatchManager.CanRebase && gui.GitCommand.WorkingTreeState() == enums.REBASE_MODE_NONE {
menuItems = append(menuItems, []*menuItem{
{
displayString: fmt.Sprintf("remove patch from original commit (%s)", gui.GitCommand.PatchManager.To),
@@ -74,7 +74,7 @@ func (gui *Gui) getPatchCommitIndex() int {
}
func (gui *Gui) validateNormalWorkingTreeState() (bool, error) {
- if gui.GitCommand.WorkingTreeState() != commands.REBASE_MODE_NONE {
+ if gui.GitCommand.WorkingTreeState() != enums.REBASE_MODE_NONE {
return false, gui.createErrorPanel(gui.Tr.CantPatchWhileRebasingError)
}
return true, nil
diff --git a/pkg/gui/rebase_options_panel.go b/pkg/gui/rebase_options_panel.go
index 514cdf5ae..6cc9f113b 100644
--- a/pkg/gui/rebase_options_panel.go
+++ b/pkg/gui/rebase_options_panel.go
@@ -4,7 +4,7 @@ import (
"fmt"
"strings"
- "github.com/jesseduffield/lazygit/pkg/commands"
+ "github.com/jesseduffield/lazygit/pkg/commands/types/enums"
)
type RebaseOption string
@@ -18,7 +18,7 @@ const (
func (gui *Gui) handleCreateRebaseOptionsMenu() error {
options := []string{REBASE_OPTION_CONTINUE, REBASE_OPTION_ABORT}
- if gui.GitCommand.WorkingTreeState() == commands.REBASE_MODE_REBASING {
+ if gui.GitCommand.WorkingTreeState() == enums.REBASE_MODE_REBASING {
options = append(options, REBASE_OPTION_SKIP)
}
@@ -35,7 +35,7 @@ func (gui *Gui) handleCreateRebaseOptionsMenu() error {
}
var title string
- if gui.GitCommand.WorkingTreeState() == commands.REBASE_MODE_MERGING {
+ if gui.GitCommand.WorkingTreeState() == enums.REBASE_MODE_MERGING {
title = gui.Tr.MergeOptionsTitle
} else {
title = gui.Tr.RebaseOptionsTitle
@@ -47,7 +47,7 @@ func (gui *Gui) handleCreateRebaseOptionsMenu() error {
func (gui *Gui) genericMergeCommand(command string) error {
status := gui.GitCommand.WorkingTreeState()
- if status != commands.REBASE_MODE_MERGING && status != commands.REBASE_MODE_REBASING {
+ if status != enums.REBASE_MODE_MERGING && status != enums.REBASE_MODE_REBASING {
return gui.createErrorPanel(gui.Tr.NotMergingOrRebasing)
}
@@ -55,16 +55,16 @@ func (gui *Gui) genericMergeCommand(command string) error {
commandType := ""
switch status {
- case commands.REBASE_MODE_MERGING:
+ case enums.REBASE_MODE_MERGING:
commandType = "merge"
- case commands.REBASE_MODE_REBASING:
+ case enums.REBASE_MODE_REBASING:
commandType = "rebase"
}
// 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
- if status == commands.REBASE_MODE_MERGING && command != REBASE_OPTION_ABORT && gui.UserConfig.Git.Merging.ManualCommit {
+ if status == enums.REBASE_MODE_MERGING && command != REBASE_OPTION_ABORT && gui.UserConfig.Git.Merging.ManualCommit {
sub := gitCommand.Cmd.New("git " + commandType + " --" + command)
if sub != nil {
return gui.runSubprocessWithSuspenseAndRefresh(sub)
@@ -144,9 +144,9 @@ func (gui *Gui) abortMergeOrRebaseWithConfirm() error {
func (gui *Gui) workingTreeStateNoun() string {
workingTreeState := gui.GitCommand.WorkingTreeState()
switch workingTreeState {
- case commands.REBASE_MODE_NONE:
+ case enums.REBASE_MODE_NONE:
return ""
- case commands.REBASE_MODE_MERGING:
+ case enums.REBASE_MODE_MERGING:
return "merge"
default:
return "rebase"
diff --git a/pkg/gui/status_panel.go b/pkg/gui/status_panel.go
index ee09f6187..d6985dd0d 100644
--- a/pkg/gui/status_panel.go
+++ b/pkg/gui/status_panel.go
@@ -5,7 +5,7 @@ import (
"fmt"
"strings"
- "github.com/jesseduffield/lazygit/pkg/commands"
+ "github.com/jesseduffield/lazygit/pkg/commands/types/enums"
"github.com/jesseduffield/lazygit/pkg/constants"
"github.com/jesseduffield/lazygit/pkg/gui/presentation"
"github.com/jesseduffield/lazygit/pkg/gui/style"
@@ -28,7 +28,7 @@ func (gui *Gui) refreshStatus() {
status += presentation.ColoredBranchStatus(currentBranch) + " "
}
- if gui.GitCommand.WorkingTreeState() != commands.REBASE_MODE_NONE {
+ if gui.GitCommand.WorkingTreeState() != enums.REBASE_MODE_NONE {
status += style.FgYellow.Sprintf("(%s) ", gui.GitCommand.WorkingTreeState())
}
@@ -72,7 +72,7 @@ func (gui *Gui) handleStatusClick() error {
upstreamStatus := presentation.BranchStatus(currentBranch)
repoName := utils.GetCurrentRepoName()
switch gui.GitCommand.WorkingTreeState() {
- case commands.REBASE_MODE_REBASING, commands.REBASE_MODE_MERGING:
+ case enums.REBASE_MODE_REBASING, enums.REBASE_MODE_MERGING:
workingTreeStatus := fmt.Sprintf("(%s)", gui.GitCommand.WorkingTreeState())
if cursorInSubstring(cx, upstreamStatus+" ", workingTreeStatus) {
return gui.handleCreateRebaseOptionsMenu()
diff --git a/pkg/gui/sub_commits_panel.go b/pkg/gui/sub_commits_panel.go
index c212e3caa..a41ccb315 100644
--- a/pkg/gui/sub_commits_panel.go
+++ b/pkg/gui/sub_commits_panel.go
@@ -2,6 +2,7 @@ package gui
import (
"github.com/jesseduffield/lazygit/pkg/commands"
+ "github.com/jesseduffield/lazygit/pkg/commands/loaders"
"github.com/jesseduffield/lazygit/pkg/commands/models"
)
@@ -75,10 +76,10 @@ func (gui *Gui) handleViewSubCommitFiles() error {
func (gui *Gui) switchToSubCommitsContext(refName string) error {
// need to populate my sub commits
- builder := commands.NewCommitListBuilder(gui.Common, gui.GitCommand, gui.OSCommand)
+ loader := commands.NewCommitLoader(gui.Common, gui.GitCommand, gui.OSCommand)
- commits, err := builder.GetCommits(
- commands.GetCommitsOptions{
+ commits, err := loader.GetCommits(
+ loaders.GetCommitsOptions{
Limit: gui.State.Panels.Commits.LimitCommits,
FilterPath: gui.State.Modes.Filtering.GetPath(),
IncludeRebaseCommits: false,
diff --git a/pkg/gui/undoing.go b/pkg/gui/undoing.go
index 76a391730..cb9a46c2c 100644
--- a/pkg/gui/undoing.go
+++ b/pkg/gui/undoing.go
@@ -1,7 +1,7 @@
package gui
import (
- "github.com/jesseduffield/lazygit/pkg/commands"
+ "github.com/jesseduffield/lazygit/pkg/commands/types/enums"
"github.com/jesseduffield/lazygit/pkg/utils"
)
@@ -88,7 +88,7 @@ func (gui *Gui) reflogUndo() error {
undoEnvVars := []string{"GIT_REFLOG_ACTION=[lazygit undo]"}
undoingStatus := gui.Tr.UndoingStatus
- if gui.GitCommand.WorkingTreeState() == commands.REBASE_MODE_REBASING {
+ if gui.GitCommand.WorkingTreeState() == enums.REBASE_MODE_REBASING {
return gui.createErrorPanel(gui.Tr.LcCantUndoWhileRebasing)
}
@@ -123,7 +123,7 @@ func (gui *Gui) reflogRedo() error {
redoEnvVars := []string{"GIT_REFLOG_ACTION=[lazygit redo]"}
redoingStatus := gui.Tr.RedoingStatus
- if gui.GitCommand.WorkingTreeState() == commands.REBASE_MODE_REBASING {
+ if gui.GitCommand.WorkingTreeState() == enums.REBASE_MODE_REBASING {
return gui.createErrorPanel(gui.Tr.LcCantRedoWhileRebasing)
}