Fix version comparison to handle Git version strings correctly

Co-authored-by: DRSDavidSoft <4673812+DRSDavidSoft@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2025-11-08 21:00:30 +00:00
parent c039d977c2
commit f6adae5fb2

View File

@@ -53,14 +53,22 @@ function Compare-Version {
if ($null -eq $UserVersion) { return -1 } if ($null -eq $UserVersion) { return -1 }
if ($null -eq $VendorVersion) { return 1 } if ($null -eq $VendorVersion) { return 1 }
try { # Extract all numeric parts from version strings (e.g., "2.49.0.windows.1" -> 2, 49, 0, 1)
$userVer = [version]$UserVersion # This handles Git version strings like "2.49.0.windows.1" correctly
$vendorVer = [version]$VendorVersion $userParts = [regex]::Matches($UserVersion, '\d+') | ForEach-Object { [int]$_.Value }
return $userVer.CompareTo($vendorVer) $vendorParts = [regex]::Matches($VendorVersion, '\d+') | ForEach-Object { [int]$_.Value }
} catch {
# Fallback to string comparison if version parsing fails # Compare each numeric part sequentially
return [string]::Compare($UserVersion, $VendorVersion) $maxLength = [Math]::Max($userParts.Count, $vendorParts.Count)
for ($i = 0; $i -lt $maxLength; $i++) {
$userPart = if ($i -lt $userParts.Count) { $userParts[$i] } else { 0 }
$vendorPart = if ($i -lt $vendorParts.Count) { $vendorParts[$i] } else { 0 }
if ($userPart -gt $vendorPart) { return 1 }
if ($userPart -lt $vendorPart) { return -1 }
} }
return 0
} }
function Compare-GitVersion { function Compare-GitVersion {