Skip to content

Commit 37f8352

Browse files
committed
Use WorkingTreeState instead of RebaseMode in CommitLoader
We want to get rid of RebaseMode, and using the more general WorkingTreeState will later allow us to also show cherry-pick or revert todos.
1 parent 94fc4d7 commit 37f8352

File tree

3 files changed

+25
-34
lines changed

3 files changed

+25
-34
lines changed

pkg/commands/git.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ func NewGitCommandAux(
136136

137137
branchLoader := git_commands.NewBranchLoader(cmn, gitCommon, cmd, branchCommands.CurrentBranchInfo, configCommands)
138138
commitFileLoader := git_commands.NewCommitFileLoader(cmn, cmd)
139-
commitLoader := git_commands.NewCommitLoader(cmn, cmd, statusCommands.RebaseMode, gitCommon)
139+
commitLoader := git_commands.NewCommitLoader(cmn, cmd, statusCommands.WorkingTreeState, gitCommon)
140140
reflogCommitLoader := git_commands.NewReflogCommitLoader(cmn, cmd)
141141
remoteLoader := git_commands.NewRemoteLoader(cmn, cmd, repo.Remotes)
142142
worktreeLoader := git_commands.NewWorktreeLoader(gitCommon)

pkg/commands/git_commands/commit_loader.go

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -31,27 +31,27 @@ type CommitLoader struct {
3131
*common.Common
3232
cmd oscommands.ICmdObjBuilder
3333

34-
getRebaseMode func() (enums.RebaseMode, error)
35-
readFile func(filename string) ([]byte, error)
36-
walkFiles func(root string, fn filepath.WalkFunc) error
37-
dotGitDir string
34+
getWorkingTreeState func() enums.RebaseMode
35+
readFile func(filename string) ([]byte, error)
36+
walkFiles func(root string, fn filepath.WalkFunc) error
37+
dotGitDir string
3838
*GitCommon
3939
}
4040

4141
// making our dependencies explicit for the sake of easier testing
4242
func NewCommitLoader(
4343
cmn *common.Common,
4444
cmd oscommands.ICmdObjBuilder,
45-
getRebaseMode func() (enums.RebaseMode, error),
45+
getWorkingTreeState func() enums.RebaseMode,
4646
gitCommon *GitCommon,
4747
) *CommitLoader {
4848
return &CommitLoader{
49-
Common: cmn,
50-
cmd: cmd,
51-
getRebaseMode: getRebaseMode,
52-
readFile: os.ReadFile,
53-
walkFiles: filepath.Walk,
54-
GitCommon: gitCommon,
49+
Common: cmn,
50+
cmd: cmd,
51+
getWorkingTreeState: getWorkingTreeState,
52+
readFile: os.ReadFile,
53+
walkFiles: filepath.Walk,
54+
GitCommon: gitCommon,
5555
}
5656
}
5757

@@ -172,17 +172,12 @@ func (self *CommitLoader) MergeRebasingCommits(commits []*models.Commit) ([]*mod
172172
}
173173
}
174174

175-
rebaseMode, err := self.getRebaseMode()
176-
if err != nil {
177-
return nil, err
178-
}
179-
180-
if rebaseMode == enums.REBASE_MODE_NONE {
175+
if !self.getWorkingTreeState().IsRebasing() {
181176
// not in rebase mode so return original commits
182177
return result, nil
183178
}
184179

185-
rebasingCommits, err := self.getHydratedRebasingCommits(rebaseMode)
180+
rebasingCommits, err := self.getHydratedRebasingCommits()
186181
if err != nil {
187182
return nil, err
188183
}
@@ -248,8 +243,8 @@ func (self *CommitLoader) extractCommitFromLine(line string, showDivergence bool
248243
}
249244
}
250245

251-
func (self *CommitLoader) getHydratedRebasingCommits(rebaseMode enums.RebaseMode) ([]*models.Commit, error) {
252-
commits := self.getRebasingCommits(rebaseMode)
246+
func (self *CommitLoader) getHydratedRebasingCommits() ([]*models.Commit, error) {
247+
commits := self.getRebasingCommits()
253248

254249
if len(commits) == 0 {
255250
return nil, nil
@@ -310,11 +305,7 @@ func (self *CommitLoader) getHydratedRebasingCommits(rebaseMode enums.RebaseMode
310305
// git-rebase-todo example:
311306
// pick ac446ae94ee560bdb8d1d057278657b251aaef17 ac446ae
312307
// pick afb893148791a2fbd8091aeb81deba4930c73031 afb8931
313-
func (self *CommitLoader) getRebasingCommits(rebaseMode enums.RebaseMode) []*models.Commit {
314-
if rebaseMode != enums.REBASE_MODE_INTERACTIVE {
315-
return nil
316-
}
317-
308+
func (self *CommitLoader) getRebasingCommits() []*models.Commit {
318309
bytesContent, err := self.readFile(filepath.Join(self.repoPaths.WorktreeGitDirPath(), "rebase-merge/git-rebase-todo"))
319310
if err != nil {
320311
self.Log.Error(fmt.Sprintf("error occurred reading git-rebase-todo: %s", err.Error()))

pkg/commands/git_commands/commit_loader_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -302,10 +302,10 @@ func TestGetCommits(t *testing.T) {
302302
cmd := oscommands.NewDummyCmdObjBuilder(scenario.runner)
303303

304304
builder := &CommitLoader{
305-
Common: common,
306-
cmd: cmd,
307-
getRebaseMode: func() (enums.RebaseMode, error) { return enums.REBASE_MODE_NONE, nil },
308-
dotGitDir: ".git",
305+
Common: common,
306+
cmd: cmd,
307+
getWorkingTreeState: func() enums.RebaseMode { return enums.REBASE_MODE_NONE },
308+
dotGitDir: ".git",
309309
readFile: func(filename string) ([]byte, error) {
310310
return []byte(""), nil
311311
},
@@ -485,10 +485,10 @@ func TestCommitLoader_getConflictedCommitImpl(t *testing.T) {
485485
common := utils.NewDummyCommon()
486486

487487
builder := &CommitLoader{
488-
Common: common,
489-
cmd: oscommands.NewDummyCmdObjBuilder(oscommands.NewFakeRunner(t)),
490-
getRebaseMode: func() (enums.RebaseMode, error) { return enums.REBASE_MODE_INTERACTIVE, nil },
491-
dotGitDir: ".git",
488+
Common: common,
489+
cmd: oscommands.NewDummyCmdObjBuilder(oscommands.NewFakeRunner(t)),
490+
getWorkingTreeState: func() enums.RebaseMode { return enums.REBASE_MODE_INTERACTIVE },
491+
dotGitDir: ".git",
492492
readFile: func(filename string) ([]byte, error) {
493493
return []byte(""), nil
494494
},

0 commit comments

Comments
 (0)