| 781 | } |
| 782 | |
| 783 | func (c *Client) AddRemote(ctx context.Context, name, urlStr string, trackingBranches []string) (*Remote, error) { |
| 784 | args := []string{"remote", "add"} |
| 785 | for _, branch := range trackingBranches { |
| 786 | args = append(args, "-t", branch) |
| 787 | } |
| 788 | args = append(args, name, urlStr) |
| 789 | cmd, err := c.Command(ctx, args...) |
| 790 | if err != nil { |
| 791 | return nil, err |
| 792 | } |
| 793 | if _, err := cmd.Output(); err != nil { |
| 794 | return nil, err |
| 795 | } |
| 796 | var urlParsed *url.URL |
| 797 | if strings.HasPrefix(urlStr, "https") { |
| 798 | urlParsed, err = url.Parse(urlStr) |
| 799 | if err != nil { |
| 800 | return nil, err |
| 801 | } |
| 802 | } else { |
| 803 | urlParsed, err = ParseURL(urlStr) |
| 804 | if err != nil { |
| 805 | return nil, err |
| 806 | } |
| 807 | } |
| 808 | remote := &Remote{ |
| 809 | Name: name, |
| 810 | FetchURL: urlParsed, |
| 811 | PushURL: urlParsed, |
| 812 | } |
| 813 | return remote, nil |
| 814 | } |
| 815 | |
| 816 | // Below are commands that make network calls and need authentication credentials supplied from gh. |
| 817 | |