MCPcopy
hub / github.com/cli/cli / AddRemote

Method AddRemote

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

Source from the content-addressed store, hash-verified

781}
782
783func (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

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