MCPcopy
hub / github.com/cli/cli / syncRemoteRepo

Function syncRemoteRepo

pkg/cmd/repo/sync/sync.go:168–217  ·  view source on GitHub ↗
(opts *SyncOptions)

Source from the content-addressed store, hash-verified

166}
167
168func syncRemoteRepo(opts *SyncOptions) error {
169 httpClient, err := opts.HttpClient()
170 if err != nil {
171 return err
172 }
173 apiClient := api.NewClientFromHTTP(httpClient)
174
175 var destRepo, srcRepo ghrepo.Interface
176
177 destRepo, err = ghrepo.FromFullName(opts.DestArg)
178 if err != nil {
179 return err
180 }
181
182 if opts.SrcArg != "" {
183 srcRepo, err = ghrepo.FromFullName(opts.SrcArg)
184 if err != nil {
185 return err
186 }
187 }
188
189 if srcRepo != nil && destRepo.RepoHost() != srcRepo.RepoHost() {
190 return fmt.Errorf("can't sync repositories from different hosts")
191 }
192
193 opts.IO.StartProgressIndicator()
194 baseBranchLabel, err := executeRemoteRepoSync(apiClient, destRepo, srcRepo, opts)
195 opts.IO.StopProgressIndicator()
196 if err != nil {
197 if errors.Is(err, divergingError) {
198 return fmt.Errorf("can't sync because there are diverging changes; use `--force` to overwrite the destination branch")
199 }
200 return err
201 }
202
203 if opts.IO.IsStdoutTTY() {
204 cs := opts.IO.ColorScheme()
205 branchName := opts.Branch
206 if idx := strings.Index(baseBranchLabel, ":"); idx >= 0 {
207 branchName = baseBranchLabel[idx+1:]
208 }
209 fmt.Fprintf(opts.IO.Out, "%s Synced the \"%s:%s\" branch from \"%s\"\n",
210 cs.SuccessIcon(),
211 destRepo.RepoOwner(),
212 branchName,
213 baseBranchLabel)
214 }
215
216 return nil
217}
218
219var divergingError = errors.New("diverging changes")
220

Callers 1

syncRunFunction · 0.85

Calls 11

RepoHostMethod · 0.95
RepoOwnerMethod · 0.95
NewClientFromHTTPFunction · 0.92
FromFullNameFunction · 0.92
executeRemoteRepoSyncFunction · 0.85
IsStdoutTTYMethod · 0.80
ColorSchemeMethod · 0.80
SuccessIconMethod · 0.80
ErrorfMethod · 0.65
StopProgressIndicatorMethod · 0.65

Tested by

no test coverage detected