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

Method updateLocalReferenceStorage

remote.go:1220–1295  ·  view source on GitHub ↗
(
	specs []config.RefSpec,
	fetchedRefs, remoteRefs memory.ReferenceStorage,
	specToRefs [][]*plumbing.Reference,
	tagMode TagMode,
	force bool,
)

Source from the content-addressed store, hash-verified

1218}
1219
1220func (r *Remote) updateLocalReferenceStorage(
1221 specs []config.RefSpec,
1222 fetchedRefs, remoteRefs memory.ReferenceStorage,
1223 specToRefs [][]*plumbing.Reference,
1224 tagMode TagMode,
1225 force bool,
1226) (updated bool, err error) {
1227 isWildcard := true
1228 forceNeeded := false
1229
1230 for i, spec := range specs {
1231 if !spec.IsWildcard() {
1232 isWildcard = false
1233 }
1234
1235 for _, ref := range specToRefs[i] {
1236 if ref.Type() != plumbing.HashReference {
1237 continue
1238 }
1239
1240 localName := spec.Dst(ref.Name())
1241 // If localName doesn't start with "refs/" then treat as a branch.
1242 if !strings.HasPrefix(localName.String(), "refs/") {
1243 localName = plumbing.NewBranchReferenceName(localName.String())
1244 }
1245 old, _ := storer.ResolveReference(r.s, localName)
1246 new := plumbing.NewHashReference(localName, ref.Hash())
1247
1248 // If the ref exists locally as a non-tag and force is not
1249 // specified, only update if the new ref is an ancestor of the old
1250 if old != nil && !old.Name().IsTag() && !force && !spec.IsForceUpdate() {
1251 ff, err := isFastForward(r.s, old.Hash(), new.Hash(), nil)
1252 if err != nil {
1253 return updated, err
1254 }
1255
1256 if !ff {
1257 forceNeeded = true
1258 continue
1259 }
1260 }
1261
1262 refUpdated, err := checkAndUpdateReferenceStorerIfNeeded(r.s, new, old)
1263 if err != nil {
1264 return updated, err
1265 }
1266
1267 if refUpdated {
1268 updated = true
1269 }
1270 }
1271 }
1272
1273 if tagMode == NoTags {
1274 return updated, nil
1275 }
1276
1277 tags := fetchedRefs

Callers 1

fetchMethod · 0.95

Calls 14

buildFetchedTagsMethod · 0.95
NewBranchReferenceNameFunction · 0.92
ResolveReferenceFunction · 0.92
NewHashReferenceFunction · 0.92
isFastForwardFunction · 0.85
IsWildcardMethod · 0.80
DstMethod · 0.80
IsTagMethod · 0.80
IsForceUpdateMethod · 0.80
TypeMethod · 0.65
NameMethod · 0.65

Tested by

no test coverage detected