diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2019-03-16 11:31:09 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2019-03-16 11:38:16 +1100 |
commit | 43e5c042a2595ebfcf1109b989db94600dac530a (patch) | |
tree | 5317cf3255f701e96f498565789f686eabe1e764 /pkg/app | |
parent | 39844ffef9987a8ee6ff97d68491dc766079f07b (diff) |
prompt user to git init when outside a repo
Diffstat (limited to 'pkg/app')
-rw-r--r-- | pkg/app/app.go | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/pkg/app/app.go b/pkg/app/app.go index c5bfd516f..fc75a6608 100644 --- a/pkg/app/app.go +++ b/pkg/app/app.go @@ -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() |