Fix creating a repository from template
Fixes a problem where setting up a new local directory for the
repository created from a template would not contain any files:
gh repo create -p OWNER/some-template my-repo --private --confirm
ls my-repo
//=> [empty directory]
Fixes #2290
This commit is contained in:
parent
a8fdd9a303
commit
e596f8732b
1 changed files with 36 additions and 23 deletions
|
|
@ -304,32 +304,11 @@ func createRun(opts *CreateOptions) error {
|
|||
}
|
||||
if createLocalDirectory {
|
||||
path := repo.Name
|
||||
|
||||
gitInit, err := git.GitCommand("init", path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
isTTY := opts.IO.IsStdoutTTY()
|
||||
if isTTY {
|
||||
gitInit.Stdout = stdout
|
||||
}
|
||||
gitInit.Stderr = stderr
|
||||
err = run.PrepareCmd(gitInit).Run()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
gitRemoteAdd, err := git.GitCommand("-C", path, "remote", "add", "origin", remoteURL)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
gitRemoteAdd.Stdout = stdout
|
||||
gitRemoteAdd.Stderr = stderr
|
||||
err = run.PrepareCmd(gitRemoteAdd).Run()
|
||||
if err != nil {
|
||||
if err := localInit(opts.IO, remoteURL, path, opts.Template != ""); err != nil {
|
||||
return err
|
||||
}
|
||||
if isTTY {
|
||||
fmt.Fprintf(stderr, "%s Initialized repository in './%s/'\n", cs.SuccessIcon(), path)
|
||||
fmt.Fprintf(stderr, "%s Initialized repository in \"%s\"\n", cs.SuccessIcon(), path)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -340,6 +319,40 @@ func createRun(opts *CreateOptions) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func localInit(io *iostreams.IOStreams, remoteURL, path string, isTemplate bool) error {
|
||||
if isTemplate {
|
||||
cloneCmd, err := git.GitCommand("clone", remoteURL, path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
cloneCmd.Stdout = io.Out
|
||||
cloneCmd.Stderr = io.ErrOut
|
||||
return run.PrepareCmd(cloneCmd).Run()
|
||||
}
|
||||
|
||||
gitInit, err := git.GitCommand("init", path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
isTTY := io.IsStdoutTTY()
|
||||
if isTTY {
|
||||
gitInit.Stdout = io.Out
|
||||
}
|
||||
gitInit.Stderr = io.ErrOut
|
||||
err = run.PrepareCmd(gitInit).Run()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
gitRemoteAdd, err := git.GitCommand("-C", path, "remote", "add", "origin", remoteURL)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
gitRemoteAdd.Stdout = io.Out
|
||||
gitRemoteAdd.Stderr = io.ErrOut
|
||||
return run.PrepareCmd(gitRemoteAdd).Run()
|
||||
}
|
||||
|
||||
func interactiveRepoCreate(isDescEmpty bool, isVisibilityPassed bool, repoName string) (string, string, string, error) {
|
||||
qs := []*survey.Question{}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue