MCPcopy Create free account
hub / github.com/go-git/go-git / addReferenceIfRefSpecMatches

Method addReferenceIfRefSpecMatches

remote.go:750–796  ·  view source on GitHub ↗
(rs config.RefSpec,
	remoteRefs storer.ReferenceStorer, localRef *plumbing.Reference,
	req *packp.ReferenceUpdateRequest, forceWithLease *ForceWithLease)

Source from the content-addressed store, hash-verified

748}
749
750func (r *Remote) addReferenceIfRefSpecMatches(rs config.RefSpec,
751 remoteRefs storer.ReferenceStorer, localRef *plumbing.Reference,
752 req *packp.ReferenceUpdateRequest, forceWithLease *ForceWithLease) error {
753
754 if localRef.Type() != plumbing.HashReference {
755 return nil
756 }
757
758 if !rs.Match(localRef.Name()) {
759 return nil
760 }
761
762 cmd := &packp.Command{
763 Name: rs.Dst(localRef.Name()),
764 Old: plumbing.ZeroHash,
765 New: localRef.Hash(),
766 }
767
768 remoteRef, err := remoteRefs.Reference(cmd.Name)
769 if err == nil {
770 if remoteRef.Type() != plumbing.HashReference {
771 // TODO: check actual git behavior here
772 return nil
773 }
774
775 cmd.Old = remoteRef.Hash()
776 } else if err != plumbing.ErrReferenceNotFound {
777 return err
778 }
779
780 if cmd.Old == cmd.New {
781 return nil
782 }
783
784 if forceWithLease != nil {
785 if err = r.checkForceWithLease(localRef, cmd, forceWithLease); err != nil {
786 return err
787 }
788 } else if !rs.IsForceUpdate() {
789 if err := checkFastForwardUpdate(r.s, remoteRefs, cmd); err != nil {
790 return err
791 }
792 }
793
794 req.Commands = append(req.Commands, cmd)
795 return nil
796}
797
798func (r *Remote) checkForceWithLease(localRef *plumbing.Reference, cmd *packp.Command, forceWithLease *ForceWithLease) error {
799 remotePrefix := fmt.Sprintf("refs/remotes/%s/", r.Config().Name)

Callers 1

addOrUpdateReferencesMethod · 0.95

Calls 9

checkForceWithLeaseMethod · 0.95
checkFastForwardUpdateFunction · 0.85
DstMethod · 0.80
IsForceUpdateMethod · 0.80
TypeMethod · 0.65
MatchMethod · 0.65
NameMethod · 0.65
HashMethod · 0.65
ReferenceMethod · 0.65

Tested by

no test coverage detected