MCPcopy
hub / github.com/cli/cli / cloneWithRetry

Function cloneWithRetry

pkg/cmd/repo/create/create.go:709–734  ·  view source on GitHub ↗
(opts *CreateOptions, remoteURL, branch string)

Source from the content-addressed store, hash-verified

707}
708
709func cloneWithRetry(opts *CreateOptions, remoteURL, branch string) error {
710 // Allow injecting alternative BackOff in tests.
711 if opts.BackOff == nil {
712 opts.BackOff = backoff.NewConstantBackOff(3 * time.Second)
713 }
714
715 var args []string
716 if branch != "" {
717 args = append(args, "--branch", branch)
718 }
719
720 ctx := context.Background()
721 return backoff.Retry(func() error {
722 stderr := &bytes.Buffer{}
723 _, err := opts.GitClient.Clone(ctx, remoteURL, args, git.WithStderr(stderr))
724
725 var execError errWithExitCode
726 if errors.As(err, &execError) && execError.ExitCode() == 128 {
727 return err
728 } else {
729 _, _ = io.Copy(opts.IO.ErrOut, stderr)
730 }
731
732 return backoff.Permanent(err)
733 }, backoff.WithContext(backoff.WithMaxRetries(opts.BackOff, 3), ctx))
734}
735
736func sourceInit(gitClient *git.Client, io *iostreams.IOStreams, remoteURL, baseRemote string) error {
737 cs := io.ColorScheme()

Callers 2

createFromScratchFunction · 0.85
createFromTemplateFunction · 0.85

Calls 4

ExitCodeMethod · 0.95
WithStderrFunction · 0.92
CloneMethod · 0.65
CopyMethod · 0.45

Tested by

no test coverage detected