(opts *SyncOptions)
| 97 | } |
| 98 | |
| 99 | func syncLocalRepo(opts *SyncOptions) error { |
| 100 | var srcRepo ghrepo.Interface |
| 101 | |
| 102 | if opts.SrcArg != "" { |
| 103 | var err error |
| 104 | srcRepo, err = ghrepo.FromFullName(opts.SrcArg) |
| 105 | if err != nil { |
| 106 | return err |
| 107 | } |
| 108 | } else { |
| 109 | var err error |
| 110 | srcRepo, err = opts.BaseRepo() |
| 111 | if err != nil { |
| 112 | return err |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | // Find remote that matches the srcRepo |
| 117 | var remote string |
| 118 | remotes, err := opts.Remotes() |
| 119 | if err != nil { |
| 120 | return err |
| 121 | } |
| 122 | if r, err := remotes.FindByRepo(srcRepo.RepoOwner(), srcRepo.RepoName()); err == nil { |
| 123 | remote = r.Name |
| 124 | } else { |
| 125 | return fmt.Errorf("can't find corresponding remote for %s", ghrepo.FullName(srcRepo)) |
| 126 | } |
| 127 | |
| 128 | if opts.Branch == "" { |
| 129 | httpClient, err := opts.HttpClient() |
| 130 | if err != nil { |
| 131 | return err |
| 132 | } |
| 133 | apiClient := api.NewClientFromHTTP(httpClient) |
| 134 | opts.IO.StartProgressIndicator() |
| 135 | opts.Branch, err = api.RepoDefaultBranch(apiClient, srcRepo) |
| 136 | opts.IO.StopProgressIndicator() |
| 137 | if err != nil { |
| 138 | return err |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | // Git fetch might require input from user, so do it before starting progress indicator. |
| 143 | if err := opts.Git.Fetch(remote, fmt.Sprintf("refs/heads/%s", opts.Branch)); err != nil { |
| 144 | return err |
| 145 | } |
| 146 | |
| 147 | opts.IO.StartProgressIndicator() |
| 148 | err = executeLocalRepoSync(srcRepo, remote, opts) |
| 149 | opts.IO.StopProgressIndicator() |
| 150 | if err != nil { |
| 151 | if errors.Is(err, divergingError) { |
| 152 | return fmt.Errorf("can't sync because there are diverging changes; use `--force` to overwrite the destination branch") |
| 153 | } |
| 154 | return err |
| 155 | } |
| 156 |
no test coverage detected