MCPcopy Create free account
hub / github.com/github/gh-aw / IsCompatible

Function IsCompatible

pkg/semverutil/semverutil.go:162–183  ·  view source on GitHub ↗

IsCompatible reports whether pinVersion is semver-compatible with requestedVersion. Semver compatibility is defined as both versions sharing the same major version. Examples: - IsCompatible("v5.0.0", "v5") → true - IsCompatible("v5.1.0", "v5.0.0") → true - IsCompatible("v6.0.0", "v5") → false

(pinVersion, requestedVersion string)

Source from the content-addressed store, hash-verified

160// - IsCompatible("v5.1.0", "v5.0.0") → true
161// - IsCompatible("v6.0.0", "v5") → false
162func IsCompatible(pinVersion, requestedVersion string) bool {
163 pinVersion = EnsureVPrefix(pinVersion)
164 requestedVersion = EnsureVPrefix(requestedVersion)
165
166 // Guard: both versions must be valid semver before comparing majors.
167 // semver.Major returns "" for invalid input, causing "" == "" to
168 // incorrectly report two invalid versions as compatible.
169 if !IsValid(pinVersion) || !IsValid(requestedVersion) {
170 semverLog.Printf("IsCompatible: one or both versions are invalid: pin=%s, requested=%s",
171 pinVersion, requestedVersion)
172 return false
173 }
174
175 pinMajor := semver.Major(pinVersion)
176 requestedMajor := semver.Major(requestedVersion)
177
178 compatible := pinMajor == requestedMajor
179 semverLog.Printf("Checking semver compatibility: pin=%s (major=%s), requested=%s (major=%s) -> %v",
180 pinVersion, pinMajor, requestedVersion, requestedMajor, compatible)
181
182 return compatible
183}

Callers 4

findCompatiblePinFunction · 0.92
ResolveSHAMethod · 0.92
TestIsCompatibleFunction · 0.85

Calls 3

EnsureVPrefixFunction · 0.85
IsValidFunction · 0.85
PrintfMethod · 0.45

Tested by 2

TestIsCompatibleFunction · 0.68