@@ -171,43 +171,52 @@ func (app *App) setupRepo() (bool, error) {
171171 return false , err
172172 }
173173
174- shouldInitRepo := true
175- notARepository := app . UserConfig . NotARepository
176- initialBranch := ""
177- if notARepository == "prompt" {
174+ var shouldInitRepo bool
175+ initialBranchArg := ""
176+ switch app . UserConfig . NotARepository {
177+ case "prompt" :
178178 // Offer to initialize a new repository in current directory.
179179 fmt .Print (app .Tr .CreateRepo )
180180 response , _ := bufio .NewReader (os .Stdin ).ReadString ('\n' )
181- if strings .Trim (response , " \r \n " ) != "y" {
182- shouldInitRepo = false
183- } else {
181+ shouldInitRepo = (strings .Trim (response , " \r \n " ) == "y" )
182+ if shouldInitRepo {
184183 // Ask for the initial branch name
185184 fmt .Print (app .Tr .InitialBranch )
186185 response , _ := bufio .NewReader (os .Stdin ).ReadString ('\n' )
187186 if trimmedResponse := strings .Trim (response , " \r \n " ); len (trimmedResponse ) > 0 {
188- initialBranch += "--initial-branch=" + trimmedResponse
187+ initialBranchArg += "--initial-branch=" + app . OSCommand . Quote ( trimmedResponse )
189188 }
190189 }
191- } else if notARepository == "skip" {
190+ case "create" :
191+ shouldInitRepo = true
192+ case "skip" :
192193 shouldInitRepo = false
194+ case "quit" :
195+ fmt .Fprintln (os .Stderr , app .Tr .NotARepository )
196+ os .Exit (1 )
197+ default :
198+ fmt .Fprintln (os .Stderr , app .Tr .IncorrectNotARepository )
199+ os .Exit (1 )
193200 }
194201
195- if ! shouldInitRepo {
196- // check if we have a recent repo we can open
197- for _ , repoDir := range app .Config .GetAppState ().RecentRepos {
198- if isRepo , _ := isDirectoryAGitRepository (repoDir ); isRepo {
199- if err := os .Chdir (repoDir ); err == nil {
200- return true , nil
201- }
202- }
202+ if shouldInitRepo {
203+ if err := app .OSCommand .Cmd .New ("git init " + initialBranchArg ).Run (); err != nil {
204+ return false , err
203205 }
204-
205- fmt .Println (app .Tr .NoRecentRepositories )
206- os .Exit (1 )
206+ return false , nil
207207 }
208- if err := app .OSCommand .Cmd .New ("git init " + initialBranch ).Run (); err != nil {
209- return false , err
208+
209+ // check if we have a recent repo we can open
210+ for _ , repoDir := range app .Config .GetAppState ().RecentRepos {
211+ if isRepo , _ := isDirectoryAGitRepository (repoDir ); isRepo {
212+ if err := os .Chdir (repoDir ); err == nil {
213+ return true , nil
214+ }
215+ }
210216 }
217+
218+ fmt .Fprintln (os .Stderr , app .Tr .NoRecentRepositories )
219+ os .Exit (1 )
211220 }
212221
213222 return false , nil
0 commit comments