Fix Git version check to handle Windows formatting

- Update Test-GitVersion to properly parse Git versions with Windows suffixes
- Handle formats like '2.52.0.windows.1' correctly
- Parse major and minor version numbers separately for accurate comparison
- Now correctly identifies versions 2.23+ regardless of Windows-specific suffixes
- Add better error message when version parsing fails
This commit is contained in:
Bjarke Sporring
2026-01-14 16:56:29 +01:00
parent 734b49bc7d
commit 14cfc2feeb

View File

@@ -185,17 +185,24 @@ function Test-GitVersion {
}
$version = Get-InstalledVersion 'git'
if ($version -match 'git version (\d+\.\d+)') {
$versionNumber = [decimal]$matches[1]
if ($versionNumber -ge 2.23) {
# Parse Git version from various formats:
# "git version 2.52.0", "git version 2.52.0.windows.1", etc.
if ($version -match 'git version (\d+)\.(\d+)') {
$majorVersion = [int]$matches[1]
$minorVersion = [int]$matches[2]
# Check if version is 2.23 or higher
if ($majorVersion -gt 2 -or ($majorVersion -eq 2 -and $minorVersion -ge 23)) {
return $true
}
else {
Write-Warning "Git version $versionNumber is below required version 2.23"
Write-Warning "Git version $majorVersion.$minorVersion is below required version 2.23"
return $false
}
}
Write-Warning "Could not parse Git version from: $version"
return $false
}