diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2020-09-29 09:02:44 +1000 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2020-09-29 18:21:59 +1000 |
commit | 914fb361732c116b3db6bd47bd9d08bb9f15a608 (patch) | |
tree | 57284367b095f1c895573bcc0f5def3def7238ea /pkg/gui | |
parent | b882ac9e066bce21c18d73122005f06acfda3bfa (diff) |
allow entering and returning from submodule
Diffstat (limited to 'pkg/gui')
-rw-r--r-- | pkg/gui/files_panel.go | 12 | ||||
-rw-r--r-- | pkg/gui/gui.go | 7 | ||||
-rw-r--r-- | pkg/gui/quitting.go | 12 | ||||
-rw-r--r-- | pkg/gui/recent_repos_panel.go | 32 |
4 files changed, 49 insertions, 14 deletions
diff --git a/pkg/gui/files_panel.go b/pkg/gui/files_panel.go index c57f94082..26ec38bc5 100644 --- a/pkg/gui/files_panel.go +++ b/pkg/gui/files_panel.go @@ -8,6 +8,7 @@ import ( // "strings" "fmt" + "os" "regexp" "strings" @@ -159,6 +160,17 @@ func (gui *Gui) enterFile(forceSecondaryFocused bool, selectedLineIdx int) error return nil } + submoduleConfigs := gui.State.SubmoduleConfigs + if file.IsSubmodule(submoduleConfigs) { + wd, err := os.Getwd() + if err != nil { + return err + } + gui.State.RepoPathStack = append(gui.State.RepoPathStack, wd) + submoduleConfig := file.SubmoduleConfig(submoduleConfigs) + return gui.dispatchSwitchToRepo(submoduleConfig.Path) + } + if file.HasInlineMergeConflicts { return gui.handleSwitchToMerge() } diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go index 94634113b..d35fe59be 100644 --- a/pkg/gui/gui.go +++ b/pkg/gui/gui.go @@ -317,6 +317,10 @@ type guiState struct { // Some views move between windows for example the commitFiles view and when cycling through // side windows we need to know which view to give focus to for a given window WindowViewNameMap map[string]string + + // when you enter into a submodule we'll append the superproject's path to this array + // so that you can return to the superproject + RepoPathStack []string } func (gui *Gui) resetState() { @@ -329,10 +333,12 @@ func (gui *Gui) resetState() { CherryPickedCommits: make([]*commands.Commit, 0), ContextKey: "", } + prevRepoPathStack := []string{} if gui.State != nil { prevFiltering = gui.State.Modes.Filtering prevDiff = gui.State.Modes.Diffing prevCherryPicking = gui.State.Modes.CherryPicking + prevRepoPathStack = gui.State.RepoPathStack } modes := Modes{ @@ -371,6 +377,7 @@ func (gui *Gui) resetState() { Ptmx: nil, Modes: modes, ViewContextMap: gui.initialViewContextMap(), + RepoPathStack: prevRepoPathStack, } } diff --git a/pkg/gui/quitting.go b/pkg/gui/quitting.go index d53971ba3..34df87e92 100644 --- a/pkg/gui/quitting.go +++ b/pkg/gui/quitting.go @@ -49,6 +49,18 @@ func (gui *Gui) handleTopLevelReturn(g *gocui.Gui, v *gocui.View) error { } } + + repoPathStack := gui.State.RepoPathStack + if len(repoPathStack) > 0 { + n := len(repoPathStack) - 1 + + path := repoPathStack[n] + + gui.State.RepoPathStack = repoPathStack[:n] + + return gui.dispatchSwitchToRepo(path) + } + if gui.Config.GetUserConfig().GetBool("quitOnTopLevelReturn") { return gui.handleQuit() } diff --git a/pkg/gui/recent_repos_panel.go b/pkg/gui/recent_repos_panel.go index 677836172..ab17ee8d3 100644 --- a/pkg/gui/recent_repos_panel.go +++ b/pkg/gui/recent_repos_panel.go @@ -17,24 +17,14 @@ func (gui *Gui) handleCreateRecentReposMenu() error { // we won't show the current repo hence the -1 menuItems := make([]*menuItem, reposCount-1) for i, path := range recentRepoPaths[1:reposCount] { - innerPath := path + path := path // cos we're closing over the loop variable menuItems[i] = &menuItem{ displayStrings: []string{ - filepath.Base(innerPath), - yellow.Sprint(innerPath), + filepath.Base(path), + yellow.Sprint(path), }, onPress: func() error { - env.UnsetGitDirEnvs() - if err := os.Chdir(innerPath); err != nil { - return err - } - newGitCommand, err := commands.NewGitCommand(gui.Log, gui.OSCommand, gui.Tr, gui.Config) - if err != nil { - return err - } - gui.GitCommand = newGitCommand - gui.State.Modes.Filtering.Path = "" - return gui.Errors.ErrSwitchRepo + return gui.dispatchSwitchToRepo(path) }, } } @@ -42,6 +32,20 @@ func (gui *Gui) handleCreateRecentReposMenu() error { return gui.createMenu(gui.Tr.SLocalize("RecentRepos"), menuItems, createMenuOptions{showCancel: true}) } +func (gui *Gui) dispatchSwitchToRepo(path string) error { + env.UnsetGitDirEnvs() + if err := os.Chdir(path); err != nil { + return err + } + newGitCommand, err := commands.NewGitCommand(gui.Log, gui.OSCommand, gui.Tr, gui.Config) + if err != nil { + return err + } + gui.GitCommand = newGitCommand + gui.State.Modes.Filtering.Path = "" + return gui.Errors.ErrSwitchRepo +} + // updateRecentRepoList registers the fact that we opened lazygit in this repo, // so that we can open the same repo via the 'recent repos' menu func (gui *Gui) updateRecentRepoList() error { |