1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-01-08 04:04:22 +02:00

allow entering and returning from submodule

This commit is contained in:
Jesse Duffield 2020-09-29 09:02:44 +10:00
parent b882ac9e06
commit 914fb36173
4 changed files with 49 additions and 14 deletions

View File

@ -8,6 +8,7 @@ import (
// "strings" // "strings"
"fmt" "fmt"
"os"
"regexp" "regexp"
"strings" "strings"
@ -159,6 +160,17 @@ func (gui *Gui) enterFile(forceSecondaryFocused bool, selectedLineIdx int) error
return nil 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 { if file.HasInlineMergeConflicts {
return gui.handleSwitchToMerge() return gui.handleSwitchToMerge()
} }

View File

@ -317,6 +317,10 @@ type guiState struct {
// Some views move between windows for example the commitFiles view and when cycling through // 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 // side windows we need to know which view to give focus to for a given window
WindowViewNameMap map[string]string 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() { func (gui *Gui) resetState() {
@ -329,10 +333,12 @@ func (gui *Gui) resetState() {
CherryPickedCommits: make([]*commands.Commit, 0), CherryPickedCommits: make([]*commands.Commit, 0),
ContextKey: "", ContextKey: "",
} }
prevRepoPathStack := []string{}
if gui.State != nil { if gui.State != nil {
prevFiltering = gui.State.Modes.Filtering prevFiltering = gui.State.Modes.Filtering
prevDiff = gui.State.Modes.Diffing prevDiff = gui.State.Modes.Diffing
prevCherryPicking = gui.State.Modes.CherryPicking prevCherryPicking = gui.State.Modes.CherryPicking
prevRepoPathStack = gui.State.RepoPathStack
} }
modes := Modes{ modes := Modes{
@ -371,6 +377,7 @@ func (gui *Gui) resetState() {
Ptmx: nil, Ptmx: nil,
Modes: modes, Modes: modes,
ViewContextMap: gui.initialViewContextMap(), ViewContextMap: gui.initialViewContextMap(),
RepoPathStack: prevRepoPathStack,
} }
} }

View File

@ -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") { if gui.Config.GetUserConfig().GetBool("quitOnTopLevelReturn") {
return gui.handleQuit() return gui.handleQuit()
} }

View File

@ -17,15 +17,24 @@ func (gui *Gui) handleCreateRecentReposMenu() error {
// we won't show the current repo hence the -1 // we won't show the current repo hence the -1
menuItems := make([]*menuItem, reposCount-1) menuItems := make([]*menuItem, reposCount-1)
for i, path := range recentRepoPaths[1:reposCount] { for i, path := range recentRepoPaths[1:reposCount] {
innerPath := path path := path // cos we're closing over the loop variable
menuItems[i] = &menuItem{ menuItems[i] = &menuItem{
displayStrings: []string{ displayStrings: []string{
filepath.Base(innerPath), filepath.Base(path),
yellow.Sprint(innerPath), yellow.Sprint(path),
}, },
onPress: func() error { onPress: func() error {
return gui.dispatchSwitchToRepo(path)
},
}
}
return gui.createMenu(gui.Tr.SLocalize("RecentRepos"), menuItems, createMenuOptions{showCancel: true})
}
func (gui *Gui) dispatchSwitchToRepo(path string) error {
env.UnsetGitDirEnvs() env.UnsetGitDirEnvs()
if err := os.Chdir(innerPath); err != nil { if err := os.Chdir(path); err != nil {
return err return err
} }
newGitCommand, err := commands.NewGitCommand(gui.Log, gui.OSCommand, gui.Tr, gui.Config) newGitCommand, err := commands.NewGitCommand(gui.Log, gui.OSCommand, gui.Tr, gui.Config)
@ -35,11 +44,6 @@ func (gui *Gui) handleCreateRecentReposMenu() error {
gui.GitCommand = newGitCommand gui.GitCommand = newGitCommand
gui.State.Modes.Filtering.Path = "" gui.State.Modes.Filtering.Path = ""
return gui.Errors.ErrSwitchRepo return gui.Errors.ErrSwitchRepo
},
}
}
return gui.createMenu(gui.Tr.SLocalize("RecentRepos"), menuItems, createMenuOptions{showCancel: true})
} }
// updateRecentRepoList registers the fact that we opened lazygit in this repo, // updateRecentRepoList registers the fact that we opened lazygit in this repo,