summaryrefslogtreecommitdiffstats
path: root/pkg/gui
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
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')
-rw-r--r--pkg/gui/controllers/helpers/refresh_helper.go2
-rw-r--r--pkg/gui/controllers/helpers/repos_helper.go2
-rw-r--r--pkg/gui/controllers/helpers/working_tree_helper.go3
-rw-r--r--pkg/gui/controllers/status_controller.go4
-rw-r--r--pkg/gui/gui.go10
5 files changed, 8 insertions, 13 deletions
diff --git a/pkg/gui/controllers/helpers/refresh_helper.go b/pkg/gui/controllers/helpers/refresh_helper.go
index 0dc6924f9..46130231f 100644
--- a/pkg/gui/controllers/helpers/refresh_helper.go
+++ b/pkg/gui/controllers/helpers/refresh_helper.go
@@ -631,7 +631,7 @@ func (self *RefreshHelper) refreshStatus() {
workingTreeState := self.c.Git().Status.WorkingTreeState()
linkedWorktreeName := self.worktreeHelper.GetLinkedWorktreeName()
- repoName := git_commands.GetCurrentRepoName()
+ repoName := self.c.Git().RepoPaths.RepoName()
status := presentation.FormatStatus(repoName, currentBranch, linkedWorktreeName, workingTreeState, self.c.Tr)
diff --git a/pkg/gui/controllers/helpers/repos_helper.go b/pkg/gui/controllers/helpers/repos_helper.go
index c39997c5b..0faa0e16b 100644
--- a/pkg/gui/controllers/helpers/repos_helper.go
+++ b/pkg/gui/controllers/helpers/repos_helper.go
@@ -145,7 +145,7 @@ func (self *ReposHelper) DispatchSwitchToRepo(path string, contextKey types.Cont
func (self *ReposHelper) DispatchSwitchTo(path string, errMsg string, contextKey types.ContextKey) error {
return self.c.WithWaitingStatus(self.c.Tr.Switching, func(gocui.Task) error {
- env.UnsetGitDirEnvs()
+ env.UnsetGitDirEnv()
originalPath, err := os.Getwd()
if err != nil {
return nil
diff --git a/pkg/gui/controllers/helpers/working_tree_helper.go b/pkg/gui/controllers/helpers/working_tree_helper.go
index a0a0447d7..dba9d2a6a 100644
--- a/pkg/gui/controllers/helpers/working_tree_helper.go
+++ b/pkg/gui/controllers/helpers/working_tree_helper.go
@@ -4,7 +4,6 @@ import (
"fmt"
"regexp"
- "github.com/jesseduffield/lazygit/pkg/commands/git_commands"
"github.com/jesseduffield/lazygit/pkg/commands/models"
"github.com/jesseduffield/lazygit/pkg/config"
"github.com/jesseduffield/lazygit/pkg/gui/context"
@@ -203,7 +202,7 @@ func (self *WorkingTreeHelper) prepareFilesForCommit() error {
}
func (self *WorkingTreeHelper) commitPrefixConfigForRepo() *config.CommitPrefixConfig {
- cfg, ok := self.c.UserConfig.Git.CommitPrefixes[git_commands.GetCurrentRepoName()]
+ cfg, ok := self.c.UserConfig.Git.CommitPrefixes[self.c.Git().RepoPaths.RepoName()]
if !ok {
return nil
}
diff --git a/pkg/gui/controllers/status_controller.go b/pkg/gui/controllers/status_controller.go
index d8e906f3b..af1cb9984 100644
--- a/pkg/gui/controllers/status_controller.go
+++ b/pkg/gui/controllers/status_controller.go
@@ -6,7 +6,6 @@ import (
"strings"
"github.com/jesseduffield/generics/slices"
- "github.com/jesseduffield/lazygit/pkg/commands/git_commands"
"github.com/jesseduffield/lazygit/pkg/commands/types/enums"
"github.com/jesseduffield/lazygit/pkg/constants"
"github.com/jesseduffield/lazygit/pkg/gui/presentation"
@@ -108,8 +107,7 @@ func (self *StatusController) onClick() error {
cx, _ := self.c.Views().Status.Cursor()
upstreamStatus := presentation.BranchStatus(currentBranch, self.c.Tr)
- // TODO: support worktrees here
- repoName := git_commands.GetCurrentRepoName()
+ repoName := self.c.Git().RepoPaths.RepoName()
workingTreeState := self.c.Git().Status.WorkingTreeState()
switch workingTreeState {
case enums.REBASE_MODE_REBASING, enums.REBASE_MODE_MERGING:
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