From a8fdd9a303526f2570da7969530e0dbd0d2ccb3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Wed, 17 Feb 2021 20:22:23 +0100 Subject: [PATCH] Further clarify what will happen on `repo create` In local git directory: 1. `This will add an "origin" git remote to your local repository. Continue?` 2. "origin" git remote is added in current directory. Outside of a local git directory: 1. This will create the "REPO" repository on GitHub. Continue? 2. `Create a local project directory for "REPO"?` 3. new directory called "REPO" now set up for the GitHub repository. --- pkg/cmd/repo/create/create.go | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/pkg/cmd/repo/create/create.go b/pkg/cmd/repo/create/create.go index 2aa7834ea..0b193b426 100644 --- a/pkg/cmd/repo/create/create.go +++ b/pkg/cmd/repo/create/create.go @@ -132,6 +132,7 @@ func createRun(opts *CreateOptions) error { isNameAnArg := false isDescEmpty := opts.Description == "" isVisibilityPassed := false + inLocalRepo := projectDirErr == nil if opts.Name != "" { isNameAnArg = true @@ -250,7 +251,7 @@ func createRun(opts *CreateOptions) error { createLocalDirectory := opts.ConfirmSubmit if !opts.ConfirmSubmit { - opts.ConfirmSubmit, err = confirmSubmission(input.Name, input.OwnerID, projectDirErr) + opts.ConfirmSubmit, err = confirmSubmission(input.Name, input.OwnerID, inLocalRepo) if err != nil { return err } @@ -284,7 +285,7 @@ func createRun(opts *CreateOptions) error { } remoteURL := ghrepo.FormatRemoteURL(repo, protocol) - if projectDirErr == nil { + if inLocalRepo { _, err = git.AddRemote("origin", remoteURL) if err != nil { return err @@ -295,7 +296,7 @@ func createRun(opts *CreateOptions) error { } else { if opts.IO.CanPrompt() { if !createLocalDirectory { - err := prompt.Confirm(fmt.Sprintf("Create a local project directory for %s?", ghrepo.FullName(repo)), &createLocalDirectory) + err := prompt.Confirm(fmt.Sprintf(`Create a local project directory for "%s"?`, ghrepo.FullName(repo)), &createLocalDirectory) if err != nil { return err } @@ -388,16 +389,18 @@ func interactiveRepoCreate(isDescEmpty bool, isVisibilityPassed bool, repoName s return answers.RepoName, answers.RepoDescription, strings.ToUpper(answers.RepoVisibility), nil } -func confirmSubmission(repoName string, repoOwner string, projectDirErr error) (bool, error) { +func confirmSubmission(repoName string, repoOwner string, inLocalRepo bool) (bool, error) { qs := []*survey.Question{} promptString := "" - if projectDirErr == nil { - promptString = "This will add remote origin to your current directory. Continue? " - } else if repoOwner != "" { - promptString = fmt.Sprintf("This will create '%s/%s' in your current directory. Continue? ", repoOwner, repoName) + if inLocalRepo { + promptString = `This will add an "origin" git remote to your local repository. Continue?` } else { - promptString = fmt.Sprintf("This will create '%s' in your current directory. Continue? ", repoName) + targetRepo := repoName + if repoOwner != "" { + targetRepo = fmt.Sprintf("%s/%s", repoOwner, repoName) + } + promptString = fmt.Sprintf(`This will create the "%s" repository on GitHub. Continue?`, targetRepo) } confirmSubmitQuestion := &survey.Question{