MCPcopy Create free account
hub / github.com/cli/cli / AddRemote

Method AddRemote

git/client.go:845–876  ·  view source on GitHub ↗
(ctx context.Context, name, urlStr string, trackingBranches []string)

Source from the content-addressed store, hash-verified

843}
844
845func (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

Callers 4

TestClientAddRemoteFunction · 0.95
cloneRunFunction · 0.80
forkRunFunction · 0.80
handlePushFunction · 0.80

Calls 3

CommandMethod · 0.95
ParseURLFunction · 0.70
OutputMethod · 0.65

Tested by 1

TestClientAddRemoteFunction · 0.76