MCPcopy
hub / github.com/cli/cli / cloneRun

Function cloneRun

pkg/cmd/repo/clone/clone.go:111–237  ·  view source on GitHub ↗
(opts *CloneOptions)

Source from the content-addressed store, hash-verified

109}
110
111func cloneRun(opts *CloneOptions) error {
112 httpClient, err := opts.HttpClient()
113 if err != nil {
114 return err
115 }
116
117 cfg, err := opts.Config()
118 if err != nil {
119 return err
120 }
121
122 apiClient := api.NewClientFromHTTP(httpClient)
123
124 repositoryIsURL := strings.Contains(opts.Repository, ":")
125 repositoryIsFullName := !repositoryIsURL && strings.Contains(opts.Repository, "/")
126
127 var repo ghrepo.Interface
128 var protocol string
129
130 if repositoryIsURL {
131 initialURL, err := git.ParseURL(opts.Repository)
132 if err != nil {
133 return err
134 }
135
136 repoURL := simplifyURL(initialURL)
137 repo, err = ghrepo.FromURL(repoURL)
138 if err != nil {
139 return err
140 }
141 if repoURL.Scheme == "git+ssh" {
142 repoURL.Scheme = "ssh"
143 }
144 protocol = repoURL.Scheme
145 } else {
146 var fullName string
147 if repositoryIsFullName {
148 fullName = opts.Repository
149 } else {
150 host, _ := cfg.Authentication().DefaultHost()
151 currentUser, err := api.CurrentLoginName(apiClient, host)
152 if err != nil {
153 return err
154 }
155 fullName = currentUser + "/" + opts.Repository
156 }
157
158 repo, err = ghrepo.FromFullName(fullName)
159 if err != nil {
160 return err
161 }
162
163 protocol = cfg.GitProtocol(repo.RepoHost()).Value
164 }
165
166 wantsWiki := strings.HasSuffix(repo.RepoName(), ".wiki")
167 if wantsWiki {
168 repoName := strings.TrimSuffix(repo.RepoName(), ".wiki")

Callers 1

NewCmdCloneFunction · 0.70

Calls 15

RepoHostMethod · 0.95
RepoNameMethod · 0.95
RepoOwnerMethod · 0.95
NewClientFromHTTPFunction · 0.92
ParseURLFunction · 0.92
FromURLFunction · 0.92
CurrentLoginNameFunction · 0.92
FromFullNameFunction · 0.92
NewWithHostFunction · 0.92
GitHubRepoFunction · 0.92
FormatRemoteURLFunction · 0.92
FullNameFunction · 0.92

Tested by

no test coverage detected