MCPcopy Create free account
hub / github.com/git-bug/git-bug / resolveRemote

Method resolveRemote

repository/gogit.go:407–441  ·  view source on GitHub ↗

resolveRemote returns the URI for a given remote

(remote string, fetch bool)

Source from the content-addressed store, hash-verified

405
406// resolveRemote returns the URI for a given remote
407func (repo *GoGitRepo) resolveRemote(remote string, fetch bool) (string, error) {
408 cfg, err := repo.r.ConfigScoped(config.SystemScope)
409 if err != nil {
410 return "", fmt.Errorf("unable to load system-scoped git config: %v", err)
411 }
412
413 var url string
414 for _, re := range cfg.Remotes {
415 if remote == re.Name {
416 // url is set matching the default logic in go-git's repository.Push
417 // and repository.Fetch logic as of go-git v5.12.1.
418 //
419 // we do this because the push and fetch methods can only take one
420 // remote for both option structs, even though the push method
421 // _should_ push to all of the URLs defined for a given remote.
422 url = re.URLs[len(re.URLs)-1]
423 if fetch {
424 url = re.URLs[0]
425 }
426
427 for _, u := range cfg.URLs {
428 if strings.HasPrefix(url, u.InsteadOf) {
429 url = u.ApplyInsteadOf(url)
430 break
431 }
432 }
433 }
434 }
435
436 if url == "" {
437 return "", fmt.Errorf("unable to resolve URL for remote: %v", err)
438 }
439
440 return url, nil
441}
442
443// PushRefs push git refs matching a directory prefix to a remote
444// Ex: prefix="foo" will push any local refs matching "refs/foo/*" to the remote.

Callers 2

FetchRefsMethod · 0.95
PushRefsMethod · 0.95

Calls 2

ErrorfMethod · 0.80
HasPrefixMethod · 0.45

Tested by

no test coverage detected