(opts *SyncOptions)
| 166 | } |
| 167 | |
| 168 | func 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 | |
| 219 | var divergingError = errors.New("diverging changes") |
| 220 |
no test coverage detected