create repo on remote host from existing local repo
(opts *CreateOptions)
| 532 | |
| 533 | // create repo on remote host from existing local repo |
| 534 | func createFromLocal(opts *CreateOptions) error { |
| 535 | httpClient, err := opts.HttpClient() |
| 536 | if err != nil { |
| 537 | return err |
| 538 | } |
| 539 | |
| 540 | cs := opts.IO.ColorScheme() |
| 541 | isTTY := opts.IO.IsStdoutTTY() |
| 542 | stdout := opts.IO.Out |
| 543 | |
| 544 | cfg, err := opts.Config() |
| 545 | if err != nil { |
| 546 | return err |
| 547 | } |
| 548 | host, _ := cfg.Authentication().DefaultHost() |
| 549 | |
| 550 | if opts.Interactive { |
| 551 | var err error |
| 552 | opts.Source, err = opts.Prompter.Input("Path to local repository", ".") |
| 553 | if err != nil { |
| 554 | return err |
| 555 | } |
| 556 | } |
| 557 | |
| 558 | repoPath := opts.Source |
| 559 | opts.GitClient.RepoDir = repoPath |
| 560 | |
| 561 | var baseRemote string |
| 562 | if opts.Remote == "" { |
| 563 | baseRemote = "origin" |
| 564 | } else { |
| 565 | baseRemote = opts.Remote |
| 566 | } |
| 567 | |
| 568 | absPath, err := filepath.Abs(repoPath) |
| 569 | if err != nil { |
| 570 | return err |
| 571 | } |
| 572 | |
| 573 | repoType, err := localRepoType(opts.GitClient) |
| 574 | if err != nil { |
| 575 | return err |
| 576 | } |
| 577 | if repoType == unknown { |
| 578 | if repoPath == "." { |
| 579 | return fmt.Errorf("current directory is not a git repository. Run `git init` to initialize it") |
| 580 | } |
| 581 | return fmt.Errorf("%s is not a git repository. Run `git -C \"%s\" init` to initialize it", absPath, repoPath) |
| 582 | } |
| 583 | |
| 584 | committed, err := hasCommits(opts.GitClient) |
| 585 | if err != nil { |
| 586 | return err |
| 587 | } |
| 588 | if opts.Push { |
| 589 | // fail immediately if trying to push with no commits |
| 590 | if !committed { |
| 591 | return fmt.Errorf("`--push` enabled but no commits found in %s", absPath) |
no test coverage detected