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 | |
parent | 39844ffef9987a8ee6ff97d68491dc766079f07b (diff) |
prompt user to git init when outside a repo
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/app/app.go | 28 | ||||
-rw-r--r-- | pkg/i18n/dutch.go | 3 | ||||
-rw-r--r-- | pkg/i18n/english.go | 3 | ||||
-rw-r--r-- | pkg/i18n/polish.go | 3 |
4 files changed, 33 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() diff --git a/pkg/i18n/dutch.go b/pkg/i18n/dutch.go index c90bab649..4daa83075 100644 --- a/pkg/i18n/dutch.go +++ b/pkg/i18n/dutch.go @@ -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): ", }, ) } diff --git a/pkg/i18n/english.go b/pkg/i18n/english.go index f9b32b86f..b94bbb3ec 100644 --- a/pkg/i18n/english.go +++ b/pkg/i18n/english.go @@ -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): ", }, ) } diff --git a/pkg/i18n/polish.go b/pkg/i18n/polish.go index 2eaddeff1..b459c6ee3 100644 --- a/pkg/i18n/polish.go +++ b/pkg/i18n/polish.go @@ -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): ", }, ) } |