mirror of
https://github.com/cmderdev/cmder.git
synced 2025-11-09 13:49:05 +08:00
Fix version comparison to handle Git version strings correctly
Co-authored-by: DRSDavidSoft <4673812+DRSDavidSoft@users.noreply.github.com>
This commit is contained in:
22
vendor/psmodules/Cmder.ps1
vendored
22
vendor/psmodules/Cmder.ps1
vendored
@@ -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 {
|
||||||
|
|||||||
Reference in New Issue
Block a user