MCPcopy
hub / github.com/cli/cli / createFromLocal

Function createFromLocal

pkg/cmd/repo/create/create.go:533–707  ·  view source on GitHub ↗

create repo on remote host from existing local repo

(opts *CreateOptions)

Source from the content-addressed store, hash-verified

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

Callers 1

createRunFunction · 0.85

Calls 15

RepoNameMethod · 0.95
RepoOwnerMethod · 0.95
RepoHostMethod · 0.95
NewWithHostFunction · 0.92
FromFullNameFunction · 0.92
FullNameFunction · 0.92
FormatRemoteURLFunction · 0.92
localRepoTypeFunction · 0.85
hasCommitsFunction · 0.85
interactiveRepoInfoFunction · 0.85
repoCreateFunction · 0.85
sourceInitFunction · 0.85

Tested by

no test coverage detected