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

Method PushRefs

repository/gogit.go:449–500  ·  view source on GitHub ↗

PushRefs push git refs matching a directory prefix to a remote Ex: prefix="foo" will push any local refs matching "refs/foo/*" to the remote. The equivalent git refspec would be "refs/foo/*:refs/foo/*" Additionally, PushRefs will update the local references in refs/remotes/ /foo to match the

(remote string, prefixes ...string)

Source from the content-addressed store, hash-verified

447// Additionally, PushRefs will update the local references in refs/remotes/<remote>/foo to match
448// the remote state.
449func (repo *GoGitRepo) PushRefs(remote string, prefixes ...string) (string, error) {
450 remo, err := repo.r.Remote(remote)
451 if err != nil {
452 return "", err
453 }
454
455 refSpecs := make([]config.RefSpec, len(prefixes))
456
457 for i, prefix := range prefixes {
458 refspec := fmt.Sprintf("refs/%s/*:refs/%s/*", prefix, prefix)
459
460 // to make sure that the push also create the corresponding refs/remotes/<remote>/... references,
461 // we need to have a default fetch refspec configured on the remote, to make our refs "track" the remote ones.
462 // This does not change the config on disk, only on memory.
463 hasCustomFetch := false
464 fetchRefspec := fmt.Sprintf("refs/%s/*:refs/remotes/%s/%s/*", prefix, remote, prefix)
465 for _, r := range remo.Config().Fetch {
466 if string(r) == fetchRefspec {
467 hasCustomFetch = true
468 break
469 }
470 }
471
472 if !hasCustomFetch {
473 remo.Config().Fetch = append(remo.Config().Fetch, config.RefSpec(fetchRefspec))
474 }
475
476 refSpecs[i] = config.RefSpec(refspec)
477 }
478
479 buf := bytes.NewBuffer(nil)
480
481 remoteUrl, err := repo.resolveRemote(remote, false)
482 if err != nil {
483 return "", err
484 }
485
486 err = remo.Push(&gogit.PushOptions{
487 RemoteName: remote,
488 RemoteURL: remoteUrl,
489 RefSpecs: refSpecs,
490 Progress: buf,
491 })
492 if err == gogit.NoErrAlreadyUpToDate {
493 return "already up-to-date", nil
494 }
495 if err != nil {
496 return "", err
497 }
498
499 return buf.String(), nil
500}
501
502// StoreData will store arbitrary data and return the corresponding hash
503func (repo *GoGitRepo) StoreData(data []byte) (Hash, error) {

Callers

nothing calls this directly

Calls 3

resolveRemoteMethod · 0.95
PushMethod · 0.80
StringMethod · 0.65

Tested by

no test coverage detected