| 843 | } |
| 844 | |
| 845 | func (c *Client) AddRemote(ctx context.Context, name, urlStr string, trackingBranches []string) (*Remote, error) { |
| 846 | args := []string{"remote", "add"} |
| 847 | for _, branch := range trackingBranches { |
| 848 | args = append(args, "-t", branch) |
| 849 | } |
| 850 | args = append(args, name, urlStr) |
| 851 | cmd, err := c.Command(ctx, args...) |
| 852 | if err != nil { |
| 853 | return nil, err |
| 854 | } |
| 855 | if _, err := cmd.Output(); err != nil { |
| 856 | return nil, err |
| 857 | } |
| 858 | var urlParsed *url.URL |
| 859 | if strings.HasPrefix(urlStr, "https") { |
| 860 | urlParsed, err = url.Parse(urlStr) |
| 861 | if err != nil { |
| 862 | return nil, err |
| 863 | } |
| 864 | } else { |
| 865 | urlParsed, err = ParseURL(urlStr) |
| 866 | if err != nil { |
| 867 | return nil, err |
| 868 | } |
| 869 | } |
| 870 | remote := &Remote{ |
| 871 | Name: name, |
| 872 | FetchURL: urlParsed, |
| 873 | PushURL: urlParsed, |
| 874 | } |
| 875 | return remote, nil |
| 876 | } |
| 877 | |
| 878 | // Below are commands that make network calls and need authentication credentials supplied from gh. |
| 879 | |