1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-07-17 01:42:45 +02:00

Better CWD check for a git repository.

This commit is contained in:
Dima Kotik
2020-05-28 07:20:13 +03:00
committed by Jesse Duffield
parent cf5cefb2d6
commit e73f4c6b7e

View File

@ -131,9 +131,16 @@ func NewApp(config config.AppConfigurer, filterPath string) (*App, error) {
func (app *App) setupRepo() error {
// if we are not in a git repo, we ask if we want to `git init`
if err := app.OSCommand.RunCommand("git status"); err != nil {
if !strings.Contains(err.Error(), "Not a git repository") {
cwd, err := os.Getwd()
if err != nil {
return err
}
info, _ := os.Stat(filepath.Join(cwd, ".git"))
if info != nil && info.IsDir() {
return err // Current directory appears to be a git repository.
}
// Offer to initialize a new repository in current directory.
fmt.Print(app.Tr.SLocalize("CreateRepo"))
response, _ := bufio.NewReader(os.Stdin).ReadString('\n')
if strings.Trim(response, " \n") != "y" {