mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-04-25 12:24:47 +02:00
more work on rebasing feature
This commit is contained in:
parent
ad93b4c863
commit
e011e9bc42
@ -17,6 +17,10 @@
|
|||||||
- blue
|
- blue
|
||||||
commitLength:
|
commitLength:
|
||||||
show: true
|
show: true
|
||||||
|
git:
|
||||||
|
merging:
|
||||||
|
# only applicable to unix users
|
||||||
|
manualCommit: false
|
||||||
update:
|
update:
|
||||||
method: prompt # can be: prompt | background | never
|
method: prompt # can be: prompt | background | never
|
||||||
days: 14 # how often an update is checked for
|
days: 14 # how often an update is checked for
|
||||||
|
@ -274,26 +274,6 @@ func (c *GitCommand) RebaseBranch(onto string) error {
|
|||||||
return c.OSCommand.RunCommand(fmt.Sprintf("git rebase %s %s ", onto, curBranch))
|
return c.OSCommand.RunCommand(fmt.Sprintf("git rebase %s %s ", onto, curBranch))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *GitCommand) ContinueRebaseBranch() error {
|
|
||||||
return c.OSCommand.RunCommand("git rebase --continue")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *GitCommand) SkipRebaseBranch() error {
|
|
||||||
return c.OSCommand.RunCommand("git rebase --skip")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *GitCommand) AbortRebaseBranch() error {
|
|
||||||
return c.OSCommand.RunCommand("git rebase --abort")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *GitCommand) ContinueMergeBranch() error {
|
|
||||||
return c.OSCommand.RunCommand("git merge --continue")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *GitCommand) AbortMergeBranch() error {
|
|
||||||
return c.OSCommand.RunCommand("git merge --abort")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fetch fetch git repo
|
// Fetch fetch git repo
|
||||||
func (c *GitCommand) Fetch(unamePassQuestion func(string) string, canAskForCredentials bool) error {
|
func (c *GitCommand) Fetch(unamePassQuestion func(string) string, canAskForCredentials bool) error {
|
||||||
return c.OSCommand.DetectUnamePass("git fetch", func(question string) string {
|
return c.OSCommand.DetectUnamePass("git fetch", func(question string) string {
|
||||||
@ -787,3 +767,10 @@ func (c *GitCommand) FastForward(branchName string) error {
|
|||||||
upstream := "origin" // hardcoding for now
|
upstream := "origin" // hardcoding for now
|
||||||
return c.OSCommand.RunCommand(fmt.Sprintf("git fetch %s %s:%s", upstream, branchName, branchName))
|
return c.OSCommand.RunCommand(fmt.Sprintf("git fetch %s %s:%s", upstream, branchName, branchName))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GenericMerge takes a commandType of "merging" or "rebasing" and a command of "abort", "skip" or "continue"
|
||||||
|
// By default we skip the editor in the case where a commit will be made
|
||||||
|
func (c *GitCommand) GenericMerge(commandType string, command string) error {
|
||||||
|
gitCommand := fmt.Sprintf("git %s %s --%s", c.OSCommand.Platform.skipEditorArg, commandType, command)
|
||||||
|
return c.OSCommand.RunCommand(gitCommand)
|
||||||
|
}
|
||||||
|
@ -25,6 +25,7 @@ type Platform struct {
|
|||||||
openCommand string
|
openCommand string
|
||||||
openLinkCommand string
|
openLinkCommand string
|
||||||
fallbackEscapedQuote string
|
fallbackEscapedQuote string
|
||||||
|
skipEditorArg string
|
||||||
}
|
}
|
||||||
|
|
||||||
// OSCommand holds all the os commands
|
// OSCommand holds all the os commands
|
||||||
|
@ -15,5 +15,6 @@ func getPlatform() *Platform {
|
|||||||
openCommand: "open {{filename}}",
|
openCommand: "open {{filename}}",
|
||||||
openLinkCommand: "open {{link}}",
|
openLinkCommand: "open {{link}}",
|
||||||
fallbackEscapedQuote: "\"",
|
fallbackEscapedQuote: "\"",
|
||||||
|
skipEditorArg: "-c core.editor=true",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -239,6 +239,9 @@ func GetDefaultConfig() []byte {
|
|||||||
- blue
|
- blue
|
||||||
commitLength:
|
commitLength:
|
||||||
show: true
|
show: true
|
||||||
|
git:
|
||||||
|
merging:
|
||||||
|
manualCommit: false
|
||||||
update:
|
update:
|
||||||
method: prompt # can be: prompt | background | never
|
method: prompt # can be: prompt | background | never
|
||||||
days: 14 # how often a update is checked for
|
days: 14 # how often a update is checked for
|
||||||
|
@ -98,43 +98,6 @@ func (gui *Gui) handleBranchesPrevLine(g *gocui.Gui, v *gocui.View) error {
|
|||||||
|
|
||||||
// specific functions
|
// specific functions
|
||||||
|
|
||||||
func (gui *Gui) handleRebase(g *gocui.Gui, v *gocui.View) error {
|
|
||||||
|
|
||||||
selectedBranch := gui.getSelectedBranch().Name
|
|
||||||
checkedOutBranch := gui.State.Branches[0].Name
|
|
||||||
title := "Rebasing"
|
|
||||||
prompt := fmt.Sprintf("Are you sure you want to rebase %s onto %s?", checkedOutBranch, selectedBranch)
|
|
||||||
|
|
||||||
return gui.createConfirmationPanel(g, v, title, prompt,
|
|
||||||
func(g *gocui.Gui, v *gocui.View) error {
|
|
||||||
if selectedBranch == checkedOutBranch {
|
|
||||||
return gui.createErrorPanel(g, gui.Tr.SLocalize("CantRebaseOntoSelf"))
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := gui.GitCommand.RebaseBranch(selectedBranch); err != nil {
|
|
||||||
if !strings.Contains(err.Error(), "When you have resolved this problem") {
|
|
||||||
return gui.createErrorPanel(gui.g, err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := gui.refreshSidePanels(g); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return gui.createConfirmationPanel(g, v, "Auto-rebase failed", gui.Tr.SLocalize("FoundConflicts"),
|
|
||||||
func(g *gocui.Gui, v *gocui.View) error {
|
|
||||||
return gui.refreshSidePanels(g)
|
|
||||||
}, func(g *gocui.Gui, v *gocui.View) error {
|
|
||||||
if err := gui.GitCommand.AbortRebaseBranch(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return gui.refreshSidePanels(g)
|
|
||||||
},
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
return gui.refreshSidePanels(g)
|
|
||||||
}, nil)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (gui *Gui) handleBranchPress(g *gocui.Gui, v *gocui.View) error {
|
func (gui *Gui) handleBranchPress(g *gocui.Gui, v *gocui.View) error {
|
||||||
if gui.State.Panels.Branches.SelectedLine == -1 {
|
if gui.State.Panels.Branches.SelectedLine == -1 {
|
||||||
return nil
|
return nil
|
||||||
@ -263,28 +226,45 @@ func (gui *Gui) deleteNamedBranch(g *gocui.Gui, v *gocui.View, selectedBranch *c
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) handleMerge(g *gocui.Gui, v *gocui.View) error {
|
func (gui *Gui) handleMerge(g *gocui.Gui, v *gocui.View) error {
|
||||||
checkedOutBranch := gui.State.Branches[0]
|
checkedOutBranch := gui.State.Branches[0].Name
|
||||||
selectedBranch := gui.getSelectedBranch()
|
selectedBranch := gui.getSelectedBranch().Name
|
||||||
defer gui.refreshSidePanels(g)
|
if checkedOutBranch == selectedBranch {
|
||||||
if checkedOutBranch.Name == selectedBranch.Name {
|
|
||||||
return gui.createErrorPanel(g, gui.Tr.SLocalize("CantMergeBranchIntoItself"))
|
return gui.createErrorPanel(g, gui.Tr.SLocalize("CantMergeBranchIntoItself"))
|
||||||
}
|
}
|
||||||
if err := gui.GitCommand.Merge(selectedBranch.Name); err != nil {
|
prompt := gui.Tr.TemplateLocalize(
|
||||||
if strings.Contains(err.Error(), "fix conflicts") {
|
"ConfirmMerge",
|
||||||
return gui.createConfirmationPanel(g, v, "Auto-merge failed", gui.Tr.SLocalize("FoundConflicts"),
|
Teml{
|
||||||
func(g *gocui.Gui, v *gocui.View) error {
|
"checkedOutBranch": checkedOutBranch,
|
||||||
return nil
|
"selectedBranch": selectedBranch,
|
||||||
}, func(g *gocui.Gui, v *gocui.View) error {
|
},
|
||||||
if err := gui.GitCommand.AbortMergeBranch(); err != nil {
|
)
|
||||||
return err
|
return gui.createConfirmationPanel(g, v, gui.Tr.SLocalize("MergingTitle"), prompt,
|
||||||
}
|
func(g *gocui.Gui, v *gocui.View) error {
|
||||||
return gui.refreshSidePanels(g)
|
|
||||||
},
|
err := gui.GitCommand.Merge(selectedBranch)
|
||||||
)
|
return gui.handleGenericMergeCommandResult(err)
|
||||||
}
|
}, nil)
|
||||||
return gui.createErrorPanel(g, err.Error())
|
}
|
||||||
|
|
||||||
|
func (gui *Gui) handleRebase(g *gocui.Gui, v *gocui.View) error {
|
||||||
|
checkedOutBranch := gui.State.Branches[0].Name
|
||||||
|
selectedBranch := gui.getSelectedBranch().Name
|
||||||
|
if selectedBranch == checkedOutBranch {
|
||||||
|
return gui.createErrorPanel(g, gui.Tr.SLocalize("CantRebaseOntoSelf"))
|
||||||
}
|
}
|
||||||
return nil
|
prompt := gui.Tr.TemplateLocalize(
|
||||||
|
"ConfirmRebase",
|
||||||
|
Teml{
|
||||||
|
"checkedOutBranch": checkedOutBranch,
|
||||||
|
"selectedBranch": selectedBranch,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
return gui.createConfirmationPanel(g, v, gui.Tr.SLocalize("RebasingTitle"), prompt,
|
||||||
|
func(g *gocui.Gui, v *gocui.View) error {
|
||||||
|
|
||||||
|
err := gui.GitCommand.RebaseBranch(selectedBranch)
|
||||||
|
return gui.handleGenericMergeCommandResult(err)
|
||||||
|
}, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) handleFastForward(g *gocui.Gui, v *gocui.View) error {
|
func (gui *Gui) handleFastForward(g *gocui.Gui, v *gocui.View) error {
|
||||||
@ -296,10 +276,10 @@ func (gui *Gui) handleFastForward(g *gocui.Gui, v *gocui.View) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if branch.Pushables == "?" {
|
if branch.Pushables == "?" {
|
||||||
return gui.createErrorPanel(gui.g, "Cannot fast-forward a branch with no upstream")
|
return gui.createErrorPanel(gui.g, gui.Tr.SLocalize("FwdNoUpstream"))
|
||||||
}
|
}
|
||||||
if branch.Pushables != "0" {
|
if branch.Pushables != "0" {
|
||||||
return gui.createErrorPanel(gui.g, "Cannot fast-forward a branch with commits to push")
|
return gui.createErrorPanel(gui.g, gui.Tr.SLocalize("FwdCommitsToPush"))
|
||||||
}
|
}
|
||||||
upstream := "origin" // hardcoding for now
|
upstream := "origin" // hardcoding for now
|
||||||
message := gui.Tr.TemplateLocalize(
|
message := gui.Tr.TemplateLocalize(
|
||||||
|
76
pkg/gui/context.go
Normal file
76
pkg/gui/context.go
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
package gui
|
||||||
|
|
||||||
|
func (gui *Gui) titleMap() map[string]string {
|
||||||
|
return map[string]string{
|
||||||
|
"commits": gui.Tr.SLocalize("DiffTitle"),
|
||||||
|
"branches": gui.Tr.SLocalize("LogTitle"),
|
||||||
|
"files": gui.Tr.SLocalize("DiffTitle"),
|
||||||
|
"status": "",
|
||||||
|
"stash": gui.Tr.SLocalize("DiffTitle"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (gui *Gui) contextTitleMap() map[string]map[string]string {
|
||||||
|
return map[string]map[string]string{
|
||||||
|
"main": {
|
||||||
|
"staging": gui.Tr.SLocalize("StagingMainTitle"),
|
||||||
|
"merging": gui.Tr.SLocalize("MergingMainTitle"),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (gui *Gui) setMainTitle() error {
|
||||||
|
currentViewName := gui.g.CurrentView().Name()
|
||||||
|
var newTitle string
|
||||||
|
if context, ok := gui.State.Contexts[currentViewName]; ok {
|
||||||
|
newTitle = gui.contextTitleMap()[currentViewName][context]
|
||||||
|
} else if title, ok := gui.titleMap()[currentViewName]; ok {
|
||||||
|
newTitle = title
|
||||||
|
} else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
gui.getMainView().Title = newTitle
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (gui *Gui) changeContext(viewName, context string) error {
|
||||||
|
// todo: store somewhere permanently
|
||||||
|
if gui.State.Contexts[viewName] == context {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
contextMap := gui.getContextMap()
|
||||||
|
|
||||||
|
gui.g.DeleteKeybindings(viewName)
|
||||||
|
|
||||||
|
bindings := contextMap[viewName][context]
|
||||||
|
for _, binding := range bindings {
|
||||||
|
if err := gui.g.SetKeybinding(viewName, binding.Key, binding.Modifier, binding.Handler); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
gui.State.Contexts[viewName] = context
|
||||||
|
gui.setMainTitle()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (gui *Gui) setInitialContexts() error {
|
||||||
|
contextMap := gui.getContextMap()
|
||||||
|
|
||||||
|
initialContexts := map[string]string{
|
||||||
|
"main": "merging",
|
||||||
|
}
|
||||||
|
|
||||||
|
for viewName, context := range initialContexts {
|
||||||
|
bindings := contextMap[viewName][context]
|
||||||
|
for _, binding := range bindings {
|
||||||
|
if err := gui.g.SetKeybinding(binding.ViewName, binding.Key, binding.Modifier, binding.Handler); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
gui.State.Contexts = initialContexts
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
@ -217,6 +217,9 @@ func (gui *Gui) getFocusLayout() func(g *gocui.Gui) error {
|
|||||||
return func(g *gocui.Gui) error {
|
return func(g *gocui.Gui) error {
|
||||||
v := gui.g.CurrentView()
|
v := gui.g.CurrentView()
|
||||||
if v != focusedView {
|
if v != focusedView {
|
||||||
|
if err := gui.onFocusChange(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
if err := gui.onFocusLost(focusedView); err != nil {
|
if err := gui.onFocusLost(focusedView); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -229,6 +232,14 @@ func (gui *Gui) getFocusLayout() func(g *gocui.Gui) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (gui *Gui) onFocusChange() error {
|
||||||
|
currentView := gui.g.CurrentView()
|
||||||
|
for _, view := range gui.g.Views() {
|
||||||
|
view.Highlight = view == currentView
|
||||||
|
}
|
||||||
|
return gui.setMainTitle()
|
||||||
|
}
|
||||||
|
|
||||||
func (gui *Gui) onFocusLost(v *gocui.View) error {
|
func (gui *Gui) onFocusLost(v *gocui.View) error {
|
||||||
if v == nil {
|
if v == nil {
|
||||||
return nil
|
return nil
|
||||||
@ -306,31 +317,6 @@ func (gui *Gui) layout(g *gocui.Gui) error {
|
|||||||
v.FgColor = gocui.ColorWhite
|
v.FgColor = gocui.ColorWhite
|
||||||
}
|
}
|
||||||
|
|
||||||
// v, err = g.SetView("staging", leftSideWidth+panelSpacing, 0, width-1, optionsTop, gocui.LEFT)
|
|
||||||
// if err != nil {
|
|
||||||
// if err.Error() != "unknown view" {
|
|
||||||
// return err
|
|
||||||
// }
|
|
||||||
// v.Title = gui.Tr.SLocalize("StagingTitle")
|
|
||||||
// v.Highlight = true
|
|
||||||
// v.FgColor = gocui.ColorWhite
|
|
||||||
// if _, err := g.SetViewOnBottom("staging"); err != nil {
|
|
||||||
// return err
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// v, err = g.SetView("merging", leftSideWidth+panelSpacing, 0, width-1, optionsTop, gocui.LEFT)
|
|
||||||
// if err != nil {
|
|
||||||
// if err.Error() != "unknown view" {
|
|
||||||
// return err
|
|
||||||
// }
|
|
||||||
// v.Title = gui.Tr.SLocalize("MergingTitle")
|
|
||||||
// v.FgColor = gocui.ColorWhite
|
|
||||||
// if _, err := g.SetViewOnBottom("merging"); err != nil {
|
|
||||||
// return err
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
if v, err := g.SetView("status", 0, 0, leftSideWidth, statusFilesBoundary, gocui.BOTTOM|gocui.RIGHT); err != nil {
|
if v, err := g.SetView("status", 0, 0, leftSideWidth, statusFilesBoundary, gocui.BOTTOM|gocui.RIGHT); err != nil {
|
||||||
if err.Error() != "unknown view" {
|
if err.Error() != "unknown view" {
|
||||||
return err
|
return err
|
||||||
|
@ -417,48 +417,6 @@ func (gui *Gui) keybindings(g *gocui.Gui) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) setInitialContexts() error {
|
|
||||||
contextMap := gui.getContextMap()
|
|
||||||
|
|
||||||
initialContexts := map[string]string{
|
|
||||||
"main": "merging",
|
|
||||||
}
|
|
||||||
|
|
||||||
for viewName, context := range initialContexts {
|
|
||||||
bindings := contextMap[viewName][context]
|
|
||||||
for _, binding := range bindings {
|
|
||||||
if err := gui.g.SetKeybinding(binding.ViewName, binding.Key, binding.Modifier, binding.Handler); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
gui.State.Contexts = initialContexts
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (gui *Gui) changeContext(viewName, context string) error {
|
|
||||||
// todo: store somewhere permanently
|
|
||||||
if gui.State.Contexts[viewName] == context {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
contextMap := gui.getContextMap()
|
|
||||||
|
|
||||||
gui.g.DeleteKeybindings(viewName)
|
|
||||||
|
|
||||||
bindings := contextMap[viewName][context]
|
|
||||||
for _, binding := range bindings {
|
|
||||||
if err := gui.g.SetKeybinding(viewName, binding.Key, binding.Modifier, binding.Handler); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
gui.State.Contexts[viewName] = context
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (gui *Gui) getContextMap() map[string]map[string][]*Binding {
|
func (gui *Gui) getContextMap() map[string]map[string][]*Binding {
|
||||||
return map[string]map[string][]*Binding{
|
return map[string]map[string][]*Binding{
|
||||||
"main": {
|
"main": {
|
||||||
|
@ -270,27 +270,16 @@ func (gui *Gui) handleCompleteMerge() error {
|
|||||||
filesView := gui.getFilesView()
|
filesView := gui.getFilesView()
|
||||||
gui.stageSelectedFile(gui.g)
|
gui.stageSelectedFile(gui.g)
|
||||||
gui.refreshFiles()
|
gui.refreshFiles()
|
||||||
|
// if we got conflicts after unstashing, we don't want to call any git
|
||||||
|
// commands to continue rebasing/merging here
|
||||||
|
if gui.State.WorkingTreeState == "normal" {
|
||||||
|
return gui.handleEscapeMerge(gui.g, gui.getMainView())
|
||||||
|
}
|
||||||
// if there are no more files with merge conflicts, we should ask whether the user wants to continue
|
// if there are no more files with merge conflicts, we should ask whether the user wants to continue
|
||||||
if !gui.anyFilesWithMergeConflicts() {
|
if !gui.anyFilesWithMergeConflicts() {
|
||||||
// ask if user wants to continue
|
// ask if user wants to continue
|
||||||
if err := gui.createConfirmationPanel(gui.g, filesView, "continue", gui.Tr.SLocalize("ConflictsResolved"), func(g *gocui.Gui, v *gocui.View) error {
|
if err := gui.createConfirmationPanel(gui.g, filesView, "continue", gui.Tr.SLocalize("ConflictsResolved"), func(g *gocui.Gui, v *gocui.View) error {
|
||||||
if err := gui.genericRebaseCommand("continue"); err != nil {
|
return gui.genericMergeCommand("continue")
|
||||||
if err == gui.Errors.ErrSubProcess {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if strings.Contains(err.Error(), "No changes - did you forget to use") {
|
|
||||||
if err := gui.genericRebaseCommand("skip"); err != nil {
|
|
||||||
if err == gui.Errors.ErrSubProcess {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
gui.createErrorPanel(gui.g, err.Error())
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// HERE is the place for this special error panel
|
|
||||||
gui.createErrorPanel(gui.g, err.Error())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return gui.refreshSidePanels(gui.g)
|
|
||||||
}, nil); err != nil {
|
}, nil); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -28,11 +28,7 @@ func (gui *Gui) handleCreateRebaseOptionsMenu(g *gocui.Gui, v *gocui.View) error
|
|||||||
|
|
||||||
handleMenuPress := func(index int) error {
|
handleMenuPress := func(index int) error {
|
||||||
command := options[index].value
|
command := options[index].value
|
||||||
err := gui.genericRebaseCommand(command)
|
return gui.genericMergeCommand(command)
|
||||||
if err != nil {
|
|
||||||
return gui.createErrorPanel(gui.g, err.Error())
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var title string
|
var title string
|
||||||
@ -45,7 +41,7 @@ func (gui *Gui) handleCreateRebaseOptionsMenu(g *gocui.Gui, v *gocui.View) error
|
|||||||
return gui.createMenu(title, options, handleMenuPress)
|
return gui.createMenu(title, options, handleMenuPress)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) genericRebaseCommand(command string) error {
|
func (gui *Gui) genericMergeCommand(command string) error {
|
||||||
status := gui.State.WorkingTreeState
|
status := gui.State.WorkingTreeState
|
||||||
|
|
||||||
if status != "merging" && status != "rebasing" {
|
if status != "merging" && status != "rebasing" {
|
||||||
@ -56,7 +52,8 @@ func (gui *Gui) genericRebaseCommand(command string) error {
|
|||||||
// we should end up with a command like 'git merge --continue'
|
// we should end up with a command like 'git merge --continue'
|
||||||
|
|
||||||
// it's impossible for a rebase to require a commit so we'll use a subprocess only if it's a merge
|
// it's impossible for a rebase to require a commit so we'll use a subprocess only if it's a merge
|
||||||
if status == "merging" {
|
// TODO: find a way to make the commit automatic
|
||||||
|
if status == "merging" && command != "abort" && gui.Config.GetUserConfig().GetBool("git.merging.manualCommit") {
|
||||||
sub := gui.OSCommand.PrepareSubProcess("git", commandType, fmt.Sprintf("--%s", command))
|
sub := gui.OSCommand.PrepareSubProcess("git", commandType, fmt.Sprintf("--%s", command))
|
||||||
if sub != nil {
|
if sub != nil {
|
||||||
gui.SubProcess = sub
|
gui.SubProcess = sub
|
||||||
@ -64,6 +61,33 @@ func (gui *Gui) genericRebaseCommand(command string) error {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
result := gui.GitCommand.GenericMerge(commandType, command)
|
||||||
return gui.OSCommand.RunCommand(fmt.Sprintf("git %s --%s", commandType, command))
|
if err := gui.handleGenericMergeCommandResult(result); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
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")
|
||||||
|
} else if strings.Contains(result.Error(), "When you have resolved this problem") || strings.Contains(result.Error(), "fix conflicts") {
|
||||||
|
// TODO: generalise this title to support merging and rebasing
|
||||||
|
return gui.createConfirmationPanel(gui.g, gui.getFilesView(), gui.Tr.SLocalize("FoundConflictsTitle"), gui.Tr.SLocalize("FoundConflicts"),
|
||||||
|
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())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -127,19 +127,11 @@ func (gui *Gui) returnFocus(g *gocui.Gui, v *gocui.View) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// pass in oldView = nil if you don't want to be able to return to your old view
|
// pass in oldView = nil if you don't want to be able to return to your old view
|
||||||
|
// TODO: move some of this logic into our onFocusLost and onFocus hooks
|
||||||
func (gui *Gui) switchFocus(g *gocui.Gui, oldView, newView *gocui.View) error {
|
func (gui *Gui) switchFocus(g *gocui.Gui, oldView, newView *gocui.View) error {
|
||||||
// we assume we'll never want to return focus to a confirmation panel i.e.
|
// we assume we'll never want to return focus to a confirmation panel i.e.
|
||||||
// we should never stack confirmation panels
|
// we should never stack confirmation panels
|
||||||
if oldView != nil && oldView.Name() != "confirmation" {
|
if oldView != nil && oldView.Name() != "confirmation" {
|
||||||
oldView.Highlight = false
|
|
||||||
message := gui.Tr.TemplateLocalize(
|
|
||||||
"settingPreviewsViewTo",
|
|
||||||
Teml{
|
|
||||||
"oldViewName": oldView.Name(),
|
|
||||||
},
|
|
||||||
)
|
|
||||||
gui.Log.Info(message)
|
|
||||||
|
|
||||||
// second class panels should never have focus restored to them because
|
// second class panels should never have focus restored to them because
|
||||||
// once they lose focus they are effectively 'destroyed'
|
// once they lose focus they are effectively 'destroyed'
|
||||||
secondClassPanels := []string{"confirmation", "menu"}
|
secondClassPanels := []string{"confirmation", "menu"}
|
||||||
@ -148,7 +140,7 @@ func (gui *Gui) switchFocus(g *gocui.Gui, oldView, newView *gocui.View) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
newView.Highlight = true
|
gui.Log.Info("setting highlight to true for view" + newView.Name())
|
||||||
message := gui.Tr.TemplateLocalize(
|
message := gui.Tr.TemplateLocalize(
|
||||||
"newFocusedViewIs",
|
"newFocusedViewIs",
|
||||||
Teml{
|
Teml{
|
||||||
|
@ -16,6 +16,9 @@ func addDutch(i18nObject *i18n.Bundle) error {
|
|||||||
}, &i18n.Message{
|
}, &i18n.Message{
|
||||||
ID: "DiffTitle",
|
ID: "DiffTitle",
|
||||||
Other: "Diff",
|
Other: "Diff",
|
||||||
|
}, &i18n.Message{
|
||||||
|
ID: "LogTitle",
|
||||||
|
Other: "Log",
|
||||||
}, &i18n.Message{
|
}, &i18n.Message{
|
||||||
ID: "FilesTitle",
|
ID: "FilesTitle",
|
||||||
Other: "Bestanden",
|
Other: "Bestanden",
|
||||||
@ -28,6 +31,12 @@ func addDutch(i18nObject *i18n.Bundle) error {
|
|||||||
}, &i18n.Message{
|
}, &i18n.Message{
|
||||||
ID: "StashTitle",
|
ID: "StashTitle",
|
||||||
Other: "Stash",
|
Other: "Stash",
|
||||||
|
}, &i18n.Message{
|
||||||
|
ID: "StagingMainTitle",
|
||||||
|
Other: `Stage Lines/Hunks`,
|
||||||
|
}, &i18n.Message{
|
||||||
|
ID: "MergingMainTitle",
|
||||||
|
Other: "Resolve merge conflicts",
|
||||||
}, &i18n.Message{
|
}, &i18n.Message{
|
||||||
ID: "CommitMessage",
|
ID: "CommitMessage",
|
||||||
Other: "Commit bericht",
|
Other: "Commit bericht",
|
||||||
@ -186,7 +195,7 @@ func addDutch(i18nObject *i18n.Bundle) error {
|
|||||||
Other: "rebase branch",
|
Other: "rebase branch",
|
||||||
}, &i18n.Message{
|
}, &i18n.Message{
|
||||||
ID: "CantRebaseOntoSelf",
|
ID: "CantRebaseOntoSelf",
|
||||||
Other: "It is not possible to rebase the branch onto itself!",
|
Other: "You cannot rebase a branch onto itself",
|
||||||
}, &i18n.Message{
|
}, &i18n.Message{
|
||||||
ID: "CantMergeBranchIntoItself",
|
ID: "CantMergeBranchIntoItself",
|
||||||
Other: "Je kan niet een branch in zichzelf mergen",
|
Other: "Je kan niet een branch in zichzelf mergen",
|
||||||
@ -331,9 +340,6 @@ func addDutch(i18nObject *i18n.Bundle) error {
|
|||||||
}, &i18n.Message{
|
}, &i18n.Message{
|
||||||
ID: "NoViewMachingNewLineFocusedSwitchStatement",
|
ID: "NoViewMachingNewLineFocusedSwitchStatement",
|
||||||
Other: "Er machen geen weergave met de newLineFocused switch declaratie",
|
Other: "Er machen geen weergave met de newLineFocused switch declaratie",
|
||||||
}, &i18n.Message{
|
|
||||||
ID: "settingPreviewsViewTo",
|
|
||||||
Other: "vorige weergave instellen op: {{.oldViewName}}",
|
|
||||||
}, &i18n.Message{
|
}, &i18n.Message{
|
||||||
ID: "newFocusedViewIs",
|
ID: "newFocusedViewIs",
|
||||||
Other: "nieuw gefocussed weergave is {{.newFocusedView}}",
|
Other: "nieuw gefocussed weergave is {{.newFocusedView}}",
|
||||||
@ -438,7 +444,7 @@ func addDutch(i18nObject *i18n.Bundle) error {
|
|||||||
Other: `Kan alleen individuele lijnen stagen van getrackte bestanden met onstaged veranderingen`,
|
Other: `Kan alleen individuele lijnen stagen van getrackte bestanden met onstaged veranderingen`,
|
||||||
}, &i18n.Message{
|
}, &i18n.Message{
|
||||||
ID: "StagingTitle",
|
ID: "StagingTitle",
|
||||||
Other: `Staging`,
|
Other: `Stage Lines/Hunks`,
|
||||||
}, &i18n.Message{
|
}, &i18n.Message{
|
||||||
ID: "StageHunk",
|
ID: "StageHunk",
|
||||||
Other: `stage hunk`,
|
Other: `stage hunk`,
|
||||||
@ -454,6 +460,24 @@ func addDutch(i18nObject *i18n.Bundle) error {
|
|||||||
}, &i18n.Message{
|
}, &i18n.Message{
|
||||||
ID: "CantFindHunk",
|
ID: "CantFindHunk",
|
||||||
Other: `Kan geen hunk vinden`,
|
Other: `Kan geen hunk vinden`,
|
||||||
|
}, &i18n.Message{
|
||||||
|
ID: "RebasingTitle",
|
||||||
|
Other: "Rebasing",
|
||||||
|
}, &i18n.Message{
|
||||||
|
ID: "MergingTitle",
|
||||||
|
Other: "Merging",
|
||||||
|
}, &i18n.Message{
|
||||||
|
ID: "ConfirmRebase",
|
||||||
|
Other: "Are you sure you want to rebase {{.checkedOutBranch}} onto {{.selectedBranch}}?",
|
||||||
|
}, &i18n.Message{
|
||||||
|
ID: "ConfirmMerge",
|
||||||
|
Other: "Are you sure you want to merge {{.selectedBranch}} into {{.checkedOutBranch}}?",
|
||||||
|
}, &i18n.Message{}, &i18n.Message{
|
||||||
|
ID: "FwdNoUpstream",
|
||||||
|
Other: "Cannot fast-forward a branch with no upstream",
|
||||||
|
}, &i18n.Message{
|
||||||
|
ID: "FwdCommitsToPush",
|
||||||
|
Other: "Cannot fast-forward a branch with commits to push",
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,9 @@ func addEnglish(i18nObject *i18n.Bundle) error {
|
|||||||
}, &i18n.Message{
|
}, &i18n.Message{
|
||||||
ID: "DiffTitle",
|
ID: "DiffTitle",
|
||||||
Other: "Diff",
|
Other: "Diff",
|
||||||
|
}, &i18n.Message{
|
||||||
|
ID: "LogTitle",
|
||||||
|
Other: "Log",
|
||||||
}, &i18n.Message{
|
}, &i18n.Message{
|
||||||
ID: "FilesTitle",
|
ID: "FilesTitle",
|
||||||
Other: "Files",
|
Other: "Files",
|
||||||
@ -36,6 +39,12 @@ func addEnglish(i18nObject *i18n.Bundle) error {
|
|||||||
}, &i18n.Message{
|
}, &i18n.Message{
|
||||||
ID: "StashTitle",
|
ID: "StashTitle",
|
||||||
Other: "Stash",
|
Other: "Stash",
|
||||||
|
}, &i18n.Message{
|
||||||
|
ID: "StagingMainTitle",
|
||||||
|
Other: `Stage Lines/Hunks`,
|
||||||
|
}, &i18n.Message{
|
||||||
|
ID: "MergingMainTitle",
|
||||||
|
Other: "Resolve merge conflicts",
|
||||||
}, &i18n.Message{
|
}, &i18n.Message{
|
||||||
ID: "CommitMessage",
|
ID: "CommitMessage",
|
||||||
Other: "Commit message",
|
Other: "Commit message",
|
||||||
@ -194,7 +203,7 @@ func addEnglish(i18nObject *i18n.Bundle) error {
|
|||||||
Other: "rebase branch",
|
Other: "rebase branch",
|
||||||
}, &i18n.Message{
|
}, &i18n.Message{
|
||||||
ID: "CantRebaseOntoSelf",
|
ID: "CantRebaseOntoSelf",
|
||||||
Other: "It is not possible to rebase the branch onto itself!",
|
Other: "You cannot rebase a branch onto itself",
|
||||||
}, &i18n.Message{
|
}, &i18n.Message{
|
||||||
ID: "CantMergeBranchIntoItself",
|
ID: "CantMergeBranchIntoItself",
|
||||||
Other: "You cannot merge a branch into itself",
|
Other: "You cannot merge a branch into itself",
|
||||||
@ -339,9 +348,6 @@ func addEnglish(i18nObject *i18n.Bundle) error {
|
|||||||
}, &i18n.Message{
|
}, &i18n.Message{
|
||||||
ID: "NoViewMachingNewLineFocusedSwitchStatement",
|
ID: "NoViewMachingNewLineFocusedSwitchStatement",
|
||||||
Other: "No view matching newLineFocused switch statement",
|
Other: "No view matching newLineFocused switch statement",
|
||||||
}, &i18n.Message{
|
|
||||||
ID: "settingPreviewsViewTo",
|
|
||||||
Other: "setting previous view to: {{.oldViewName}}",
|
|
||||||
}, &i18n.Message{
|
}, &i18n.Message{
|
||||||
ID: "newFocusedViewIs",
|
ID: "newFocusedViewIs",
|
||||||
Other: "new focused view is {{.newFocusedView}}",
|
Other: "new focused view is {{.newFocusedView}}",
|
||||||
@ -444,9 +450,6 @@ func addEnglish(i18nObject *i18n.Bundle) error {
|
|||||||
}, &i18n.Message{
|
}, &i18n.Message{
|
||||||
ID: "FileStagingRequirements",
|
ID: "FileStagingRequirements",
|
||||||
Other: `Can only stage individual lines for tracked files with unstaged changes`,
|
Other: `Can only stage individual lines for tracked files with unstaged changes`,
|
||||||
}, &i18n.Message{
|
|
||||||
ID: "StagingTitle",
|
|
||||||
Other: `Staging`,
|
|
||||||
}, &i18n.Message{
|
}, &i18n.Message{
|
||||||
ID: "StageHunk",
|
ID: "StageHunk",
|
||||||
Other: `stage hunk`,
|
Other: `stage hunk`,
|
||||||
@ -468,12 +471,12 @@ func addEnglish(i18nObject *i18n.Bundle) error {
|
|||||||
}, &i18n.Message{
|
}, &i18n.Message{
|
||||||
ID: "Fetching",
|
ID: "Fetching",
|
||||||
Other: "fetching and fast-forwarding {{.from}} -> {{.to}} ...",
|
Other: "fetching and fast-forwarding {{.from}} -> {{.to}} ...",
|
||||||
}, &i18n.Message{
|
|
||||||
ID: "MergingTitle",
|
|
||||||
Other: "Resolve merge conflicts",
|
|
||||||
}, &i18n.Message{
|
}, &i18n.Message{
|
||||||
ID: "FoundConflicts",
|
ID: "FoundConflicts",
|
||||||
Other: "Damn, conflicts! To abort press 'esc', otherwise press 'enter'",
|
Other: "Damn, conflicts! To abort press 'esc', otherwise press 'enter'",
|
||||||
|
}, &i18n.Message{
|
||||||
|
ID: "FoundConflictsTitle",
|
||||||
|
Other: "Auto-merge failed",
|
||||||
}, &i18n.Message{
|
}, &i18n.Message{
|
||||||
ID: "Undo",
|
ID: "Undo",
|
||||||
Other: "undo",
|
Other: "undo",
|
||||||
@ -501,6 +504,24 @@ func addEnglish(i18nObject *i18n.Bundle) error {
|
|||||||
}, &i18n.Message{
|
}, &i18n.Message{
|
||||||
ID: "ConflictsResolved",
|
ID: "ConflictsResolved",
|
||||||
Other: "all merge conflicts resolved. Continue?",
|
Other: "all merge conflicts resolved. Continue?",
|
||||||
|
}, &i18n.Message{
|
||||||
|
ID: "RebasingTitle",
|
||||||
|
Other: "Rebasing",
|
||||||
|
}, &i18n.Message{
|
||||||
|
ID: "MergingTitle",
|
||||||
|
Other: "Merging",
|
||||||
|
}, &i18n.Message{
|
||||||
|
ID: "ConfirmRebase",
|
||||||
|
Other: "Are you sure you want to rebase {{.checkedOutBranch}} onto {{.selectedBranch}}?",
|
||||||
|
}, &i18n.Message{
|
||||||
|
ID: "ConfirmMerge",
|
||||||
|
Other: "Are you sure you want to merge {{.selectedBranch}} into {{.checkedOutBranch}}?",
|
||||||
|
}, &i18n.Message{}, &i18n.Message{
|
||||||
|
ID: "FwdNoUpstream",
|
||||||
|
Other: "Cannot fast-forward a branch with no upstream",
|
||||||
|
}, &i18n.Message{
|
||||||
|
ID: "FwdCommitsToPush",
|
||||||
|
Other: "Cannot fast-forward a branch with commits to push",
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,9 @@ func addPolish(i18nObject *i18n.Bundle) error {
|
|||||||
}, &i18n.Message{
|
}, &i18n.Message{
|
||||||
ID: "DiffTitle",
|
ID: "DiffTitle",
|
||||||
Other: "Różnice",
|
Other: "Różnice",
|
||||||
|
}, &i18n.Message{
|
||||||
|
ID: "LogTitle",
|
||||||
|
Other: "Log",
|
||||||
}, &i18n.Message{
|
}, &i18n.Message{
|
||||||
ID: "FilesTitle",
|
ID: "FilesTitle",
|
||||||
Other: "Pliki",
|
Other: "Pliki",
|
||||||
@ -26,6 +29,12 @@ func addPolish(i18nObject *i18n.Bundle) error {
|
|||||||
}, &i18n.Message{
|
}, &i18n.Message{
|
||||||
ID: "StashTitle",
|
ID: "StashTitle",
|
||||||
Other: "Schowek",
|
Other: "Schowek",
|
||||||
|
}, &i18n.Message{
|
||||||
|
ID: "StagingMainTitle",
|
||||||
|
Other: `Stage Lines/Hunks`,
|
||||||
|
}, &i18n.Message{
|
||||||
|
ID: "MergingMainTitle",
|
||||||
|
Other: "Resolve merge conflicts",
|
||||||
}, &i18n.Message{
|
}, &i18n.Message{
|
||||||
ID: "CommitMessage",
|
ID: "CommitMessage",
|
||||||
Other: "Wiadomość commita",
|
Other: "Wiadomość commita",
|
||||||
@ -175,7 +184,7 @@ func addPolish(i18nObject *i18n.Bundle) error {
|
|||||||
Other: "rebase branch",
|
Other: "rebase branch",
|
||||||
}, &i18n.Message{
|
}, &i18n.Message{
|
||||||
ID: "CantRebaseOntoSelf",
|
ID: "CantRebaseOntoSelf",
|
||||||
Other: "It is not possible to rebase the branch onto itself!",
|
Other: "You cannot rebase a branch onto itself",
|
||||||
}, &i18n.Message{
|
}, &i18n.Message{
|
||||||
ID: "CantMergeBranchIntoItself",
|
ID: "CantMergeBranchIntoItself",
|
||||||
Other: "Nie możesz scalić gałęzi do samej siebie",
|
Other: "Nie możesz scalić gałęzi do samej siebie",
|
||||||
@ -320,9 +329,6 @@ func addPolish(i18nObject *i18n.Bundle) error {
|
|||||||
}, &i18n.Message{
|
}, &i18n.Message{
|
||||||
ID: "NoViewMachingNewLineFocusedSwitchStatement",
|
ID: "NoViewMachingNewLineFocusedSwitchStatement",
|
||||||
Other: "Brak widoku pasującego do instrukcji przełączania newLineFocused",
|
Other: "Brak widoku pasującego do instrukcji przełączania newLineFocused",
|
||||||
}, &i18n.Message{
|
|
||||||
ID: "settingPreviewsViewTo",
|
|
||||||
Other: "ustawianie poprzedniego widoku na: {{.oldViewName}}",
|
|
||||||
}, &i18n.Message{
|
}, &i18n.Message{
|
||||||
ID: "newFocusedViewIs",
|
ID: "newFocusedViewIs",
|
||||||
Other: "nowy skupiony widok to {{.newFocusedView}}",
|
Other: "nowy skupiony widok to {{.newFocusedView}}",
|
||||||
@ -437,6 +443,24 @@ func addPolish(i18nObject *i18n.Bundle) error {
|
|||||||
}, &i18n.Message{
|
}, &i18n.Message{
|
||||||
ID: "CantFindHunk",
|
ID: "CantFindHunk",
|
||||||
Other: `Nie można znaleźć kawałka`,
|
Other: `Nie można znaleźć kawałka`,
|
||||||
|
}, &i18n.Message{
|
||||||
|
ID: "RebasingTitle",
|
||||||
|
Other: "Rebasing",
|
||||||
|
}, &i18n.Message{
|
||||||
|
ID: "MergingTitle",
|
||||||
|
Other: "Merging",
|
||||||
|
}, &i18n.Message{
|
||||||
|
ID: "ConfirmRebase",
|
||||||
|
Other: "Are you sure you want to rebase {{.checkedOutBranch}} onto {{.selectedBranch}}?",
|
||||||
|
}, &i18n.Message{
|
||||||
|
ID: "ConfirmMerge",
|
||||||
|
Other: "Are you sure you want to merge {{.selectedBranch}} into {{.checkedOutBranch}}?",
|
||||||
|
}, &i18n.Message{}, &i18n.Message{
|
||||||
|
ID: "FwdNoUpstream",
|
||||||
|
Other: "Cannot fast-forward a branch with no upstream",
|
||||||
|
}, &i18n.Message{
|
||||||
|
ID: "FwdCommitsToPush",
|
||||||
|
Other: "Cannot fast-forward a branch with commits to push",
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user