github.com/ungtb10d/git-lfs@v2.5.2+incompatible/lfs/gitscanner_remotes.go (about) 1 package lfs 2 3 import ( 4 "github.com/git-lfs/git-lfs/git" 5 "github.com/git-lfs/git-lfs/tools" 6 ) 7 8 // calcSkippedRefs checks that locally cached versions of remote refs are still 9 // present on the remote before they are used as a 'from' point. If the server 10 // implements garbage collection and a remote branch had been deleted since we 11 // last did 'git fetch --prune', then the objects in that branch may have also 12 // been deleted on the server if unreferenced. If some refs are missing on the 13 // remote, use a more explicit diff command. 14 func calcSkippedRefs(remote string) []string { 15 cachedRemoteRefs, _ := git.CachedRemoteRefs(remote) 16 actualRemoteRefs, _ := git.RemoteRefs(remote) 17 18 // Only check for missing refs on remote; if the ref is different it has moved 19 // forward probably, and if not and the ref has changed to a non-descendant 20 // (force push) then that will cause a re-evaluation in a subsequent command. 21 missingRefs := tools.NewStringSet() 22 for _, cachedRef := range cachedRemoteRefs { 23 found := false 24 for _, realRemoteRef := range actualRemoteRefs { 25 if cachedRef.Type == realRemoteRef.Type && cachedRef.Name == realRemoteRef.Name { 26 found = true 27 break 28 } 29 } 30 if !found { 31 missingRefs.Add(cachedRef.Name) 32 } 33 } 34 35 if len(missingRefs) == 0 { 36 return nil 37 } 38 39 skippedRefs := make([]string, 0, len(cachedRemoteRefs)-missingRefs.Cardinality()) 40 for _, cachedRef := range cachedRemoteRefs { 41 if !missingRefs.Contains(cachedRef.Name) { 42 skippedRefs = append(skippedRefs, "^"+cachedRef.Sha) 43 } 44 } 45 return skippedRefs 46 }