mirror of
				https://github.com/jesseduffield/lazygit.git
				synced 2025-10-30 23:57:43 +02:00 
			
		
		
		
	reset state on each Run() call
This commit is contained in:
		| @@ -283,6 +283,8 @@ func NewGui(log *logrus.Entry, gitCommand *commands.GitCommand, oSCommand *comma | |||||||
|  |  | ||||||
| // Run setup the gui with keybindings and start the mainloop | // Run setup the gui with keybindings and start the mainloop | ||||||
| func (gui *Gui) Run() error { | func (gui *Gui) Run() error { | ||||||
|  | 	gui.resetState() | ||||||
|  |  | ||||||
| 	g, err := gocui.NewGui(gocui.Output256, OverlappingEdges) | 	g, err := gocui.NewGui(gocui.Output256, OverlappingEdges) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return err | 		return err | ||||||
|   | |||||||
| @@ -32,6 +32,7 @@ func (gui *Gui) handleCreateRecentReposMenu(g *gocui.Gui, v *gocui.View) error { | |||||||
| 					return err | 					return err | ||||||
| 				} | 				} | ||||||
| 				gui.GitCommand = newGitCommand | 				gui.GitCommand = newGitCommand | ||||||
|  | 				gui.State.FilterPath = "" | ||||||
| 				return gui.Errors.ErrSwitchRepo | 				return gui.Errors.ErrSwitchRepo | ||||||
| 			}, | 			}, | ||||||
| 		} | 		} | ||||||
|   | |||||||
| @@ -47,23 +47,30 @@ func (gui *Gui) handleReflogCommitSelect(g *gocui.Gui, v *gocui.View) error { | |||||||
| 	return nil | 	return nil | ||||||
| } | } | ||||||
|  |  | ||||||
|  | // the reflogs panel is the only panel where we cache data, in that we only | ||||||
|  | // load entries that have been created since we last ran the call. This means | ||||||
|  | // we need to be more careful with how we use this, and to ensure we're emptying | ||||||
|  | // the reflogs array when changing contexts. | ||||||
| func (gui *Gui) refreshReflogCommits() error { | func (gui *Gui) refreshReflogCommits() error { | ||||||
|  | 	// pulling state into its own variable incase it gets swapped out for another state | ||||||
|  | 	// and we get an out of bounds exception | ||||||
|  | 	state := gui.State | ||||||
| 	var lastReflogCommit *commands.Commit | 	var lastReflogCommit *commands.Commit | ||||||
| 	if len(gui.State.ReflogCommits) > 0 { | 	if len(state.ReflogCommits) > 0 { | ||||||
| 		lastReflogCommit = gui.State.ReflogCommits[0] | 		lastReflogCommit = state.ReflogCommits[0] | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	commits, onlyObtainedNewReflogCommits, err := gui.GitCommand.GetReflogCommits(lastReflogCommit, gui.State.FilterPath) | 	commits, onlyObtainedNewReflogCommits, err := gui.GitCommand.GetReflogCommits(lastReflogCommit, state.FilterPath) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return gui.surfaceError(err) | 		return gui.surfaceError(err) | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	if onlyObtainedNewReflogCommits { | 	if onlyObtainedNewReflogCommits { | ||||||
| 		gui.State.ReflogCommits = append(commits, gui.State.ReflogCommits...) | 		state.ReflogCommits = append(commits, state.ReflogCommits...) | ||||||
| 	} else { | 	} else { | ||||||
| 		// if we haven't found it we're probably in a new repo so we don't want to | 		// if we haven't found it we're probably in a new repo so we don't want to | ||||||
| 		// retain the old reflog commits | 		// retain the old reflog commits | ||||||
| 		gui.State.ReflogCommits = commits | 		state.ReflogCommits = commits | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	if gui.getCommitsView().Context == "reflog-commits" { | 	if gui.getCommitsView().Context == "reflog-commits" { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user