2018-08-14 11:05:26 +02:00
|
|
|
package gui
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
|
|
|
// "io"
|
|
|
|
// "io/ioutil"
|
|
|
|
|
|
|
|
// "strings"
|
|
|
|
|
2018-09-12 10:23:25 +02:00
|
|
|
"fmt"
|
2018-08-14 11:05:26 +02:00
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/jesseduffield/gocui"
|
|
|
|
"github.com/jesseduffield/lazygit/pkg/commands"
|
2018-09-17 13:02:30 +02:00
|
|
|
"github.com/jesseduffield/lazygit/pkg/utils"
|
2018-08-14 11:05:26 +02:00
|
|
|
)
|
|
|
|
|
2018-12-06 13:18:17 +02:00
|
|
|
// list panel functions
|
|
|
|
|
|
|
|
func (gui *Gui) getSelectedFile(g *gocui.Gui) (*commands.File, error) {
|
|
|
|
selectedLine := gui.State.Panels.Files.SelectedLine
|
|
|
|
if selectedLine == -1 {
|
|
|
|
return &commands.File{}, gui.Errors.ErrNoFiles
|
|
|
|
}
|
|
|
|
|
|
|
|
return gui.State.Files[selectedLine], nil
|
|
|
|
}
|
|
|
|
|
2019-01-15 11:12:31 +02:00
|
|
|
func (gui *Gui) handleFileSelect(g *gocui.Gui, v *gocui.View, alreadySelected bool) error {
|
2018-12-06 13:18:17 +02:00
|
|
|
file, err := gui.getSelectedFile(g)
|
|
|
|
if err != nil {
|
|
|
|
if err != gui.Errors.ErrNoFiles {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return gui.renderString(g, "main", gui.Tr.SLocalize("NoChangedFiles"))
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := gui.focusPoint(0, gui.State.Panels.Files.SelectedLine, v); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-12-08 07:54:54 +02:00
|
|
|
if file.HasMergeConflicts {
|
2019-02-16 03:07:27 +02:00
|
|
|
return gui.refreshMergePanel()
|
2018-12-08 07:54:54 +02:00
|
|
|
} else {
|
2019-02-16 03:07:27 +02:00
|
|
|
// TODO: set title appropriately
|
|
|
|
// if _, err := gui.g.SetViewOnBottom("merging"); err != nil {
|
|
|
|
// return err
|
|
|
|
// }
|
2018-12-08 07:54:54 +02:00
|
|
|
}
|
|
|
|
|
2018-12-06 13:18:17 +02:00
|
|
|
content := gui.GitCommand.Diff(file, false)
|
2019-01-15 11:12:31 +02:00
|
|
|
if alreadySelected {
|
|
|
|
g.Update(func(*gocui.Gui) error {
|
2019-02-11 12:07:12 +02:00
|
|
|
return gui.setViewContent(gui.g, gui.getMainView(), content)
|
2019-01-15 11:12:31 +02:00
|
|
|
})
|
|
|
|
return nil
|
|
|
|
}
|
2018-12-06 13:18:17 +02:00
|
|
|
return gui.renderString(g, "main", content)
|
|
|
|
}
|
|
|
|
|
2018-12-08 07:54:54 +02:00
|
|
|
func (gui *Gui) refreshFiles() error {
|
2019-01-15 11:12:31 +02:00
|
|
|
selectedFile, _ := gui.getSelectedFile(gui.g)
|
|
|
|
|
2018-12-08 07:54:54 +02:00
|
|
|
filesView := gui.getFilesView()
|
2018-12-06 13:18:17 +02:00
|
|
|
gui.refreshStateFiles()
|
|
|
|
|
|
|
|
gui.g.Update(func(g *gocui.Gui) error {
|
|
|
|
|
|
|
|
filesView.Clear()
|
2019-02-16 06:17:44 +02:00
|
|
|
isFocused := gui.g.CurrentView().Name() == "files"
|
|
|
|
list, err := utils.RenderList(gui.State.Files, isFocused)
|
2018-12-06 13:18:17 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
fmt.Fprint(filesView, list)
|
|
|
|
|
|
|
|
if filesView == g.CurrentView() {
|
2019-01-15 11:12:31 +02:00
|
|
|
newSelectedFile, _ := gui.getSelectedFile(gui.g)
|
|
|
|
alreadySelected := newSelectedFile.Name == selectedFile.Name
|
|
|
|
return gui.handleFileSelect(g, filesView, alreadySelected)
|
2018-12-06 13:18:17 +02:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (gui *Gui) handleFilesNextLine(g *gocui.Gui, v *gocui.View) error {
|
|
|
|
panelState := gui.State.Panels.Files
|
|
|
|
gui.changeSelectedLine(&panelState.SelectedLine, len(gui.State.Files), false)
|
|
|
|
|
2019-01-15 11:12:31 +02:00
|
|
|
return gui.handleFileSelect(gui.g, v, false)
|
2018-12-06 13:18:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (gui *Gui) handleFilesPrevLine(g *gocui.Gui, v *gocui.View) error {
|
|
|
|
panelState := gui.State.Panels.Files
|
|
|
|
gui.changeSelectedLine(&panelState.SelectedLine, len(gui.State.Files), true)
|
|
|
|
|
2019-01-15 11:12:31 +02:00
|
|
|
return gui.handleFileSelect(gui.g, v, false)
|
2018-12-06 13:18:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// specific functions
|
|
|
|
|
2018-09-17 13:02:30 +02:00
|
|
|
func (gui *Gui) stagedFiles() []*commands.File {
|
2018-08-14 11:05:26 +02:00
|
|
|
files := gui.State.Files
|
2018-09-17 13:02:30 +02:00
|
|
|
result := make([]*commands.File, 0)
|
2018-08-14 11:05:26 +02:00
|
|
|
for _, file := range files {
|
|
|
|
if file.HasStagedChanges {
|
|
|
|
result = append(result, file)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
2018-09-17 13:02:30 +02:00
|
|
|
func (gui *Gui) trackedFiles() []*commands.File {
|
2018-08-14 11:05:26 +02:00
|
|
|
files := gui.State.Files
|
2018-09-17 13:02:30 +02:00
|
|
|
result := make([]*commands.File, 0)
|
2018-08-14 11:05:26 +02:00
|
|
|
for _, file := range files {
|
|
|
|
if file.Tracked {
|
|
|
|
result = append(result, file)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
|
|
|
func (gui *Gui) stageSelectedFile(g *gocui.Gui) error {
|
|
|
|
file, err := gui.getSelectedFile(g)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return gui.GitCommand.StageFile(file.Name)
|
|
|
|
}
|
|
|
|
|
2018-12-05 13:30:10 +02:00
|
|
|
func (gui *Gui) handleEnterFile(g *gocui.Gui, v *gocui.View) error {
|
2018-12-02 10:57:01 +02:00
|
|
|
file, err := gui.getSelectedFile(g)
|
|
|
|
if err != nil {
|
|
|
|
if err != gui.Errors.ErrNoFiles {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
2018-12-05 13:30:10 +02:00
|
|
|
if file.HasMergeConflicts {
|
|
|
|
return gui.handleSwitchToMerge(g, v)
|
|
|
|
}
|
2018-12-05 10:33:46 +02:00
|
|
|
if !file.HasUnstagedChanges {
|
2018-12-02 10:57:01 +02:00
|
|
|
return gui.createErrorPanel(g, gui.Tr.SLocalize("FileStagingRequirements"))
|
|
|
|
}
|
2019-02-16 03:07:27 +02:00
|
|
|
if err := gui.changeContext("main", "staging"); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := gui.switchFocus(g, v, gui.getMainView()); err != nil {
|
2018-12-05 10:33:46 +02:00
|
|
|
return err
|
|
|
|
}
|
2018-12-02 10:57:01 +02:00
|
|
|
return gui.refreshStagingPanel()
|
|
|
|
}
|
|
|
|
|
2018-08-14 11:05:26 +02:00
|
|
|
func (gui *Gui) handleFilePress(g *gocui.Gui, v *gocui.View) error {
|
|
|
|
file, err := gui.getSelectedFile(g)
|
|
|
|
if err != nil {
|
2018-08-14 15:47:14 +02:00
|
|
|
if err == gui.Errors.ErrNoFiles {
|
2018-08-14 11:05:26 +02:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if file.HasMergeConflicts {
|
|
|
|
return gui.handleSwitchToMerge(g, v)
|
|
|
|
}
|
|
|
|
|
|
|
|
if file.HasUnstagedChanges {
|
|
|
|
gui.GitCommand.StageFile(file.Name)
|
|
|
|
} else {
|
|
|
|
gui.GitCommand.UnStageFile(file.Name, file.Tracked)
|
|
|
|
}
|
|
|
|
|
2018-12-08 07:54:54 +02:00
|
|
|
if err := gui.refreshFiles(); err != nil {
|
2018-08-14 11:05:26 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-01-15 11:12:31 +02:00
|
|
|
return gui.handleFileSelect(g, v, true)
|
2018-08-14 11:05:26 +02:00
|
|
|
}
|
|
|
|
|
2018-08-25 00:51:47 +02:00
|
|
|
func (gui *Gui) allFilesStaged() bool {
|
|
|
|
for _, file := range gui.State.Files {
|
|
|
|
if file.HasUnstagedChanges {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
func (gui *Gui) handleStageAll(g *gocui.Gui, v *gocui.View) error {
|
|
|
|
var err error
|
|
|
|
if gui.allFilesStaged() {
|
|
|
|
err = gui.GitCommand.UnstageAll()
|
|
|
|
} else {
|
|
|
|
err = gui.GitCommand.StageAll()
|
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
_ = gui.createErrorPanel(g, err.Error())
|
|
|
|
}
|
|
|
|
|
2018-12-08 07:54:54 +02:00
|
|
|
if err := gui.refreshFiles(); err != nil {
|
2018-08-25 00:51:47 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-02-11 12:07:12 +02:00
|
|
|
return gui.handleFileSelect(g, v, false)
|
2018-08-25 00:51:47 +02:00
|
|
|
}
|
|
|
|
|
2018-08-14 11:05:26 +02:00
|
|
|
func (gui *Gui) handleAddPatch(g *gocui.Gui, v *gocui.View) error {
|
|
|
|
file, err := gui.getSelectedFile(g)
|
|
|
|
if err != nil {
|
2018-08-14 15:47:14 +02:00
|
|
|
if err == gui.Errors.ErrNoFiles {
|
2018-08-14 11:05:26 +02:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if !file.HasUnstagedChanges {
|
2018-08-16 07:16:32 +02:00
|
|
|
return gui.createErrorPanel(g, gui.Tr.SLocalize("FileHasNoUnstagedChanges"))
|
2018-08-14 11:05:26 +02:00
|
|
|
}
|
|
|
|
if !file.Tracked {
|
2018-08-16 07:16:32 +02:00
|
|
|
return gui.createErrorPanel(g, gui.Tr.SLocalize("CannotGitAdd"))
|
2018-08-14 11:05:26 +02:00
|
|
|
}
|
2018-08-21 22:33:25 +02:00
|
|
|
|
|
|
|
gui.SubProcess = gui.GitCommand.AddPatch(file.Name)
|
2018-08-16 11:31:03 +02:00
|
|
|
return gui.Errors.ErrSubProcess
|
2018-08-14 11:05:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (gui *Gui) handleFileRemove(g *gocui.Gui, v *gocui.View) error {
|
|
|
|
file, err := gui.getSelectedFile(g)
|
|
|
|
if err != nil {
|
2018-08-14 15:47:14 +02:00
|
|
|
if err == gui.Errors.ErrNoFiles {
|
2018-08-14 11:05:26 +02:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
var deleteVerb string
|
|
|
|
if file.Tracked {
|
2018-08-16 07:16:32 +02:00
|
|
|
deleteVerb = gui.Tr.SLocalize("checkout")
|
2018-08-14 11:05:26 +02:00
|
|
|
} else {
|
2018-08-16 07:16:32 +02:00
|
|
|
deleteVerb = gui.Tr.SLocalize("delete")
|
2018-08-14 21:06:50 +02:00
|
|
|
}
|
|
|
|
message := gui.Tr.TemplateLocalize(
|
|
|
|
"SureTo",
|
2018-08-16 11:31:03 +02:00
|
|
|
Teml{
|
2018-08-14 21:06:50 +02:00
|
|
|
"deleteVerb": deleteVerb,
|
|
|
|
"fileName": file.Name,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
return gui.createConfirmationPanel(g, v, strings.Title(deleteVerb)+" file", message, func(g *gocui.Gui, v *gocui.View) error {
|
2018-08-14 11:05:26 +02:00
|
|
|
if err := gui.GitCommand.RemoveFile(file); err != nil {
|
2018-08-18 12:14:44 +02:00
|
|
|
return err
|
2018-08-14 11:05:26 +02:00
|
|
|
}
|
2018-12-08 07:54:54 +02:00
|
|
|
return gui.refreshFiles()
|
2018-08-14 11:05:26 +02:00
|
|
|
}, nil)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (gui *Gui) handleIgnoreFile(g *gocui.Gui, v *gocui.View) error {
|
|
|
|
file, err := gui.getSelectedFile(g)
|
|
|
|
if err != nil {
|
|
|
|
return gui.createErrorPanel(g, err.Error())
|
|
|
|
}
|
|
|
|
if file.Tracked {
|
2018-08-16 07:16:32 +02:00
|
|
|
return gui.createErrorPanel(g, gui.Tr.SLocalize("CantIgnoreTrackFiles"))
|
2018-08-14 11:05:26 +02:00
|
|
|
}
|
2018-08-19 12:41:04 +02:00
|
|
|
if err := gui.GitCommand.Ignore(file.Name); err != nil {
|
|
|
|
return gui.createErrorPanel(g, err.Error())
|
|
|
|
}
|
2018-12-08 07:54:54 +02:00
|
|
|
return gui.refreshFiles()
|
2018-08-14 11:05:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (gui *Gui) handleCommitPress(g *gocui.Gui, filesView *gocui.View) error {
|
2018-12-05 13:30:10 +02:00
|
|
|
if len(gui.stagedFiles()) == 0 && gui.State.WorkingTreeState == "normal" {
|
2018-08-16 07:16:32 +02:00
|
|
|
return gui.createErrorPanel(g, gui.Tr.SLocalize("NoStagedFilesToCommit"))
|
2018-08-14 11:05:26 +02:00
|
|
|
}
|
2018-12-08 07:54:54 +02:00
|
|
|
commitMessageView := gui.getCommitMessageView()
|
2018-09-12 15:20:35 +02:00
|
|
|
g.Update(func(g *gocui.Gui) error {
|
|
|
|
g.SetViewOnTop("commitMessage")
|
|
|
|
gui.switchFocus(g, filesView, commitMessageView)
|
|
|
|
gui.RenderCommitLength()
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (gui *Gui) handleAmendCommitPress(g *gocui.Gui, filesView *gocui.View) error {
|
2018-12-05 13:30:10 +02:00
|
|
|
if len(gui.stagedFiles()) == 0 && gui.State.WorkingTreeState == "normal" {
|
2018-09-12 15:20:35 +02:00
|
|
|
return gui.createErrorPanel(g, gui.Tr.SLocalize("NoStagedFilesToCommit"))
|
|
|
|
}
|
2018-09-25 22:11:51 +02:00
|
|
|
title := strings.Title(gui.Tr.SLocalize("AmendLastCommit"))
|
|
|
|
question := gui.Tr.SLocalize("SureToAmend")
|
2018-10-08 21:19:45 +02:00
|
|
|
|
|
|
|
if len(gui.State.Commits) == 0 {
|
|
|
|
return gui.createErrorPanel(g, gui.Tr.SLocalize("NoCommitToAmend"))
|
|
|
|
}
|
|
|
|
|
2018-09-25 22:11:51 +02:00
|
|
|
return gui.createConfirmationPanel(g, filesView, title, question, func(g *gocui.Gui, v *gocui.View) error {
|
|
|
|
lastCommitMsg := gui.State.Commits[0].Name
|
|
|
|
_, err := gui.GitCommand.Commit(lastCommitMsg, true)
|
|
|
|
if err != nil {
|
2018-10-08 22:19:42 +02:00
|
|
|
return gui.createErrorPanel(g, err.Error())
|
2018-09-25 22:11:51 +02:00
|
|
|
}
|
2018-09-12 15:20:35 +02:00
|
|
|
|
2018-10-06 07:40:12 +02:00
|
|
|
return gui.refreshSidePanels(g)
|
2018-09-25 22:11:51 +02:00
|
|
|
}, nil)
|
2018-08-14 11:05:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// handleCommitEditorPress - handle when the user wants to commit changes via
|
|
|
|
// their editor rather than via the popup panel
|
|
|
|
func (gui *Gui) handleCommitEditorPress(g *gocui.Gui, filesView *gocui.View) error {
|
2018-12-05 13:30:10 +02:00
|
|
|
if len(gui.stagedFiles()) == 0 && gui.State.WorkingTreeState == "normal" {
|
2018-08-16 07:16:32 +02:00
|
|
|
return gui.createErrorPanel(g, gui.Tr.SLocalize("NoStagedFilesToCommit"))
|
2018-08-14 11:05:26 +02:00
|
|
|
}
|
|
|
|
gui.PrepareSubProcess(g, "git", "commit")
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// PrepareSubProcess - prepare a subprocess for execution and tell the gui to switch to it
|
2018-08-21 22:33:25 +02:00
|
|
|
func (gui *Gui) PrepareSubProcess(g *gocui.Gui, commands ...string) {
|
|
|
|
gui.SubProcess = gui.GitCommand.PrepareCommitSubProcess()
|
2018-08-14 11:05:26 +02:00
|
|
|
g.Update(func(g *gocui.Gui) error {
|
2018-08-16 11:31:03 +02:00
|
|
|
return gui.Errors.ErrSubProcess
|
2018-08-14 11:05:26 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-08-31 10:43:54 +02:00
|
|
|
func (gui *Gui) editFile(filename string) error {
|
|
|
|
sub, err := gui.OSCommand.EditFile(filename)
|
2018-08-14 11:05:26 +02:00
|
|
|
if err != nil {
|
2018-08-31 10:43:54 +02:00
|
|
|
return gui.createErrorPanel(gui.g, err.Error())
|
2018-08-14 11:05:26 +02:00
|
|
|
}
|
|
|
|
if sub != nil {
|
|
|
|
gui.SubProcess = sub
|
2018-08-16 11:31:03 +02:00
|
|
|
return gui.Errors.ErrSubProcess
|
2018-08-14 11:05:26 +02:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (gui *Gui) handleFileEdit(g *gocui.Gui, v *gocui.View) error {
|
2018-08-18 06:52:01 +02:00
|
|
|
file, err := gui.getSelectedFile(g)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-08-31 10:43:54 +02:00
|
|
|
|
|
|
|
return gui.editFile(file.Name)
|
2018-08-14 11:05:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (gui *Gui) handleFileOpen(g *gocui.Gui, v *gocui.View) error {
|
2018-08-18 06:52:01 +02:00
|
|
|
file, err := gui.getSelectedFile(g)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-08-23 21:05:09 +02:00
|
|
|
return gui.openFile(file.Name)
|
2018-08-14 11:05:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (gui *Gui) handleRefreshFiles(g *gocui.Gui, v *gocui.View) error {
|
2018-12-08 07:54:54 +02:00
|
|
|
return gui.refreshFiles()
|
2018-08-14 11:05:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (gui *Gui) refreshStateFiles() {
|
|
|
|
// get files to stage
|
|
|
|
files := gui.GitCommand.GetStatusFiles()
|
|
|
|
gui.State.Files = gui.GitCommand.MergeStatusFiles(gui.State.Files, files)
|
2018-12-04 10:50:11 +02:00
|
|
|
gui.refreshSelectedLine(&gui.State.Panels.Files.SelectedLine, len(gui.State.Files))
|
2018-12-05 13:30:10 +02:00
|
|
|
gui.updateWorkTreeState()
|
2018-08-14 11:05:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (gui *Gui) catSelectedFile(g *gocui.Gui) (string, error) {
|
|
|
|
item, err := gui.getSelectedFile(g)
|
|
|
|
if err != nil {
|
2018-08-14 15:47:14 +02:00
|
|
|
if err != gui.Errors.ErrNoFiles {
|
2018-08-14 11:05:26 +02:00
|
|
|
return "", err
|
|
|
|
}
|
2018-08-16 07:16:32 +02:00
|
|
|
return "", gui.renderString(g, "main", gui.Tr.SLocalize("NoFilesDisplay"))
|
2018-08-14 11:05:26 +02:00
|
|
|
}
|
2018-08-28 11:12:35 +02:00
|
|
|
if item.Type != "file" {
|
|
|
|
return "", gui.renderString(g, "main", gui.Tr.SLocalize("NotAFile"))
|
|
|
|
}
|
2018-08-14 11:05:26 +02:00
|
|
|
cat, err := gui.GitCommand.CatFile(item.Name)
|
|
|
|
if err != nil {
|
2018-08-28 11:12:35 +02:00
|
|
|
gui.Log.Error(err)
|
|
|
|
return "", gui.renderString(g, "main", err.Error())
|
2018-08-14 11:05:26 +02:00
|
|
|
}
|
|
|
|
return cat, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (gui *Gui) pullFiles(g *gocui.Gui, v *gocui.View) error {
|
2019-02-16 03:03:22 +02:00
|
|
|
if err := gui.createLoaderPanel(gui.g, v, gui.Tr.SLocalize("PullWait")); err != nil {
|
2018-11-02 10:54:54 +02:00
|
|
|
return err
|
|
|
|
}
|
2019-02-16 03:03:22 +02:00
|
|
|
|
2018-08-14 11:05:26 +02:00
|
|
|
go func() {
|
2018-11-02 10:54:54 +02:00
|
|
|
unamePassOpend := false
|
|
|
|
err := gui.GitCommand.Pull(func(passOrUname string) string {
|
|
|
|
unamePassOpend = true
|
|
|
|
return gui.waitForPassUname(g, v, passOrUname)
|
|
|
|
})
|
2018-12-10 09:22:52 +02:00
|
|
|
gui.HandleCredentialsPopup(g, unamePassOpend, err)
|
2018-08-14 11:05:26 +02:00
|
|
|
}()
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-11-02 10:54:54 +02:00
|
|
|
func (gui *Gui) pushWithForceFlag(g *gocui.Gui, v *gocui.View, force bool) error {
|
2019-02-16 03:03:22 +02:00
|
|
|
if err := gui.createLoaderPanel(gui.g, v, gui.Tr.SLocalize("PushWait")); err != nil {
|
2018-08-19 13:28:13 +02:00
|
|
|
return err
|
|
|
|
}
|
2018-08-14 11:05:26 +02:00
|
|
|
go func() {
|
2018-11-02 10:54:54 +02:00
|
|
|
unamePassOpend := false
|
2018-08-14 11:05:26 +02:00
|
|
|
branchName := gui.State.Branches[0].Name
|
2018-10-17 21:12:33 +02:00
|
|
|
err := gui.GitCommand.Push(branchName, force, func(passOrUname string) string {
|
2018-11-02 10:54:54 +02:00
|
|
|
unamePassOpend = true
|
|
|
|
return gui.waitForPassUname(g, v, passOrUname)
|
2018-10-17 21:12:33 +02:00
|
|
|
})
|
2018-12-10 09:22:52 +02:00
|
|
|
gui.HandleCredentialsPopup(g, unamePassOpend, err)
|
2018-08-14 11:05:26 +02:00
|
|
|
}()
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-08-19 13:28:13 +02:00
|
|
|
func (gui *Gui) pushFiles(g *gocui.Gui, v *gocui.View) error {
|
|
|
|
// if we have pullables we'll ask if the user wants to force push
|
2018-12-07 09:52:31 +02:00
|
|
|
_, pullables := gui.GitCommand.GetCurrentBranchUpstreamDifferenceCount()
|
2018-08-19 13:28:13 +02:00
|
|
|
if pullables == "?" || pullables == "0" {
|
2018-10-20 17:37:55 +02:00
|
|
|
return gui.pushWithForceFlag(g, v, false)
|
2018-08-19 13:28:13 +02:00
|
|
|
}
|
|
|
|
err := gui.createConfirmationPanel(g, nil, gui.Tr.SLocalize("ForcePush"), gui.Tr.SLocalize("ForcePushPrompt"), func(g *gocui.Gui, v *gocui.View) error {
|
2018-10-20 17:37:55 +02:00
|
|
|
return gui.pushWithForceFlag(g, v, true)
|
2018-08-19 13:28:13 +02:00
|
|
|
}, nil)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-08-14 11:05:26 +02:00
|
|
|
func (gui *Gui) handleSwitchToMerge(g *gocui.Gui, v *gocui.View) error {
|
|
|
|
file, err := gui.getSelectedFile(g)
|
|
|
|
if err != nil {
|
2018-08-14 15:47:14 +02:00
|
|
|
if err != gui.Errors.ErrNoFiles {
|
2018-08-14 11:05:26 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
if !file.HasMergeConflicts {
|
2018-08-16 07:16:32 +02:00
|
|
|
return gui.createErrorPanel(g, gui.Tr.SLocalize("FileNoMergeCons"))
|
2018-08-14 11:05:26 +02:00
|
|
|
}
|
2019-02-16 03:07:27 +02:00
|
|
|
if err := gui.changeContext("main", "merging"); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := gui.switchFocus(g, v, gui.getMainView()); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return gui.refreshMergePanel()
|
2018-08-14 11:05:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (gui *Gui) handleAbortMerge(g *gocui.Gui, v *gocui.View) error {
|
|
|
|
if err := gui.GitCommand.AbortMerge(); err != nil {
|
|
|
|
return gui.createErrorPanel(g, err.Error())
|
|
|
|
}
|
2018-08-16 07:16:32 +02:00
|
|
|
gui.createMessagePanel(g, v, "", gui.Tr.SLocalize("MergeAborted"))
|
2018-08-14 11:05:26 +02:00
|
|
|
gui.refreshStatus(g)
|
2018-12-08 07:54:54 +02:00
|
|
|
return gui.refreshFiles()
|
2018-08-14 11:05:26 +02:00
|
|
|
}
|
|
|
|
|
2018-12-05 11:06:47 +02:00
|
|
|
func (gui *Gui) handleResetAndClean(g *gocui.Gui, v *gocui.View) error {
|
2018-08-16 07:16:32 +02:00
|
|
|
return gui.createConfirmationPanel(g, v, gui.Tr.SLocalize("ClearFilePanel"), gui.Tr.SLocalize("SureResetHardHead"), func(g *gocui.Gui, v *gocui.View) error {
|
2018-12-05 11:06:47 +02:00
|
|
|
if err := gui.GitCommand.ResetAndClean(); err != nil {
|
2018-08-14 11:05:26 +02:00
|
|
|
gui.createErrorPanel(g, err.Error())
|
|
|
|
}
|
2018-12-08 07:54:54 +02:00
|
|
|
return gui.refreshFiles()
|
2018-08-14 11:05:26 +02:00
|
|
|
}, nil)
|
|
|
|
}
|
2018-08-23 21:05:09 +02:00
|
|
|
|
|
|
|
func (gui *Gui) openFile(filename string) error {
|
|
|
|
if err := gui.OSCommand.OpenFile(filename); err != nil {
|
|
|
|
return gui.createErrorPanel(gui.g, err.Error())
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
2018-12-08 07:54:54 +02:00
|
|
|
|
|
|
|
func (gui *Gui) anyFilesWithMergeConflicts() bool {
|
|
|
|
for _, file := range gui.State.Files {
|
|
|
|
if file.HasMergeConflicts {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
2019-02-19 14:36:29 +02:00
|
|
|
|
|
|
|
func (gui *Gui) handleSoftReset(g *gocui.Gui, v *gocui.View) error {
|
|
|
|
return gui.createConfirmationPanel(g, v, gui.Tr.SLocalize("SoftReset"), gui.Tr.SLocalize("ConfirmSoftReset"), func(g *gocui.Gui, v *gocui.View) error {
|
|
|
|
if err := gui.GitCommand.SoftReset("HEAD^"); err != nil {
|
|
|
|
return gui.createErrorPanel(g, err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := gui.refreshCommits(gui.g); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return gui.refreshFiles()
|
|
|
|
}, nil)
|
|
|
|
}
|