2018-12-08 07:54:54 +02:00
package gui
import (
"fmt"
"strings"
"github.com/jesseduffield/gocui"
)
type option struct {
value string
}
// GetDisplayStrings is a function.
2019-02-16 06:17:44 +02:00
func ( r * option ) GetDisplayStrings ( isFocused bool ) [ ] string {
2018-12-08 07:54:54 +02:00
return [ ] string { r . value }
}
func ( gui * Gui ) handleCreateRebaseOptionsMenu ( g * gocui . Gui , v * gocui . View ) error {
options := [ ] * option {
{ value : "continue" } ,
{ value : "abort" } ,
}
if gui . State . WorkingTreeState == "rebasing" {
options = append ( options , & option { value : "skip" } )
}
handleMenuPress := func ( index int ) error {
command := options [ index ] . value
2019-02-16 12:01:17 +02:00
return gui . genericMergeCommand ( command )
2018-12-08 07:54:54 +02:00
}
var title string
if gui . State . WorkingTreeState == "merging" {
title = gui . Tr . SLocalize ( "MergeOptionsTitle" )
} else {
title = gui . Tr . SLocalize ( "RebaseOptionsTitle" )
}
2019-03-23 02:42:19 +02:00
return gui . createMenu ( title , options , len ( options ) , handleMenuPress )
2018-12-08 07:54:54 +02:00
}
2019-02-16 12:01:17 +02:00
func ( gui * Gui ) genericMergeCommand ( command string ) error {
2018-12-08 07:54:54 +02:00
status := gui . State . WorkingTreeState
if status != "merging" && status != "rebasing" {
return gui . createErrorPanel ( gui . g , gui . Tr . SLocalize ( "NotMergingOrRebasing" ) )
}
commandType := strings . Replace ( status , "ing" , "e" , 1 )
// we should end up with a command like 'git merge --continue'
2018-12-11 13:16:48 +02:00
// it's impossible for a rebase to require a commit so we'll use a subprocess only if it's a merge
2019-02-16 12:01:17 +02:00
if status == "merging" && command != "abort" && gui . Config . GetUserConfig ( ) . GetBool ( "git.merging.manualCommit" ) {
2018-12-11 13:16:48 +02:00
sub := gui . OSCommand . PrepareSubProcess ( "git" , commandType , fmt . Sprintf ( "--%s" , command ) )
if sub != nil {
gui . SubProcess = sub
return gui . Errors . ErrSubProcess
}
return nil
2018-12-08 07:54:54 +02:00
}
2019-02-16 12:01:17 +02:00
result := gui . GitCommand . GenericMerge ( commandType , command )
if err := gui . handleGenericMergeCommandResult ( result ) ; err != nil {
return err
}
return nil
}
2018-12-08 07:54:54 +02:00
2019-02-16 12:01:17 +02:00
func ( gui * Gui ) handleGenericMergeCommandResult ( result error ) error {
if err := gui . refreshSidePanels ( gui . g ) ; err != nil {
return err
}
if result == nil {
return nil
} else if result == gui . Errors . ErrSubProcess {
return result
} else if strings . Contains ( result . Error ( ) , "No changes - did you forget to use" ) {
return gui . genericMergeCommand ( "skip" )
2019-11-05 04:02:04 +02:00
} else if strings . Contains ( result . Error ( ) , "The previous cherry-pick is now empty" ) {
return gui . genericMergeCommand ( "continue" )
2019-03-02 11:56:54 +02:00
} else if strings . Contains ( result . Error ( ) , "When you have resolved this problem" ) || strings . Contains ( result . Error ( ) , "fix conflicts" ) || strings . Contains ( result . Error ( ) , "Resolve all conflicts manually" ) {
2019-11-05 06:19:43 +02:00
return gui . createConfirmationPanel ( gui . g , gui . getFilesView ( ) , true , gui . Tr . SLocalize ( "FoundConflictsTitle" ) , gui . Tr . SLocalize ( "FoundConflicts" ) ,
2019-02-16 12:01:17 +02:00
func ( g * gocui . Gui , v * gocui . View ) error {
return nil
} , func ( g * gocui . Gui , v * gocui . View ) error {
return gui . genericMergeCommand ( "abort" )
} ,
)
} else {
return gui . createErrorPanel ( gui . g , result . Error ( ) )
}
2018-12-08 07:54:54 +02:00
}