Skip to content

Commit 88e6e1f

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 df6a862 commit 88e6e1f

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
@@ -314,7 +314,7 @@ func secondaryPatchPanelUpdateOpts(c *ControllerCommon) *types.ViewUpdateOpts {
314314

315315
func (self *LocalCommitsController) squashDown(selectedCommits []*models.Commit, startIdx int, endIdx int) error {
316316
if self.isRebasing() {
317-
return self.updateTodos(todo.Squash, selectedCommits)
317+
return self.updateTodos(todo.Squash, "", selectedCommits)
318318
}
319319

320320
self.c.Confirm(types.ConfirmOpts{
@@ -323,7 +323,7 @@ func (self *LocalCommitsController) squashDown(selectedCommits []*models.Commit,
323323
HandleConfirm: func() error {
324324
return self.c.WithWaitingStatus(self.c.Tr.SquashingStatus, func(gocui.Task) error {
325325
self.c.LogAction(self.c.Tr.Actions.SquashCommitDown)
326-
return self.interactiveRebase(todo.Squash, startIdx, endIdx)
326+
return self.interactiveRebase(todo.Squash, "", startIdx, endIdx)
327327
})
328328
},
329329
})
@@ -333,7 +333,7 @@ func (self *LocalCommitsController) squashDown(selectedCommits []*models.Commit,
333333

334334
func (self *LocalCommitsController) fixup(selectedCommits []*models.Commit, startIdx int, endIdx int) error {
335335
if self.isRebasing() {
336-
return self.updateTodos(todo.Fixup, selectedCommits)
336+
return self.updateTodos(todo.Fixup, "", selectedCommits)
337337
}
338338

339339
self.c.Confirm(types.ConfirmOpts{
@@ -342,7 +342,7 @@ func (self *LocalCommitsController) fixup(selectedCommits []*models.Commit, star
342342
HandleConfirm: func() error {
343343
return self.c.WithWaitingStatus(self.c.Tr.FixingStatus, func(gocui.Task) error {
344344
self.c.LogAction(self.c.Tr.Actions.FixupCommit)
345-
return self.interactiveRebase(todo.Fixup, startIdx, endIdx)
345+
return self.interactiveRebase(todo.Fixup, "", startIdx, endIdx)
346346
})
347347
},
348348
})
@@ -477,14 +477,14 @@ func (self *LocalCommitsController) drop(selectedCommits []*models.Commit, start
477477

478478
self.context().SetSelectionRangeAndMode(selectedIdx, rangeStartIdx, rangeSelectMode)
479479

480-
return self.updateTodos(todo.Drop, nonUpdateRefTodos)
480+
return self.updateTodos(todo.Drop, "", nonUpdateRefTodos)
481481
},
482482
})
483483

484484
return nil
485485
}
486486

487-
return self.updateTodos(todo.Drop, selectedCommits)
487+
return self.updateTodos(todo.Drop, "", selectedCommits)
488488
}
489489

490490
isMerge := selectedCommits[0].IsMerge()
@@ -498,7 +498,7 @@ func (self *LocalCommitsController) drop(selectedCommits []*models.Commit, start
498498
if isMerge {
499499
return self.dropMergeCommit(startIdx)
500500
}
501-
return self.interactiveRebase(todo.Drop, startIdx, endIdx)
501+
return self.interactiveRebase(todo.Drop, "", startIdx, endIdx)
502502
})
503503
},
504504
})
@@ -513,13 +513,13 @@ func (self *LocalCommitsController) dropMergeCommit(commitIdx int) error {
513513

514514
func (self *LocalCommitsController) edit(selectedCommits []*models.Commit, startIdx int, endIdx int) error {
515515
if self.isRebasing() {
516-
return self.updateTodos(todo.Edit, selectedCommits)
516+
return self.updateTodos(todo.Edit, "", selectedCommits)
517517
}
518518

519519
commits := self.c.Model().Commits
520520
if !commits[endIdx].IsMerge() {
521521
selectionRangeAndMode := self.getSelectionRangeAndMode()
522-
err := self.c.Git().Rebase.InteractiveRebase(commits, startIdx, endIdx, todo.Edit)
522+
err := self.c.Git().Rebase.InteractiveRebase(commits, startIdx, endIdx, todo.Edit, "")
523523
return self.c.Helpers().MergeAndRebase.CheckMergeOrRebaseWithRefreshOptions(
524524
err,
525525
types.RefreshOptions{
@@ -560,7 +560,7 @@ func (self *LocalCommitsController) startInteractiveRebaseWithEdit(
560560
}
561561
}
562562
if len(todos) > 0 {
563-
err := self.updateTodos(todo.Edit, todos)
563+
err := self.updateTodos(todo.Edit, "", todos)
564564
if err != nil {
565565
return err
566566
}
@@ -620,31 +620,31 @@ func (self *LocalCommitsController) findCommitForQuickStartInteractiveRebase() (
620620

621621
func (self *LocalCommitsController) pick(selectedCommits []*models.Commit) error {
622622
if self.isRebasing() {
623-
return self.updateTodos(todo.Pick, selectedCommits)
623+
return self.updateTodos(todo.Pick, "", selectedCommits)
624624
}
625625

626626
// at this point we aren't actually rebasing so we will interpret this as an
627627
// attempt to pull. We might revoke this later after enabling configurable keybindings
628628
return self.pullFiles()
629629
}
630630

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

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

640640
return self.c.Helpers().MergeAndRebase.CheckMergeOrRebase(err)
641641
}
642642

643643
// updateTodos sees if the selected commit is in fact a rebasing
644644
// commit meaning you are trying to edit the todo file rather than actually
645645
// begin a rebase. It then updates the todo file with that action
646-
func (self *LocalCommitsController) updateTodos(action todo.TodoCommand, selectedCommits []*models.Commit) error {
647-
if err := self.c.Git().Rebase.EditRebaseTodo(selectedCommits, action); err != nil {
646+
func (self *LocalCommitsController) updateTodos(action todo.TodoCommand, flag string, selectedCommits []*models.Commit) error {
647+
if err := self.c.Git().Rebase.EditRebaseTodo(selectedCommits, action, flag); err != nil {
648648
return err
649649
}
650650

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)