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

Method addReferenceIfRefSpecMatches

remote.go:764–810  ·  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

762}
763
764func (r *Remote) addReferenceIfRefSpecMatches(rs config.RefSpec,
765 remoteRefs storer.ReferenceStorer, localRef *plumbing.Reference,
766 req *packp.ReferenceUpdateRequest, forceWithLease *ForceWithLease) error {
767
768 if localRef.Type() != plumbing.HashReference {
769 return nil
770 }
771
772 if !rs.Match(localRef.Name()) {
773 return nil
774 }
775
776 cmd := &packp.Command{
777 Name: rs.Dst(localRef.Name()),
778 Old: plumbing.ZeroHash,
779 New: localRef.Hash(),
780 }
781
782 remoteRef, err := remoteRefs.Reference(cmd.Name)
783 if err == nil {
784 if remoteRef.Type() != plumbing.HashReference {
785 // TODO: check actual git behavior here
786 return nil
787 }
788
789 cmd.Old = remoteRef.Hash()
790 } else if err != plumbing.ErrReferenceNotFound {
791 return err
792 }
793
794 if cmd.Old == cmd.New {
795 return nil
796 }
797
798 if forceWithLease != nil {
799 if err = r.checkForceWithLease(localRef, cmd, forceWithLease); err != nil {
800 return err
801 }
802 } else if !rs.IsForceUpdate() {
803 if err := checkFastForwardUpdate(r.s, remoteRefs, cmd); err != nil {
804 return err
805 }
806 }
807
808 req.Commands = append(req.Commands, cmd)
809 return nil
810}
811
812func (r *Remote) checkForceWithLease(localRef *plumbing.Reference, cmd *packp.Command, forceWithLease *ForceWithLease) error {
813 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