Force Git version >= 2.35.2 (#57741)
This commit is contained in:
1 parent
3f0e350654
commit
e9e79b3ce4
1 file changed
+95
-59
+95
-59
@@ -23,12 +23,101 @@ if ($help) {
|
||||
exit
|
||||
}
|
||||
|
||||
# Check whether the script is present inside a fork/clone of microsoft/winget-pkgs repository
|
||||
try {
|
||||
$script:gitTopLevel = (Resolve-Path $(git rev-parse --show-toplevel)).Path
|
||||
} catch {
|
||||
# If there was an exception, the user isn't in a git repo. Throw a custom exception and pass the original exception as an InternalException
|
||||
throw [UnmetDependencyException]::new('This script must be run from inside a clone of the winget-pkgs repository', $_.Exception)
|
||||
# Custom menu prompt that listens for keypresses. Requires a prompt and array of entries at minimum. Entries preceeded with `*` are shown in green
|
||||
# Returns a console key value
|
||||
Function Invoke-KeypressMenu {
|
||||
Param
|
||||
(
|
||||
[Parameter(Mandatory = $true, Position = 0)]
|
||||
[string] $Prompt,
|
||||
[Parameter(Mandatory = $true, Position = 1)]
|
||||
[string[]] $Entries,
|
||||
[Parameter(Mandatory = $false)]
|
||||
[string] $HelpText,
|
||||
[Parameter(Mandatory = $false)]
|
||||
[string] $HelpTextColor,
|
||||
[Parameter(Mandatory = $false)]
|
||||
[string] $DefaultString
|
||||
)
|
||||
|
||||
Write-Host "`n"
|
||||
Write-Host -ForegroundColor 'Yellow' "$Prompt"
|
||||
if ($PSBoundParameters.ContainsKey('HelpText') -and (![string]::IsNullOrWhiteSpace($HelpText))) {
|
||||
if ($PSBoundParameters.ContainsKey('HelpTextColor') -and (![string]::IsNullOrWhiteSpace($HelpTextColor))) {
|
||||
Write-Host -ForegroundColor $HelpTextColor $HelpText
|
||||
} else {
|
||||
Write-Host -ForegroundColor 'Blue' $HelpText
|
||||
}
|
||||
}
|
||||
foreach ($entry in $Entries) {
|
||||
$_isDefault = $entry.StartsWith('*')
|
||||
if ($_isDefault) {
|
||||
$_entry = ' ' + $entry.Substring(1)
|
||||
$_color = 'Green'
|
||||
} else {
|
||||
$_entry = ' ' + $entry
|
||||
$_color = 'White'
|
||||
}
|
||||
Write-Host -ForegroundColor $_color $_entry
|
||||
}
|
||||
Write-Host
|
||||
if ($PSBoundParameters.ContainsKey('DefaultString') -and (![string]::IsNullOrWhiteSpace($DefaultString))) {
|
||||
Write-Host -NoNewline "Enter Choice (default is '$DefaultString'): "
|
||||
} else {
|
||||
Write-Host -NoNewline 'Enter Choice ('
|
||||
Write-Host -NoNewline -ForegroundColor 'Green' 'Green'
|
||||
Write-Host -NoNewline ' is default): '
|
||||
}
|
||||
|
||||
do {
|
||||
$keyInfo = [Console]::ReadKey($false)
|
||||
} until ($keyInfo.Key)
|
||||
|
||||
return $keyInfo.Key
|
||||
}
|
||||
|
||||
#If the user has git installed, make sure it is a patched version
|
||||
if (Get-Command 'git.exe' -ErrorAction SilentlyContinue) {
|
||||
$GitMinimumVersion = [System.Version]::Parse('2.35.2')
|
||||
$gitVersionString = ((git version) | Select-String '([0-9]{1,}\.){3,4}').Matches.Value.Trim(' ', '.')
|
||||
$gitVersion = [System.Version]::Parse($gitVersionString)
|
||||
if ($gitVersion -lt $GitMinimumVersion) {
|
||||
# Prompt user to install git
|
||||
if (Get-Command 'winget.exe' -ErrorAction SilentlyContinue) {
|
||||
$_menu = @{
|
||||
entries = @('[Y] Upgrade Git'; '[N] Do not upgrade')
|
||||
Prompt = 'The version of git installed on your machine does not satisfy the requirement of version >= 2.35.2; Would you like to upgrade?'
|
||||
HelpText = "Upgrading will attempt to upgrade git using winget`n"
|
||||
DefaultString = ''
|
||||
}
|
||||
switch (Invoke-KeypressMenu -Prompt $_menu['Prompt'] -Entries $_menu['Entries'] -DefaultString $_menu['DefaultString'] -HelpText $_menu['HelpText']) {
|
||||
'Y' {
|
||||
Write-Host
|
||||
try {
|
||||
winget upgrade --id Git.Git --exact
|
||||
} catch {
|
||||
throw [UnmetDependencyException]::new('Git could not be upgraded sucessfully', $_)
|
||||
} finally {
|
||||
$gitVersionString = ((git version) | Select-String '([0-9]{1,}\.){3,4}').Matches.Value.Trim(' ', '.')
|
||||
$gitVersion = [System.Version]::Parse($gitVersionString)
|
||||
if ($gitVersion -lt $GitMinimumVersion) {
|
||||
throw [UnmetDependencyException]::new('Git could not be upgraded sucessfully')
|
||||
}
|
||||
}
|
||||
}
|
||||
default { Write-Host; throw [UnmetDependencyException]::new('The version of git installed on your machine does not satisfy the requirement of version >= 2.35.2') }
|
||||
}
|
||||
} else {
|
||||
throw [UnmetDependencyException]::new('The version of git installed on your machine does not satisfy the requirement of version >= 2.35.2')
|
||||
}
|
||||
}
|
||||
# Check whether the script is present inside a fork/clone of microsoft/winget-pkgs repository
|
||||
try {
|
||||
$script:gitTopLevel = (Resolve-Path $(git rev-parse --show-toplevel)).Path
|
||||
} catch {
|
||||
# If there was an exception, the user isn't in a git repo. Throw a custom exception and pass the original exception as an InternalException
|
||||
throw [UnmetDependencyException]::new('This script must be run from inside a clone of the winget-pkgs repository', $_.Exception)
|
||||
}
|
||||
}
|
||||
|
||||
# Installs `powershell-yaml` as a dependency for parsing yaml content
|
||||
@@ -244,59 +333,6 @@ Function Write-MulticolorLine {
|
||||
}
|
||||
}
|
||||
|
||||
# Custom menu prompt that listens for keypresses. Requires a prompt and array of entries at minimum. Entries preceeded with `*` are shown in green
|
||||
# Returns a console key value
|
||||
Function Invoke-KeypressMenu {
|
||||
Param
|
||||
(
|
||||
[Parameter(Mandatory = $true, Position = 0)]
|
||||
[string] $Prompt,
|
||||
[Parameter(Mandatory = $true, Position = 1)]
|
||||
[string[]] $Entries,
|
||||
[Parameter(Mandatory = $false)]
|
||||
[string] $HelpText,
|
||||
[Parameter(Mandatory = $false)]
|
||||
[string] $HelpTextColor,
|
||||
[Parameter(Mandatory = $false)]
|
||||
[string] $DefaultString
|
||||
)
|
||||
|
||||
Write-Host "`n"
|
||||
Write-Host -ForegroundColor 'Yellow' "$Prompt"
|
||||
if ($PSBoundParameters.ContainsKey('HelpText') -and (![string]::IsNullOrWhiteSpace($HelpText))) {
|
||||
if ($PSBoundParameters.ContainsKey('HelpTextColor') -and (![string]::IsNullOrWhiteSpace($HelpTextColor))) {
|
||||
Write-Host -ForegroundColor $HelpTextColor $HelpText
|
||||
} else {
|
||||
Write-Host -ForegroundColor 'Blue' $HelpText
|
||||
}
|
||||
}
|
||||
foreach ($entry in $Entries) {
|
||||
$_isDefault = $entry.StartsWith('*')
|
||||
if ($_isDefault) {
|
||||
$_entry = ' ' + $entry.Substring(1)
|
||||
$_color = 'Green'
|
||||
} else {
|
||||
$_entry = ' ' + $entry
|
||||
$_color = 'White'
|
||||
}
|
||||
Write-Host -ForegroundColor $_color $_entry
|
||||
}
|
||||
Write-Host
|
||||
if ($PSBoundParameters.ContainsKey('DefaultString') -and (![string]::IsNullOrWhiteSpace($DefaultString))) {
|
||||
Write-Host -NoNewline "Enter Choice (default is '$DefaultString'): "
|
||||
} else {
|
||||
Write-Host -NoNewline 'Enter Choice ('
|
||||
Write-Host -NoNewline -ForegroundColor 'Green' 'Green'
|
||||
Write-Host -NoNewline ' is default): '
|
||||
}
|
||||
|
||||
do {
|
||||
$keyInfo = [Console]::ReadKey($false)
|
||||
} until ($keyInfo.Key)
|
||||
|
||||
return $keyInfo.Key
|
||||
}
|
||||
|
||||
# Checks a URL and returns the status code received from the URL
|
||||
Function Test-Url {
|
||||
Param
|
||||
|
||||
Reference in new issue
Block a user