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

Method updateLocalReferenceStorage

remote.go:1229–1304  ·  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

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