MCPcopy Create free account
hub / github.com/Scalingo/cli / AddGitRemote

Function AddGitRemote

utils/git.go:86–101  ·  view source on GitHub ↗

AddGitRemote add a remote URL to the current git repository

(ctx context.Context, url string, name string)

Source from the content-addressed store, hash-verified

84
85// AddGitRemote add a remote URL to the current git repository
86func AddGitRemote(ctx context.Context, url string, name string) error {
87 repo, err := git.PlainOpen(".")
88 if err != nil {
89 return errors.Wrapf(ctx, err, "fail to initialize the Git repository")
90 }
91
92 _, err = repo.CreateRemote(&gitconfig.RemoteConfig{
93 Name: name,
94 URLs: []string{url},
95 })
96 if err != nil {
97 return errors.Wrapf(ctx, err, "fail to add the Git remote")
98 }
99
100 return nil
101}
102
103// MainBranchName returns the repository main branch name, preferring origin/HEAD,
104// then common local branch names. In case of errors, return `main`.

Callers 1

CreateFunction · 0.92

Calls

no outgoing calls

Tested by

no test coverage detected