mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-07-03 00:57:52 +02:00
Factor out opening of recent repos
This commit is contained in:
@ -162,6 +162,18 @@ func isBareRepo(osCommand *oscommands.OSCommand) (bool, error) {
|
|||||||
return strconv.ParseBool(strings.TrimSpace(res))
|
return strconv.ParseBool(strings.TrimSpace(res))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func openRecentRepo(app *App) bool {
|
||||||
|
for _, repoDir := range app.Config.GetAppState().RecentRepos {
|
||||||
|
if isRepo, _ := isDirectoryAGitRepository(repoDir); isRepo {
|
||||||
|
if err := os.Chdir(repoDir); err == nil {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
func (app *App) setupRepo() (bool, error) {
|
func (app *App) setupRepo() (bool, error) {
|
||||||
if err := app.validateGitVersion(); err != nil {
|
if err := app.validateGitVersion(); err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
@ -205,17 +217,13 @@ func (app *App) setupRepo() (bool, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !shouldInitRepo {
|
if !shouldInitRepo {
|
||||||
// check if we have a recent repo we can open
|
// Attempt to open a recent repo, exit if no repo could be opened
|
||||||
for _, repoDir := range app.Config.GetAppState().RecentRepos {
|
if didOpenRepo := openRecentRepo(app); !didOpenRepo {
|
||||||
if isRepo, _ := isDirectoryAGitRepository(repoDir); isRepo {
|
fmt.Println(app.Tr.NoRecentRepositories)
|
||||||
if err := os.Chdir(repoDir); err == nil {
|
os.Exit(1)
|
||||||
return true, nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println(app.Tr.NoRecentRepositories)
|
return true, nil
|
||||||
os.Exit(1)
|
|
||||||
}
|
}
|
||||||
if err := app.OSCommand.Cmd.New("git init " + initialBranch).Run(); err != nil {
|
if err := app.OSCommand.Cmd.New("git init " + initialBranch).Run(); err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
@ -234,19 +242,16 @@ func (app *App) setupRepo() (bool, error) {
|
|||||||
shouldOpenRecent := strings.Trim(response, " \r\n") == "y"
|
shouldOpenRecent := strings.Trim(response, " \r\n") == "y"
|
||||||
|
|
||||||
if shouldOpenRecent {
|
if shouldOpenRecent {
|
||||||
for _, repoDir := range app.Config.GetAppState().RecentRepos {
|
if didOpenRepo := openRecentRepo(app); !didOpenRepo {
|
||||||
if isRepo, _ := isDirectoryAGitRepository(repoDir); isRepo {
|
fmt.Println(app.Tr.NoRecentRepositories)
|
||||||
if err := os.Chdir(repoDir); err == nil {
|
os.Exit(1)
|
||||||
return true, nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println(app.Tr.NoRecentRepositories)
|
// We managed to open a recent repo, continue as usual
|
||||||
os.Exit(1)
|
return true, nil
|
||||||
|
} else {
|
||||||
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
os.Exit(0)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false, nil
|
return false, nil
|
||||||
|
Reference in New Issue
Block a user