appease golangci

This commit is contained in:
Jesse Duffield 2019-03-02 13:22:02 +11:00
parent 4de31da4be
commit 1337f6e76a
6 changed files with 32 additions and 13 deletions

View file

@ -128,7 +128,10 @@ func (app *App) Rebase() error {
app.Log.Info("args: ", os.Args) app.Log.Info("args: ", os.Args)
if strings.HasSuffix(os.Args[1], "git-rebase-todo") { if strings.HasSuffix(os.Args[1], "git-rebase-todo") {
ioutil.WriteFile(os.Args[1], []byte(os.Getenv("LAZYGIT_REBASE_TODO")), 0644) if err := ioutil.WriteFile(os.Args[1], []byte(os.Getenv("LAZYGIT_REBASE_TODO")), 0644); err != nil {
return err
}
} else if strings.HasSuffix(os.Args[1], ".git/COMMIT_EDITMSG") { } else if strings.HasSuffix(os.Args[1], ".git/COMMIT_EDITMSG") {
// if we are rebasing and squashing, we'll see a COMMIT_EDITMSG // if we are rebasing and squashing, we'll see a COMMIT_EDITMSG
// but in this case we don't need to edit it, so we'll just return // but in this case we don't need to edit it, so we'll just return

View file

@ -215,7 +215,7 @@ func (c *OSCommand) AppendLineToFile(filename, line string) error {
_, err = f.WriteString("\n" + line) _, err = f.WriteString("\n" + line)
if err != nil { if err != nil {
errors.Wrap(err, 0) return errors.Wrap(err, 0)
} }
return nil return nil
} }

View file

@ -22,6 +22,13 @@ func (gui *Gui) getSelectedBranch() *commands.Branch {
// may want to standardise how these select methods work // may want to standardise how these select methods work
func (gui *Gui) handleBranchSelect(g *gocui.Gui, v *gocui.View) error { func (gui *Gui) handleBranchSelect(g *gocui.Gui, v *gocui.View) error {
if gui.popupPanelFocused() {
return nil
}
if _, err := gui.g.SetCurrentView(v.Name()); err != nil {
return err
}
// This really shouldn't happen: there should always be a master branch // This really shouldn't happen: there should always be a master branch
if len(gui.State.Branches) == 0 { if len(gui.State.Branches) == 0 {
return gui.renderString(g, "main", gui.Tr.SLocalize("NoBranchesThisRepo")) return gui.renderString(g, "main", gui.Tr.SLocalize("NoBranchesThisRepo"))

View file

@ -49,8 +49,7 @@ func (gui *Gui) changeContext(viewName, context string) error {
} }
} }
gui.State.Contexts[viewName] = context gui.State.Contexts[viewName] = context
gui.setMainTitle() return gui.setMainTitle()
return nil
} }
func (gui *Gui) setInitialContexts() error { func (gui *Gui) setInitialContexts() error {

View file

@ -27,6 +27,10 @@ func (gui *Gui) getSelectedFile(g *gocui.Gui) (*commands.File, error) {
} }
func (gui *Gui) handleFileSelect(g *gocui.Gui, v *gocui.View, alreadySelected bool) error { func (gui *Gui) handleFileSelect(g *gocui.Gui, v *gocui.View, alreadySelected bool) error {
if _, err := gui.g.SetCurrentView(v.Name()); err != nil {
return err
}
file, err := gui.getSelectedFile(g) file, err := gui.getSelectedFile(g)
if err != nil { if err != nil {
if err != gui.Errors.ErrNoFiles { if err != gui.Errors.ErrNoFiles {
@ -41,11 +45,6 @@ func (gui *Gui) handleFileSelect(g *gocui.Gui, v *gocui.View, alreadySelected bo
if file.HasMergeConflicts { if file.HasMergeConflicts {
return gui.refreshMergePanel() return gui.refreshMergePanel()
} else {
// TODO: set title appropriately
// if _, err := gui.g.SetViewOnBottom("merging"); err != nil {
// return err
// }
} }
content := gui.GitCommand.Diff(file, false) content := gui.GitCommand.Diff(file, false)
@ -62,7 +61,9 @@ func (gui *Gui) refreshFiles() error {
selectedFile, _ := gui.getSelectedFile(gui.g) selectedFile, _ := gui.getSelectedFile(gui.g)
filesView := gui.getFilesView() filesView := gui.getFilesView()
gui.refreshStateFiles() if err := gui.refreshStateFiles(); err != nil {
return err
}
gui.g.Update(func(g *gocui.Gui) error { gui.g.Update(func(g *gocui.Gui) error {
@ -346,12 +347,12 @@ func (gui *Gui) handleRefreshFiles(g *gocui.Gui, v *gocui.View) error {
return gui.refreshFiles() return gui.refreshFiles()
} }
func (gui *Gui) refreshStateFiles() { func (gui *Gui) refreshStateFiles() error {
// get files to stage // get files to stage
files := gui.GitCommand.GetStatusFiles() files := gui.GitCommand.GetStatusFiles()
gui.State.Files = gui.GitCommand.MergeStatusFiles(gui.State.Files, files) gui.State.Files = gui.GitCommand.MergeStatusFiles(gui.State.Files, files)
gui.refreshSelectedLine(&gui.State.Panels.Files.SelectedLine, len(gui.State.Files)) gui.refreshSelectedLine(&gui.State.Panels.Files.SelectedLine, len(gui.State.Files))
gui.updateWorkTreeState() return gui.updateWorkTreeState()
} }
func (gui *Gui) catSelectedFile(g *gocui.Gui) (string, error) { func (gui *Gui) catSelectedFile(g *gocui.Gui) (string, error) {

View file

@ -248,6 +248,15 @@ func (gui *Gui) onFocusLost(v *gocui.View) error {
if err := gui.renderListPanel(gui.getBranchesView(), gui.State.Branches); err != nil { if err := gui.renderListPanel(gui.getBranchesView(), gui.State.Branches); err != nil {
return err return err
} }
} else if v.Name() == "main" {
// if we have lost focus to a popup panel, that's okay
if gui.popupPanelFocused() {
return nil
}
if err := gui.changeContext("main", "normal"); err != nil {
return err
}
} }
gui.Log.Info(v.Name() + " focus lost") gui.Log.Info(v.Name() + " focus lost")
return nil return nil
@ -521,7 +530,7 @@ func (gui *Gui) renderGlobalOptions() error {
func (gui *Gui) goEvery(interval time.Duration, function func() error) { func (gui *Gui) goEvery(interval time.Duration, function func() error) {
go func() { go func() {
for range time.Tick(interval) { for range time.Tick(interval) {
function() _ = function()
} }
}() }()
} }