diff --git a/pkg/cmd/repo/create/create.go b/pkg/cmd/repo/create/create.go index 1bd37769b41..097bd193547 100644 --- a/pkg/cmd/repo/create/create.go +++ b/pkg/cmd/repo/create/create.go @@ -396,7 +396,7 @@ func createFromScratch(opts *CreateOptions) error { remoteURL := ghrepo.FormatRemoteURL(repo, protocol) - if opts.LicenseTemplate == "" && opts.GitIgnoreTemplate == "" && opts.Template == "" { + if !opts.AddReadme && opts.LicenseTemplate == "" && opts.GitIgnoreTemplate == "" && opts.Template == "" { // cloning empty repository or template if err := localInit(opts.GitClient, remoteURL, repo.RepoName()); err != nil { return err diff --git a/pkg/cmd/repo/create/create_test.go b/pkg/cmd/repo/create/create_test.go index 5b5fd72bb44..b0d21460e1d 100644 --- a/pkg/cmd/repo/create/create_test.go +++ b/pkg/cmd/repo/create/create_test.go @@ -602,6 +602,35 @@ func Test_createRun(t *testing.T) { }, wantStdout: "https://github.com/OWNER/REPO\n", }, + { + name: "noninteractive clone with readme", + opts: &CreateOptions{ + Interactive: false, + Name: "ElliotAlderson", + Visibility: "PRIVATE", + Clone: true, + AddReadme: true, + }, + tty: false, + httpStubs: func(reg *httpmock.Registry) { + reg.Register( + httpmock.REST("POST", "user/repos"), + httpmock.RESTPayload(200, "{\"name\":\"ElliotAlderson\", \"owner\":{\"login\": \"OWNER\"}, \"html_url\":\"https://github.com/OWNER/ElliotAlderson\"}", + func(payload map[string]interface{}) { + payload["name"] = "ElliotAlderson" + payload["owner"] = map[string]interface{}{"login": "OWNER"} + payload["auto_init"] = true + payload["private"] = true + }, + ), + ) + }, + execStubs: func(cs *run.CommandStubber) { + cs.Register(`git clone https://github.com/OWNER/ElliotAlderson`, 128, "") + cs.Register(`git clone https://github.com/OWNER/ElliotAlderson`, 0, "") + }, + wantStdout: "https://github.com/OWNER/ElliotAlderson\n", + }, { name: "noninteractive create from template with retry", opts: &CreateOptions{