From 4c5b1574f147fe2005bcd30bbb5dc106c4838b92 Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Fri, 28 Jul 2023 18:27:14 +1000 Subject: Centralise logic for obtaining repo paths There are quite a few paths you might want to get e.g. the repo's path, the worktree's path, the repo's git dir path, the worktree's git dir path. I want these all obtained once and then used when needed rather than having to have IO whenever we need them. This is not so much about reducing time spent on IO as it is about not having to care about errors every time we want a path. --- pkg/gui/gui.go | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'pkg/gui/gui.go') diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go index ec4ab77c5..42a29d500 100644 --- a/pkg/gui/gui.go +++ b/pkg/gui/gui.go @@ -64,7 +64,8 @@ type Gui struct { CustomCommandsClient *custom_commands.Client // this is a mapping of repos to gui states, so that we can restore the original - // gui state when returning from a subrepo + // gui state when returning from a subrepo. + // In repos with multiple worktrees, we store a separate repo state per worktree. RepoStateMap map[Repo]*GuiRepoState Config config.AppConfigurer Updater *updates.Updater @@ -325,12 +326,9 @@ func (gui *Gui) onNewRepo(startArgs appTypes.StartArgs, contextKey types.Context // you've already switched from. There's no doubt some easy way to make the UX // optimal for all cases but I'm too lazy to think about what that is right now func (gui *Gui) resetState(startArgs appTypes.StartArgs) types.Context { - currentDir, err := os.Getwd() - if err != nil { - gui.c.Log.Error(err) - } + worktreePath := gui.git.RepoPaths.WorktreePath() - if state := gui.RepoStateMap[Repo(currentDir)]; state != nil { + if state := gui.RepoStateMap[Repo(worktreePath)]; state != nil { gui.State = state gui.State.ViewsSetup = false -- cgit v1.2.3