MCPcopy
hub / github.com/go-git/go-git / defaultRemote

Function defaultRemote

submodule.go:196–217  ·  view source on GitHub ↗

defaultRemote returns the remote that relative submodule URLs are resolved against, mirroring canonical Git's repo_default_remote (remote.c) and resolve_relative_url (builtin/submodule--helper.c): 1. if HEAD is on a branch with branch. .remote configured, use that remote; 2. else if exactly on

(r *Repository)

Source from the content-addressed store, hash-verified

194// finds the branch but with an empty Remote does not short-circuit
195// rule (2). Returns an error when the chosen remote is not configured.
196func defaultRemote(r *Repository) (*config.RemoteConfig, error) {
197 cfg, err := r.Config()
198 if err != nil {
199 return nil, err
200 }
201
202 if ref, err := r.Reference(plumbing.HEAD, false); err == nil &&
203 ref.Type() == plumbing.SymbolicReference &&
204 ref.Target().IsBranch() {
205 if b, ok := cfg.Branches[ref.Target().Short()]; ok && b.Remote != "" {
206 return lookupRemote(cfg, b.Remote)
207 }
208 }
209
210 if len(cfg.Remotes) == 1 {
211 for name := range cfg.Remotes {
212 return lookupRemote(cfg, name)
213 }
214 }
215
216 return lookupRemote(cfg, DefaultRemoteName)
217}
218
219func lookupRemote(cfg *config.Config, name string) (*config.RemoteConfig, error) {
220 rc, ok := cfg.Remotes[name]

Callers 2

TestDefaultRemoteMethod · 0.85
RepositoryMethod · 0.85

Calls 7

lookupRemoteFunction · 0.85
IsBranchMethod · 0.80
TargetMethod · 0.80
ShortMethod · 0.80
ConfigMethod · 0.65
ReferenceMethod · 0.65
TypeMethod · 0.65

Tested by 1

TestDefaultRemoteMethod · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…