2016-11-16 23:05:03 +00:00
|
|
|
package lfs
|
|
|
|
|
|
|
|
import (
|
2021-08-10 06:18:38 +00:00
|
|
|
"github.com/git-lfs/git-lfs/v2/git"
|
|
|
|
"github.com/git-lfs/git-lfs/v2/tools"
|
2016-11-16 23:05:03 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// calcSkippedRefs checks that locally cached versions of remote refs are still
|
|
|
|
// present on the remote before they are used as a 'from' point. If the server
|
|
|
|
// implements garbage collection and a remote branch had been deleted since we
|
|
|
|
// last did 'git fetch --prune', then the objects in that branch may have also
|
|
|
|
// been deleted on the server if unreferenced. If some refs are missing on the
|
|
|
|
// remote, use a more explicit diff command.
|
|
|
|
func calcSkippedRefs(remote string) []string {
|
|
|
|
cachedRemoteRefs, _ := git.CachedRemoteRefs(remote)
|
|
|
|
actualRemoteRefs, _ := git.RemoteRefs(remote)
|
|
|
|
|
2020-07-02 05:50:48 +00:00
|
|
|
// The set of remote refs can be very large. Since CachedRemoteRefs only
|
|
|
|
// returns branches, filter the remote refs and convert them to a set for
|
|
|
|
// faster lookups in the skip calculation loop.
|
|
|
|
actualRemoteBranchRefs := tools.NewStringSet()
|
|
|
|
for _, ref := range actualRemoteRefs {
|
|
|
|
if ref.Type == git.RefTypeRemoteBranch {
|
|
|
|
actualRemoteBranchRefs.Add(ref.Name)
|
2016-11-16 23:05:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-02 05:50:48 +00:00
|
|
|
// Only check for missing refs on remote; if the ref is different it has moved
|
|
|
|
// forward probably, and if not and the ref has changed to a non-descendant
|
|
|
|
// (force push) then that will cause a re-evaluation in a subsequent command.
|
|
|
|
var skippedRefs []string
|
2016-11-16 23:05:03 +00:00
|
|
|
for _, cachedRef := range cachedRemoteRefs {
|
2020-07-02 05:50:48 +00:00
|
|
|
if actualRemoteBranchRefs.Contains(cachedRef.Name) {
|
2016-11-16 23:05:03 +00:00
|
|
|
skippedRefs = append(skippedRefs, "^"+cachedRef.Sha)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return skippedRefs
|
|
|
|
}
|