summaryrefslogtreecommitdiffstats
path: root/pkg/app
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2022-08-14 17:37:07 +1000
committerGitHub <noreply@github.com>2022-08-14 17:37:07 +1000
commit4aea005f2674b5d21478582b2143739fdc2fcb93 (patch)
tree7d9530fbeaaae9ecde696a9baad1b276395d656b /pkg/app
parent39e92660892ad07ed062e35c196fd9b19a70c4b1 (diff)
parent8b371ada7361030daf83a1fd6e72be42025bc1de (diff)
Merge pull request #2098 from Ryooooooga/feature/not-a-repository-quit
Diffstat (limited to 'pkg/app')
-rw-r--r--pkg/app/app.go53
1 files changed, 31 insertions, 22 deletions
diff --git a/pkg/app/app.go b/pkg/app/app.go
index 3a1c127de..9e0679755 100644
--- a/pkg/app/app.go
+++ b/pkg/app/app.go
@@ -175,43 +175,52 @@ func (app *App) setupRepo() (bool, error) {
return false, err
}
- shouldInitRepo := true
- notARepository := app.UserConfig.NotARepository
- initialBranch := ""
- if notARepository == "prompt" {
+ var shouldInitRepo bool
+ initialBranchArg := ""
+ switch app.UserConfig.NotARepository {
+ case "prompt":
// Offer to initialize a new repository in current directory.
fmt.Print(app.Tr.CreateRepo)
response, _ := bufio.NewReader(os.Stdin).ReadString('\n')
- if strings.Trim(response, " \r\n") != "y" {
- shouldInitRepo = false
- } else {
+ shouldInitRepo = (strings.Trim(response, " \r\n") == "y")
+ if shouldInitRepo {
// Ask for the initial branch name
fmt.Print(app.Tr.InitialBranch)
response, _ := bufio.NewReader(os.Stdin).ReadString('\n')
if trimmedResponse := strings.Trim(response, " \r\n"); len(trimmedResponse) > 0 {
- initialBranch += "--initial-branch=" + trimmedResponse
+ initialBranchArg += "--initial-branch=" + app.OSCommand.Quote(trimmedResponse)
}
}
- } else if notARepository == "skip" {
+ case "create":
+ shouldInitRepo = true
+ case "skip":
shouldInitRepo = false
+ case "quit":
+ fmt.Fprintln(os.Stderr, app.Tr.NotARepository)
+ os.Exit(1)
+ default:
+ fmt.Fprintln(os.Stderr, app.Tr.IncorrectNotARepository)
+ os.Exit(1)
}
- if !shouldInitRepo {
- // check if we have a recent repo we can open
- for _, repoDir := range app.Config.GetAppState().RecentRepos {
- if isRepo, _ := isDirectoryAGitRepository(repoDir); isRepo {
- if err := os.Chdir(repoDir); err == nil {
- return true, nil
- }
- }
+ if shouldInitRepo {
+ if err := app.OSCommand.Cmd.New("git init " + initialBranchArg).Run(); err != nil {
+ return false, err
}
-
- fmt.Println(app.Tr.NoRecentRepositories)
- os.Exit(1)
+ return false, nil
}
- if err := app.OSCommand.Cmd.New("git init " + initialBranch).Run(); err != nil {
- return false, err
+
+ // check if we have a recent repo we can open
+ for _, repoDir := range app.Config.GetAppState().RecentRepos {
+ if isRepo, _ := isDirectoryAGitRepository(repoDir); isRepo {
+ if err := os.Chdir(repoDir); err == nil {
+ return true, nil
+ }
+ }
}
+
+ fmt.Fprintln(os.Stderr, app.Tr.NoRecentRepositories)
+ os.Exit(1)
}
return false, nil