summaryrefslogtreecommitdiffstats
path: root/pkg/gui/gui.go
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2023-07-28 18:27:14 +1000
committerJesse Duffield <jessedduffield@gmail.com>2023-07-30 18:35:24 +1000
commit4c5b1574f147fe2005bcd30bbb5dc106c4838b92 (patch)
treece7fada27e54f793024e740add3e5779a2c63262 /pkg/gui/gui.go
parentde57cfd6ff17751f7243476441beab6486fb4381 (diff)
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.
Diffstat (limited to 'pkg/gui/gui.go')
-rw-r--r--pkg/gui/gui.go10
1 files changed, 4 insertions, 6 deletions
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