Fix version parsing in Install-Package for Windows Git format

- Update regex to extract only semantic version numbers (x.y.z)
- Prevents matching entire string like '2.52.0.windows.1'
- Uses '^(\d+(?:\.\d+){1,2})' to match version at start of string only
- Extracts '2.52.0' from '2.52.0.windows.1' for proper version comparison
- Handles Windows Git version suffixes correctly
- Maintains compatibility with standard version formats
This commit is contained in:
Bjarke Sporring
2026-01-14 17:24:33 +01:00
parent 07faa14b7a
commit c28151cc19

View File

@@ -129,9 +129,11 @@ function Install-Package {
Write-Success "$Name is already installed: $version"
if ($MinVersion -and $version) {
# Basic version check (not perfect but good enough for common cases)
if ($version -match '(\d+\.[\d.]+)') {
# Extract semantic version numbers only - stop before any non-digit/non-dot characters
# This extracts "2.52.0" from "2.52.0.windows.1"
if ($version -match '^(\d+(?:\.\d+){1,2})') {
$installedVersion = $matches[1]
try {
if ([version]$installedVersion -lt [version]$MinVersion) {
Write-Warning "Version $installedVersion is below minimum required version $MinVersion"
Write-Host " Attempting to upgrade..." -ForegroundColor Cyan
@@ -140,6 +142,16 @@ function Install-Package {
return $true
}
}
catch {
Write-Warning "Version comparison failed - assuming sufficient version"
return $true
}
}
else {
Write-Warning "Could not parse version from: $version"
Write-Host " Assuming installed version is sufficient..." -ForegroundColor Cyan
return $true
}
}
else {
return $true