MCPcopy Index your code
hub / github.com/rilldata/rill / SetRemote

Function SetRemote

cli/pkg/gitutil/gitutil.go:309–340  ·  view source on GitHub ↗

SetRemote sets the remote by name Rill for the given repository to the provided remote URL.

(path string, config *Config)

Source from the content-addressed store, hash-verified

307
308// SetRemote sets the remote by name Rill for the given repository to the provided remote URL.
309func SetRemote(path string, config *Config) error {
310 if config.Remote == "" {
311 return nil
312 }
313 repo, err := git.PlainOpen(path)
314 if err != nil {
315 return fmt.Errorf("failed to open git repository: %w", err)
316 }
317
318 remote, err := repo.Remote(config.RemoteName())
319 if err != nil && !errors.Is(err, git.ErrRemoteNotFound) {
320 return fmt.Errorf("failed to get remote: %w", err)
321 }
322 if remote != nil {
323 if remote.Config().URLs[0] == config.Remote || !config.ManagedRepo {
324 // remote already exists with the same URL, no need to create it again
325 // remote other than managed git exists, can't overwrite user's remote
326 return nil
327 }
328 // if the remote already exists with a different URL, delete it
329 err = repo.DeleteRemote(config.RemoteName())
330 if err != nil {
331 return fmt.Errorf("failed to delete existing remote: %w", err)
332 }
333 }
334
335 _, err = repo.CreateRemote(&gitConfig.RemoteConfig{
336 Name: config.RemoteName(),
337 URLs: []string{config.Remote},
338 })
339 return err
340}
341
342func IsGitRepo(path string) bool {
343 _, err := git.PlainOpenWithOptions(path, &git.PlainOpenOptions{

Callers 8

HandleRepoTransferMethod · 0.92
CommitAndSafePushMethod · 0.92
setupTestRepositoryFunction · 0.92
GitStatusMethod · 0.92
GitPullMethod · 0.92
GitPushMethod · 0.92
CommitAndPushFunction · 0.85

Calls 3

RemoteNameMethod · 0.80
ErrorfMethod · 0.65
ConfigMethod · 0.65

Tested by 2

setupTestRepositoryFunction · 0.74