MCPcopy Create free account
hub / github.com/cli/cli / createFromLocal

Function createFromLocal

pkg/cmd/repo/create/create.go:534–708  ·  view source on GitHub ↗

create repo on remote host from existing local repo

(opts *CreateOptions)

Source from the content-addressed store, hash-verified

532
533// create repo on remote host from existing local repo
534func 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)

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