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

Method FetchRefs

repository/gogit.go:376–404  ·  view source on GitHub ↗

FetchRefs fetch git refs matching a directory prefix to a remote Ex: prefix="foo" will fetch any remote refs matching "refs/foo/*" locally. The equivalent git refspec would be "refs/foo/*:refs/remotes/ /foo/*"

(remote string, prefixes ...string)

Source from the content-addressed store, hash-verified

374// Ex: prefix="foo" will fetch any remote refs matching "refs/foo/*" locally.
375// The equivalent git refspec would be "refs/foo/*:refs/remotes/<remote>/foo/*"
376func (repo *GoGitRepo) FetchRefs(remote string, prefixes ...string) (string, error) {
377 refSpecs := make([]config.RefSpec, len(prefixes))
378
379 for i, prefix := range prefixes {
380 refSpecs[i] = config.RefSpec(fmt.Sprintf("refs/%s/*:refs/remotes/%s/%s/*", prefix, remote, prefix))
381 }
382
383 buf := bytes.NewBuffer(nil)
384
385 remoteUrl, err := repo.resolveRemote(remote, true)
386 if err != nil {
387 return "", err
388 }
389
390 err = repo.r.Fetch(&gogit.FetchOptions{
391 RemoteName: remote,
392 RemoteURL: remoteUrl,
393 RefSpecs: refSpecs,
394 Progress: buf,
395 })
396 if err == gogit.NoErrAlreadyUpToDate {
397 return "already up-to-date", nil
398 }
399 if err != nil {
400 return "", err
401 }
402
403 return buf.String(), nil
404}
405
406// resolveRemote returns the URI for a given remote
407func (repo *GoGitRepo) resolveRemote(remote string, fetch bool) (string, error) {

Callers

nothing calls this directly

Calls 3

resolveRemoteMethod · 0.95
FetchMethod · 0.80
StringMethod · 0.65

Tested by

no test coverage detected