| 162 | } |
| 163 | |
| 164 | func (c *Client) Remotes(ctx context.Context) (RemoteSet, error) { |
| 165 | remoteArgs := []string{"remote", "-v"} |
| 166 | remoteCmd, err := c.Command(ctx, remoteArgs...) |
| 167 | if err != nil { |
| 168 | return nil, err |
| 169 | } |
| 170 | remoteOut, remoteErr := remoteCmd.Output() |
| 171 | if remoteErr != nil { |
| 172 | return nil, remoteErr |
| 173 | } |
| 174 | |
| 175 | configArgs := []string{"config", "--get-regexp", `^remote\..*\.gh-resolved$`} |
| 176 | configCmd, err := c.Command(ctx, configArgs...) |
| 177 | if err != nil { |
| 178 | return nil, err |
| 179 | } |
| 180 | configOut, configErr := configCmd.Output() |
| 181 | if configErr != nil { |
| 182 | // Ignore exit code 1 as it means there are no resolved remotes. |
| 183 | var gitErr *GitError |
| 184 | if ok := errors.As(configErr, &gitErr); ok && gitErr.ExitCode != 1 { |
| 185 | return nil, gitErr |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | remotes := parseRemotes(outputLines(remoteOut)) |
| 190 | populateResolvedRemotes(remotes, outputLines(configOut)) |
| 191 | sort.Sort(remotes) |
| 192 | return remotes, nil |
| 193 | } |
| 194 | |
| 195 | func (c *Client) UpdateRemoteURL(ctx context.Context, name, url string) error { |
| 196 | args := []string{"remote", "set-url", name, url} |