Skip to content

Commit 49701d2

Browse files
committed
Pass todo flag to EditRebaseTodo
Not used yet, we pass an empty string everywhere, to match the previous behavior. Just extracting this into a separate commit to make the next one smaller.
1 parent 54b8246 commit 49701d2

File tree

5 files changed

+23
-17
lines changed

5 files changed

+23
-17
lines changed

pkg/app/daemon/daemon.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ func (self *ChangeTodoActionsInstruction) run(common *common.Common) error {
201201
return utils.TodoChange{
202202
Hash: c.Hash,
203203
NewAction: c.NewAction,
204+
NewFlag: c.NewFlag,
204205
}
205206
})
206207

pkg/app/daemon/rebase.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ func TodoLinesToString(todoLines []TodoLine) string {
3737
type ChangeTodoAction struct {
3838
Hash string
3939
NewAction todo.TodoCommand
40+
NewFlag string
4041
}
4142

4243
func handleInteractiveRebase(common *common.Common, f func(path string) error) error {

pkg/commands/git_commands/rebase.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ func (self *RebaseCommands) MoveCommitsUp(commits []*models.Commit, startIdx int
137137
}).Run()
138138
}
139139

140-
func (self *RebaseCommands) InteractiveRebase(commits []*models.Commit, startIdx int, endIdx int, action todo.TodoCommand) error {
140+
func (self *RebaseCommands) InteractiveRebase(commits []*models.Commit, startIdx int, endIdx int, action todo.TodoCommand, flag string) error {
141141
baseIndex := endIdx + 1
142142
if action == todo.Squash || action == todo.Fixup {
143143
baseIndex++
@@ -149,6 +149,7 @@ func (self *RebaseCommands) InteractiveRebase(commits []*models.Commit, startIdx
149149
return daemon.ChangeTodoAction{
150150
Hash: commit.Hash(),
151151
NewAction: action,
152+
NewFlag: flag,
152153
}, !commit.IsMerge()
153154
})
154155

@@ -331,11 +332,12 @@ func todoFromCommit(commit *models.Commit) utils.Todo {
331332
}
332333

333334
// Sets the action for the given commits in the git-rebase-todo file
334-
func (self *RebaseCommands) EditRebaseTodo(commits []*models.Commit, action todo.TodoCommand) error {
335+
func (self *RebaseCommands) EditRebaseTodo(commits []*models.Commit, action todo.TodoCommand, flag string) error {
335336
commitsWithAction := lo.Map(commits, func(commit *models.Commit, _ int) utils.TodoChange {
336337
return utils.TodoChange{
337338
Hash: commit.Hash(),
338339
NewAction: action,
340+
NewFlag: flag,
339341
}
340342
})
341343

pkg/gui/controllers/local_commits_controller.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ func secondaryPatchPanelUpdateOpts(c *ControllerCommon) *types.ViewUpdateOpts {
306306

307307
func (self *LocalCommitsController) squashDown(selectedCommits []*models.Commit, startIdx int, endIdx int) error {
308308
if self.isRebasing() {
309-
return self.updateTodos(todo.Squash, selectedCommits)
309+
return self.updateTodos(todo.Squash, "", selectedCommits)
310310
}
311311

312312
self.c.Confirm(types.ConfirmOpts{
@@ -315,7 +315,7 @@ func (self *LocalCommitsController) squashDown(selectedCommits []*models.Commit,
315315
HandleConfirm: func() error {
316316
return self.c.WithWaitingStatus(self.c.Tr.SquashingStatus, func(gocui.Task) error {
317317
self.c.LogAction(self.c.Tr.Actions.SquashCommitDown)
318-
return self.interactiveRebase(todo.Squash, startIdx, endIdx)
318+
return self.interactiveRebase(todo.Squash, "", startIdx, endIdx)
319319
})
320320
},
321321
})
@@ -325,7 +325,7 @@ func (self *LocalCommitsController) squashDown(selectedCommits []*models.Commit,
325325

326326
func (self *LocalCommitsController) fixup(selectedCommits []*models.Commit, startIdx int, endIdx int) error {
327327
if self.isRebasing() {
328-
return self.updateTodos(todo.Fixup, selectedCommits)
328+
return self.updateTodos(todo.Fixup, "", selectedCommits)
329329
}
330330

331331
self.c.Confirm(types.ConfirmOpts{
@@ -334,7 +334,7 @@ func (self *LocalCommitsController) fixup(selectedCommits []*models.Commit, star
334334
HandleConfirm: func() error {
335335
return self.c.WithWaitingStatus(self.c.Tr.FixingStatus, func(gocui.Task) error {
336336
self.c.LogAction(self.c.Tr.Actions.FixupCommit)
337-
return self.interactiveRebase(todo.Fixup, startIdx, endIdx)
337+
return self.interactiveRebase(todo.Fixup, "", startIdx, endIdx)
338338
})
339339
},
340340
})
@@ -469,14 +469,14 @@ func (self *LocalCommitsController) drop(selectedCommits []*models.Commit, start
469469

470470
self.context().SetSelectionRangeAndMode(selectedIdx, rangeStartIdx, rangeSelectMode)
471471

472-
return self.updateTodos(todo.Drop, nonUpdateRefTodos)
472+
return self.updateTodos(todo.Drop, "", nonUpdateRefTodos)
473473
},
474474
})
475475

476476
return nil
477477
}
478478

479-
return self.updateTodos(todo.Drop, selectedCommits)
479+
return self.updateTodos(todo.Drop, "", selectedCommits)
480480
}
481481

482482
isMerge := selectedCommits[0].IsMerge()
@@ -490,7 +490,7 @@ func (self *LocalCommitsController) drop(selectedCommits []*models.Commit, start
490490
if isMerge {
491491
return self.dropMergeCommit(startIdx)
492492
}
493-
return self.interactiveRebase(todo.Drop, startIdx, endIdx)
493+
return self.interactiveRebase(todo.Drop, "", startIdx, endIdx)
494494
})
495495
},
496496
})
@@ -505,13 +505,13 @@ func (self *LocalCommitsController) dropMergeCommit(commitIdx int) error {
505505

506506
func (self *LocalCommitsController) edit(selectedCommits []*models.Commit, startIdx int, endIdx int) error {
507507
if self.isRebasing() {
508-
return self.updateTodos(todo.Edit, selectedCommits)
508+
return self.updateTodos(todo.Edit, "", selectedCommits)
509509
}
510510

511511
commits := self.c.Model().Commits
512512
if !commits[endIdx].IsMerge() {
513513
selectionRangeAndMode := self.getSelectionRangeAndMode()
514-
err := self.c.Git().Rebase.InteractiveRebase(commits, startIdx, endIdx, todo.Edit)
514+
err := self.c.Git().Rebase.InteractiveRebase(commits, startIdx, endIdx, todo.Edit, "")
515515
return self.c.Helpers().MergeAndRebase.CheckMergeOrRebaseWithRefreshOptions(
516516
err,
517517
types.RefreshOptions{
@@ -552,7 +552,7 @@ func (self *LocalCommitsController) startInteractiveRebaseWithEdit(
552552
}
553553
}
554554
if len(todos) > 0 {
555-
err := self.updateTodos(todo.Edit, todos)
555+
err := self.updateTodos(todo.Edit, "", todos)
556556
if err != nil {
557557
return err
558558
}
@@ -612,29 +612,29 @@ func (self *LocalCommitsController) findCommitForQuickStartInteractiveRebase() (
612612

613613
func (self *LocalCommitsController) pick(selectedCommits []*models.Commit) error {
614614
if self.isRebasing() {
615-
return self.updateTodos(todo.Pick, selectedCommits)
615+
return self.updateTodos(todo.Pick, "", selectedCommits)
616616
}
617617

618618
panic("should be disabled when not rebasing")
619619
}
620620

621-
func (self *LocalCommitsController) interactiveRebase(action todo.TodoCommand, startIdx int, endIdx int) error {
621+
func (self *LocalCommitsController) interactiveRebase(action todo.TodoCommand, flag string, startIdx int, endIdx int) error {
622622
// When performing an action that will remove the selected commits, we need to select the
623623
// next commit down (which will end up at the start index after the action is performed)
624624
if action == todo.Drop || action == todo.Fixup || action == todo.Squash {
625625
self.context().SetSelection(startIdx)
626626
}
627627

628-
err := self.c.Git().Rebase.InteractiveRebase(self.c.Model().Commits, startIdx, endIdx, action)
628+
err := self.c.Git().Rebase.InteractiveRebase(self.c.Model().Commits, startIdx, endIdx, action, flag)
629629

630630
return self.c.Helpers().MergeAndRebase.CheckMergeOrRebase(err)
631631
}
632632

633633
// updateTodos sees if the selected commit is in fact a rebasing
634634
// commit meaning you are trying to edit the todo file rather than actually
635635
// begin a rebase. It then updates the todo file with that action
636-
func (self *LocalCommitsController) updateTodos(action todo.TodoCommand, selectedCommits []*models.Commit) error {
637-
if err := self.c.Git().Rebase.EditRebaseTodo(selectedCommits, action); err != nil {
636+
func (self *LocalCommitsController) updateTodos(action todo.TodoCommand, flag string, selectedCommits []*models.Commit) error {
637+
if err := self.c.Git().Rebase.EditRebaseTodo(selectedCommits, action, flag); err != nil {
638638
return err
639639
}
640640

pkg/utils/rebase_todo.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ type Todo struct {
1919
type TodoChange struct {
2020
Hash string
2121
NewAction todo.TodoCommand
22+
NewFlag string
2223
}
2324

2425
// Read a git-rebase-todo file, change the actions for the given commits,
@@ -37,6 +38,7 @@ func EditRebaseTodo(filePath string, changes []TodoChange, commentChar byte) err
3738
if equalHash(t.Commit, change.Hash) {
3839
matchCount++
3940
t.Command = change.NewAction
41+
t.Flag = change.NewFlag
4042
}
4143
}
4244
}

0 commit comments

Comments
 (0)