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

prompt user to git init when outside a repo

This commit is contained in:
Jesse Duffield 2019-03-16 11:31:09 +11:00
parent 39844ffef9
commit 43e5c042a2
4 changed files with 33 additions and 4 deletions

View File

@ -1,6 +1,7 @@
package app
import (
"bufio"
"fmt"
"io"
"io/ioutil"
@ -114,12 +115,13 @@ func NewApp(config config.AppConfigurer) (*App, error) {
if err != nil {
return app, err
}
if err := app.setupRepo(); err != nil {
return app, err
}
app.GitCommand, err = commands.NewGitCommand(app.Log, app.OSCommand, app.Tr, app.Config)
if err != nil {
if strings.Contains(err.Error(), "Not a git repository") {
fmt.Println("Not in a git repository. Use `git init` to create a new one")
os.Exit(1)
}
return app, err
}
app.Gui, err = gui.NewGui(app.Log, app.GitCommand, app.OSCommand, app.Tr, config, app.Updater)
@ -129,6 +131,24 @@ func NewApp(config config.AppConfigurer) (*App, error) {
return app, nil
}
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") {
return err
}
fmt.Print(app.Tr.SLocalize("CreateRepo"))
response, _ := bufio.NewReader(os.Stdin).ReadString('\n')
if strings.Trim(response, " \n") != "y" {
os.Exit(1)
}
if err := app.OSCommand.RunCommand("git init"); err != nil {
return err
}
}
return nil
}
func (app *App) Run() error {
if app.ClientContext == "INTERACTIVE_REBASE" {
return app.Rebase()

View File

@ -670,6 +670,9 @@ func addDutch(i18nObject *i18n.Bundle) error {
}, &i18n.Message{
ID: "DisabledForGPG",
Other: "Feature not available for users using GPG",
}, &i18n.Message{
ID: "CreateRepo",
Other: "Not in a git repository. Create a new git repository? (y/n): ",
},
)
}

View File

@ -693,6 +693,9 @@ func addEnglish(i18nObject *i18n.Bundle) error {
}, &i18n.Message{
ID: "DisabledForGPG",
Other: "Feature not available for users using GPG",
}, &i18n.Message{
ID: "CreateRepo",
Other: "Not in a git repository. Create a new git repository? (y/n): ",
},
)
}

View File

@ -653,6 +653,9 @@ func addPolish(i18nObject *i18n.Bundle) error {
}, &i18n.Message{
ID: "DisabledForGPG",
Other: "Feature not available for users using GPG",
}, &i18n.Message{
ID: "CreateRepo",
Other: "Not in a git repository. Create a new git repository? (y/n): ",
},
)
}