Skip to content

Commit

Permalink
Extracting GenericMergeOrRebaseAction into multiple functions, fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Neko-Box-Coder committed Aug 17, 2024
1 parent f3544d7 commit bcd21fb
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
30 changes: 20 additions & 10 deletions pkg/commands/git_commands/rebase.go
Original file line number Diff line number Diff line change
Expand Up @@ -438,24 +438,34 @@ func (self *RebaseCommands) GenericMergeOrRebaseActionCmdObj(commandType string,
}

func (self *RebaseCommands) ContinueRebase() error {
return self.GenericMergeOrRebaseAction("rebase", "continue")
err := self.runSkipEditorCommand(self.GenericMergeOrRebaseActionCmdObj("rebase", "continue"))
if self.ProcessMergeRebaseResult(err) != nil {
return err
}
return self.InvokeGenericMergeOrRebaseActionCallback("rebase", "continue")
}

func (self *RebaseCommands) AbortRebase() error {
return self.GenericMergeOrRebaseAction("rebase", "abort")
err := self.runSkipEditorCommand(self.GenericMergeOrRebaseActionCmdObj("rebase", "abort"))
if self.ProcessMergeRebaseResult(err) != nil {
return err
}
return self.InvokeGenericMergeOrRebaseActionCallback("rebase", "abort")
}

// GenericMerge takes a commandType of "merge" or "rebase" and a command of "abort", "skip" or "continue"
// By default we skip the editor in the case where a commit will be made
func (self *RebaseCommands) GenericMergeOrRebaseAction(commandType string, command string) error {
err := self.runSkipEditorCommand(self.GenericMergeOrRebaseActionCmdObj(commandType, command))
if err != nil {
if !strings.Contains(err.Error(), "no rebase in progress") {
return err
func (self *RebaseCommands) ProcessMergeRebaseResult(result error) error {
if result != nil {
if !strings.Contains(result.Error(), "no rebase in progress") {
return result
}
self.Log.Warn(err)
self.Log.Warn(result)
}
return result
}

// GenericMerge takes a commandType of "merge" or "rebase" and a command of "abort", "skip" or "continue"
// By default we skip the editor in the case where a commit will be made
func (self *RebaseCommands) InvokeGenericMergeOrRebaseActionCallback(commandType string, command string) error {
// sometimes we need to do a sequence of things in a rebase but the user needs to
// fix merge conflicts along the way. When this happens we queue up the next step
// so that after the next successful rebase continue we can continue from where we left off
Expand Down
6 changes: 6 additions & 0 deletions pkg/gui/controllers/helpers/merge_and_rebase_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,12 @@ func (self *MergeAndRebaseHelper) genericMergeCommand(command string) error {
result = self.c.Git().Rebase.AddSkipEditorCommand(runCmd).Run()
}

result = self.c.Git().Rebase.ProcessMergeRebaseResult(result)
if result != nil {
return result
}

result = self.c.Git().Rebase.InvokeGenericMergeOrRebaseActionCallback(commandType, command)
if err := self.CheckMergeOrRebase(result); err != nil {
return err
}
Expand Down

0 comments on commit bcd21fb

Please sign in to comment.