mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-02-09 13:47:11 +02:00
support switching to recent repo
This commit is contained in:
parent
ba7e6add86
commit
ca715c5b23
@ -77,11 +77,11 @@ func Setup(config config.AppConfigurer) (*App, error) {
|
|||||||
|
|
||||||
app.Tr = i18n.NewLocalizer(app.Log)
|
app.Tr = i18n.NewLocalizer(app.Log)
|
||||||
|
|
||||||
app.GitCommand, err = commands.NewGitCommand(app.Log, app.OSCommand, app.Tr)
|
app.Updater, err = updates.NewUpdater(app.Log, config, app.OSCommand, app.Tr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return app, err
|
return app, err
|
||||||
}
|
}
|
||||||
app.Updater, err = updates.NewUpdater(app.Log, config, app.OSCommand, app.Tr)
|
app.GitCommand, err = commands.NewGitCommand(app.Log, app.OSCommand, app.Tr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return app, err
|
return app, err
|
||||||
}
|
}
|
||||||
|
@ -33,6 +33,7 @@ var OverlappingEdges = false
|
|||||||
type SentinelErrors struct {
|
type SentinelErrors struct {
|
||||||
ErrSubProcess error
|
ErrSubProcess error
|
||||||
ErrNoFiles error
|
ErrNoFiles error
|
||||||
|
ErrSwitchRepo error
|
||||||
}
|
}
|
||||||
|
|
||||||
// GenerateSentinelErrors makes the sentinel errors for the gui. We're defining it here
|
// GenerateSentinelErrors makes the sentinel errors for the gui. We're defining it here
|
||||||
@ -49,6 +50,7 @@ func (gui *Gui) GenerateSentinelErrors() {
|
|||||||
gui.Errors = SentinelErrors{
|
gui.Errors = SentinelErrors{
|
||||||
ErrSubProcess: errors.New(gui.Tr.SLocalize("RunningSubprocess")),
|
ErrSubProcess: errors.New(gui.Tr.SLocalize("RunningSubprocess")),
|
||||||
ErrNoFiles: errors.New(gui.Tr.SLocalize("NoChangedFiles")),
|
ErrNoFiles: errors.New(gui.Tr.SLocalize("NoChangedFiles")),
|
||||||
|
ErrSwitchRepo: errors.New("switching repo"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -292,6 +294,10 @@ func (gui *Gui) layout(g *gocui.Gui) error {
|
|||||||
// these are only called once (it's a place to put all the things you want
|
// these are only called once (it's a place to put all the things you want
|
||||||
// to happen on startup after the screen is first rendered)
|
// to happen on startup after the screen is first rendered)
|
||||||
gui.Updater.CheckForNewUpdate(gui.onBackgroundUpdateCheckFinish, false)
|
gui.Updater.CheckForNewUpdate(gui.onBackgroundUpdateCheckFinish, false)
|
||||||
|
if err := gui.updateRecentRepoList(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
gui.handleFileSelect(g, filesView)
|
gui.handleFileSelect(g, filesView)
|
||||||
gui.refreshFiles(g)
|
gui.refreshFiles(g)
|
||||||
gui.refreshBranches(g)
|
gui.refreshBranches(g)
|
||||||
@ -311,6 +317,41 @@ func (gui *Gui) layout(g *gocui.Gui) error {
|
|||||||
return gui.resizeCurrentPopupPanel(g)
|
return gui.resizeCurrentPopupPanel(g)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func newRecentReposList(recentRepos []string, currentRepo string) []string {
|
||||||
|
newRepos := []string{currentRepo}
|
||||||
|
for _, repo := range recentRepos {
|
||||||
|
if repo != currentRepo {
|
||||||
|
newRepos = append(newRepos, repo)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return newRepos
|
||||||
|
}
|
||||||
|
|
||||||
|
// updateRecentRepoList registers the fact that we opened lazygit in this repo,
|
||||||
|
// so that we can open the same repo via a 'recent repos' menu
|
||||||
|
func (gui *Gui) updateRecentRepoList() error {
|
||||||
|
recentRepos := gui.Config.GetAppState().RecentRepos
|
||||||
|
currentRepo, err := os.Getwd()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
gui.Config.GetAppState().RecentRepos = newRecentReposList(recentRepos, currentRepo)
|
||||||
|
return gui.Config.SaveAppState()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (gui *Gui) handleSwitchRepo(g *gocui.Gui, v *gocui.View) error {
|
||||||
|
newRepo := gui.Config.GetAppState().RecentRepos[1]
|
||||||
|
if err := os.Chdir(newRepo); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
newGitCommand, err := commands.NewGitCommand(gui.Log, gui.OSCommand, gui.Tr)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
gui.GitCommand = newGitCommand
|
||||||
|
return gui.Errors.ErrSwitchRepo
|
||||||
|
}
|
||||||
|
|
||||||
func (gui *Gui) promptAnonymousReporting() error {
|
func (gui *Gui) promptAnonymousReporting() error {
|
||||||
return gui.createConfirmationPanel(gui.g, nil, gui.Tr.SLocalize("AnonymousReportingTitle"), gui.Tr.SLocalize("AnonymousReportingPrompt"), func(g *gocui.Gui, v *gocui.View) error {
|
return gui.createConfirmationPanel(gui.g, nil, gui.Tr.SLocalize("AnonymousReportingTitle"), gui.Tr.SLocalize("AnonymousReportingPrompt"), func(g *gocui.Gui, v *gocui.View) error {
|
||||||
return gui.Config.WriteToUserConfig("reporting", "on")
|
return gui.Config.WriteToUserConfig("reporting", "on")
|
||||||
@ -391,6 +432,8 @@ func (gui *Gui) RunWithSubprocesses() {
|
|||||||
if err := gui.Run(); err != nil {
|
if err := gui.Run(); err != nil {
|
||||||
if err == gocui.ErrQuit {
|
if err == gocui.ErrQuit {
|
||||||
break
|
break
|
||||||
|
} else if err == gui.Errors.ErrSwitchRepo {
|
||||||
|
continue
|
||||||
} else if err == gui.Errors.ErrSubProcess {
|
} else if err == gui.Errors.ErrSubProcess {
|
||||||
gui.SubProcess.Stdin = os.Stdin
|
gui.SubProcess.Stdin = os.Stdin
|
||||||
gui.SubProcess.Stdout = os.Stdout
|
gui.SubProcess.Stdout = os.Stdout
|
||||||
|
@ -27,6 +27,7 @@ func (gui *Gui) keybindings(g *gocui.Gui) error {
|
|||||||
{ViewName: "status", Key: 'e', Modifier: gocui.ModNone, Handler: gui.handleEditConfig},
|
{ViewName: "status", Key: 'e', Modifier: gocui.ModNone, Handler: gui.handleEditConfig},
|
||||||
{ViewName: "status", Key: 'o', Modifier: gocui.ModNone, Handler: gui.handleOpenConfig},
|
{ViewName: "status", Key: 'o', Modifier: gocui.ModNone, Handler: gui.handleOpenConfig},
|
||||||
{ViewName: "status", Key: 'u', Modifier: gocui.ModNone, Handler: gui.handleCheckForUpdate},
|
{ViewName: "status", Key: 'u', Modifier: gocui.ModNone, Handler: gui.handleCheckForUpdate},
|
||||||
|
{ViewName: "status", Key: 's', Modifier: gocui.ModNone, Handler: gui.handleSwitchRepo},
|
||||||
{ViewName: "files", Key: 'c', Modifier: gocui.ModNone, Handler: gui.handleCommitPress},
|
{ViewName: "files", Key: 'c', Modifier: gocui.ModNone, Handler: gui.handleCommitPress},
|
||||||
{ViewName: "files", Key: 'C', Modifier: gocui.ModNone, Handler: gui.handleCommitEditorPress},
|
{ViewName: "files", Key: 'C', Modifier: gocui.ModNone, Handler: gui.handleCommitEditorPress},
|
||||||
{ViewName: "files", Key: gocui.KeySpace, Modifier: gocui.ModNone, Handler: gui.handleFilePress},
|
{ViewName: "files", Key: gocui.KeySpace, Modifier: gocui.ModNone, Handler: gui.handleFilePress},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user