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)
| 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/*" |
| 376 | func (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 |
| 407 | func (repo *GoGitRepo) resolveRemote(remote string, fetch bool) (string, error) { |
nothing calls this directly
no test coverage detected