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

Method AddRemote

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

Source from the content-addressed store, hash-verified

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

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