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

Function cloneWithRetry

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

Source from the content-addressed store, hash-verified

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