Revert "[Windows] Removed Git internal tools from PATH"

This commit is contained in:
Aleksandr Chebotov
2020-11-05 11:39:54 +03:00
committed by GitHub
parent ac4f5699c7
commit 635a57ab88
10 changed files with 40 additions and 127 deletions

View File

@@ -1,23 +0,0 @@
# Create shells folder
$shellPath = "C:\shells"
New-Item -Path $shellPath -ItemType Directory | Out-Null
# sh and bash <--> C:\msys64\usr\bin\bash.exe
New-Item -ItemType SymbolicLink -Path "$shellPath\bash.exe" -Target "C:\msys64\usr\bin\bash.exe" | Out-Null
New-Item -ItemType SymbolicLink -Path "$shellPath\sh.exe" -Target "C:\msys64\usr\bin\sh.exe" | Out-Null
# WSL is available on Windows Server 2019
if (Test-IsWin19)
{
# winbash <--> C:\Windows\System32\bash.exe
New-Item -ItemType SymbolicLink -Path "$shellPath\winbash.exe" -Target "$env:SystemRoot\System32\bash.exe" | Out-Null
}
# gitbash <--> C:\Program Files\Git\bin\bash.exe
New-Item -ItemType SymbolicLink -Path "$shellPath\gitbash.exe" -Target "$env:ProgramFiles\Git\bin\bash.exe" | Out-Null
# msysbash <--> C:\msys64\usr\bin\bash.exe
New-Item -ItemType SymbolicLink -Path "$shellPath\msysbash.exe" -Target "C:\msys64\usr\bin\bash.exe" | Out-Null
# Add shells to PATH
Add-MachinePathItem $shellPath

View File

@@ -26,7 +26,7 @@ Install-Binary -Url $downloadUrl `
"/SP-", ` "/SP-", `
"/CLOSEAPPLICATIONS", ` "/CLOSEAPPLICATIONS", `
"/RESTARTAPPLICATIONS", ` "/RESTARTAPPLICATIONS", `
"/o:PathOption=Cmd", ` "/o:PathOption=CmdTools", `
"/o:BashTerminalOption=ConHost", ` "/o:BashTerminalOption=ConHost", `
"/o:EnableSymlinks=Enabled", ` "/o:EnableSymlinks=Enabled", `
"/COMPONENTS=gitlfs") "/COMPONENTS=gitlfs")
@@ -36,5 +36,15 @@ Choco-Install -PackageName hub
# Disable GCM machine-wide # Disable GCM machine-wide
[Environment]::SetEnvironmentVariable("GCM_INTERACTIVE", "Never", [System.EnvironmentVariableTarget]::Machine) [Environment]::SetEnvironmentVariable("GCM_INTERACTIVE", "Never", [System.EnvironmentVariableTarget]::Machine)
Add-MachinePathItem "C:\Program Files\Git\bin"
if (Test-IsWin16) {
$env:Path += ";$env:ProgramFiles\Git\usr\bin\"
}
# Add well-known SSH host keys to ssh_known_hosts
ssh-keyscan -t rsa github.com >> "C:\Program Files\Git\etc\ssh\ssh_known_hosts"
ssh-keyscan -t rsa ssh.dev.azure.com >> "C:\Program Files\Git\etc\ssh\ssh_known_hosts"
Invoke-PesterTests -TestFile "Git" -TestName "Git" Invoke-PesterTests -TestFile "Git" -TestName "Git"
Invoke-PesterTests -TestFile "CLI.Tools" -TestName "Hub CLI" Invoke-PesterTests -TestFile "CLI.Tools" -TestName "Hub CLI"

View File

@@ -7,7 +7,7 @@ Choco-Install -PackageName mingw
# Make a copy of mingw32-make.exe to make.exe, which is a more discoverable name # Make a copy of mingw32-make.exe to make.exe, which is a more discoverable name
# and so the same command line can be used on Windows as on macOS and Linux # and so the same command line can be used on Windows as on macOS and Linux
$path = Get-Command mingw32-make.exe -CommandType All | Where-Object { $_.Path.Contains("C:\ProgramData\Chocolatey") } | Get-Item $path = where.exe mingw32-make.exe | Get-Item
Copy-Item -Path $path -Destination (Join-Path $path.Directory 'make.exe') Copy-Item -Path $path -Destination (Join-Path $path.Directory 'make.exe')
Invoke-PesterTests -TestFile "Tools" -TestName "Mingw64" Invoke-PesterTests -TestFile "Tools" -TestName "Mingw64"

View File

@@ -9,19 +9,35 @@
$dash = "-" * 40 $dash = "-" * 40
# Downloading msys2 $origPath = $env:PATH
$msys2Release = "https://api.github.com/repos/msys2/msys2-installer/releases/latest" $gitPath = "$env:ProgramFiles\Git"
$msys2Uri = ((Invoke-RestMethod $msys2Release).assets | Where-Object {
$_.name -match "x86_64" -and $_.name.EndsWith("sfx.exe") }).browser_download_url
$msys2File = Start-DownloadWithRetry -Url $msys2Uri
# extract sfx.exe to C:\ $msys2_release = "https://api.github.com/repos/msys2/msys2-installer/releases/latest"
$msys2Uri = ((Invoke-RestMethod $msys2_release).assets | Where-Object {
$_.name -match "x86_64" -and $_.name.EndsWith("tar.xz") }).browser_download_url
# Download the latest msys2 x86_64, filename includes release date
Write-Host "Starting msys2 download using $($msys2Uri.split('/')[-1])"
$msys2File = Start-DownloadWithRetry -Url $msys2Uri
Write-Host "Finished download"
# nix style path for tar
$msys2FileU = "/$msys2File".replace(':', '').replace('\', '/')
# Git tar needs exe's from mingw64\bin
$env:PATH = "$gitPath\usr\bin;$gitPath\mingw64\bin;$origPath"
$tar = "$gitPath\usr\bin\tar.exe"
# extract tar.xz to C:\
Write-Host "Starting msys2 extraction" Write-Host "Starting msys2 extraction"
& $msys2File -y -oC:\ &$tar -xJf $msys2FileU -C /c/
Remove-Item $msys2File
Write-Host "Finished extraction" Write-Host "Finished extraction"
# Add msys2 bin tools folders to PATH temporary # Add msys2 bin tools folders to PATH temporary
$env:PATH = "C:\msys64\mingw64\bin;C:\msys64\usr\bin;$env:PATH" $env:PATH = "C:\msys64\mingw64\bin;C:\msys64\usr\bin;$origPath"
Write-Host "`n$dash bash pacman-key --init" Write-Host "`n$dash bash pacman-key --init"
bash.exe -c "pacman-key --init 2>&1" bash.exe -c "pacman-key --init 2>&1"
@@ -57,10 +73,6 @@ Write-Host "`n$dash Install mingw32 packages"
$pre = "mingw-w64-i686-" $pre = "mingw-w64-i686-"
pacman.exe -S --noconfirm --needed --noprogressbar $tools32.replace('___', $pre).split(' ') pacman.exe -S --noconfirm --needed --noprogressbar $tools32.replace('___', $pre).split(' ')
# install openssh
Write-Host "`n$dash Install openssh package"
pacman.exe -S --noconfirm --needed --noprogressbar openssh
# clean all packages to decrease image size # clean all packages to decrease image size
Write-Host "`n$dash Clean packages" Write-Host "`n$dash Clean packages"
pacman.exe -Scc --noconfirm pacman.exe -Scc --noconfirm
@@ -76,23 +88,4 @@ pacman.exe -Q | grep -v ^mingw-w64-
Write-Host "`nMSYS2 installation completed" Write-Host "`nMSYS2 installation completed"
# Environment
# add C:\msys64\mingw64\bin and C:\msys64\usr\bin to PATH
# C:\msys64\mingw64\bin add after C:\Windows\System32 to not replace built-in tar.exe
$regEnvKey = 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\'
$pathValue = Get-ItemPropertyValue -Path $regEnvKey -Name 'Path'
$pathValue += ";C:\msys64\mingw64\bin;C:\msys64\usr\bin"
Set-ItemProperty -Path $regEnvKey -Name 'Path' -Value $pathValue
# Add well-known SSH host keys to ssh_known_hosts to Msys2
ssh-keyscan -t rsa github.com >> "C:\msys64\etc\ssh\ssh_known_hosts"
ssh-keyscan -t rsa ssh.dev.azure.com >> "C:\msys64\etc\ssh\ssh_known_hosts"
# Add well-known SSH host keys to ssh_known_hosts to Git
if (Test-Path "C:\Program Files\Git\etc\ssh")
{
ssh-keyscan -t rsa github.com >> "C:\Program Files\Git\etc\ssh\ssh_known_hosts"
ssh-keyscan -t rsa ssh.dev.azure.com >> "C:\Program Files\Git\etc\ssh\ssh_known_hosts"
}
Invoke-PesterTests -TestFile "MSYS2" Invoke-PesterTests -TestFile "MSYS2"

View File

@@ -282,13 +282,6 @@ function Get-PacmanVersion {
return "- Pacman $pacmanVersion" return "- Pacman $pacmanVersion"
} }
function Get-ShellTarget {
$shells = Get-ChildItem C:\shells -File | Select-Object @{n="Name";e={
$name = $_.Name
if ($name -eq 'bash.exe') {"$name (Default)"} else {$name}}},@{n="Target";e={@($_.Target)[0]}} | Sort-Object Name
$shells | New-MDTable -Columns ([ordered]@{Name = "left"; Target = "left";})
}
function Get-YAMLLintVersion { function Get-YAMLLintVersion {
yamllint --version yamllint --version
} }

View File

@@ -143,22 +143,14 @@ $markdown += New-MDList -Style Unordered -Lines @(
(Get-SeleniumWebDriverVersion -Driver "iexplorer") (Get-SeleniumWebDriverVersion -Driver "iexplorer")
) )
$markdown += New-MDHeader "Shells" -Level 3
$markdown += Get-ShellTarget
$markdown += New-MDNewLine
$markdown += New-MDHeader "MSYS2" -Level 3 $markdown += New-MDHeader "MSYS2" -Level 3
$markdown += Get-PacmanVersion $markdown += Get-PacmanVersion
$markdown += New-MDNewLine $markdown += New-MDNewLine
$markdown += New-MDHeader "Notes:" -Level 5
$markdown += @' $markdown += @'
``` ```
Location: C:\msys64 Location: C:\msys64
1. MSYS2 is pre-installed on image Note: MSYS2 is pre-installed on image but not added to PATH.
2. C:\msys64\mingw64\bin is added to PATH and has lower precedence than C:\Windows\System32
3. C:\msys64\usr\bin is added to PATH and has lower precedence than C:\Windows\System32
4. Default bash.exe shell is set to the C:\msys64\usr\bin\bash.exe
``` ```
'@ '@
$markdown += New-MDNewLine $markdown += New-MDNewLine

View File

@@ -1,5 +1,5 @@
Describe "Git" { Describe "Git" {
$gitTools = 'git', 'git-lfs' $gitTools = 'bash', 'awk', 'git', 'git-lfs'
$gitTestCases = $gitTools | ForEach-Object { $gitTestCases = $gitTools | ForEach-Object {
@{ @{
toolName = $_ toolName = $_

View File

@@ -1,50 +0,0 @@
Describe "Shell" {
$shellTestCases = @(
@{Name = "C:\shells\bash.exe"; Target = "C:\msys64\usr\bin\bash.exe"},
@{Name = "C:\shells\sh.exe"; Target = "C:\msys64\usr\bin\sh.exe"},
@{Name = "C:\shells\gitbash.exe"; Target = "$env:ProgramFiles\Git\bin\bash.exe"},
@{Name = "C:\shells\msysbash.exe"; Target = "C:\msys64\usr\bin\bash.exe"}
)
$pathTestCases = @(
@{Path = "C:\shells"},
@{Path = "C:\msys64\mingw64\bin"},
@{Path = "C:\msys64\usr\bin"}
)
$IsWin16 = Test-IsWin16
It "Default bash.exe from MSYS2" {
(Get-Command bash).Path | Should -BeExactly "C:\shells\bash.exe"
}
It "Default sh.exe from MSYS2" {
(Get-Command sh).Path | Should -BeExactly "C:\shells\sh.exe"
}
It "Folder C:\shells exists" {
"C:\shells" | Should -Exist
}
It "C:\Windows\System32 before C:\msys64\mingw64\bin and C:\msys64\usr\bin" {
$path = $env:Path.Split(";").ToLower()
$indexOfSystem32 = $path.IndexOf("c:\windows\system32")
$path.IndexOf("c:\msys64\mingw64\bin") | Should -BeGreaterThan $indexOfSystem32
$path.IndexOf("c:\msys64\usr\bin") | Should -BeGreaterThan $indexOfSystem32
}
It "C:\shells\winbash.exe target to $env:SystemRoot\System32\bash.exe" -Skip:$IsWin16 {
$Name = "C:\shells\winbash.exe"
$Target = "$env:SystemRoot\System32\bash.exe"
(Get-Item $Name).Target | Should -BeExactly $Target
}
It "<Name> target to <Target>" -TestCases $shellTestCases {
(Get-Item $Name).Target | Should -BeExactly $Target
}
It "<Path> is in PATH" -TestCases $pathTestCases {
$env:Path.Split(";") | Should -Contain $Path
}
}

View File

@@ -333,8 +333,7 @@
"type": "powershell", "type": "powershell",
"scripts": [ "scripts": [
"{{ template_dir }}/scripts/Installers/Install-WindowsUpdates.ps1", "{{ template_dir }}/scripts/Installers/Install-WindowsUpdates.ps1",
"{{ template_dir }}/scripts/Installers/Configure-DynamicPort.ps1", "{{ template_dir }}/scripts/Installers/Configure-DynamicPort.ps1"
"{{ template_dir }}/scripts/Installers/Configure-Shell.ps1"
], ],
"elevated_user": "{{user `install_user`}}", "elevated_user": "{{user `install_user`}}",
"elevated_password": "{{user `install_password`}}" "elevated_password": "{{user `install_password`}}"

View File

@@ -331,8 +331,7 @@
"type": "powershell", "type": "powershell",
"scripts": [ "scripts": [
"{{ template_dir }}/scripts/Installers/Install-WindowsUpdates.ps1", "{{ template_dir }}/scripts/Installers/Install-WindowsUpdates.ps1",
"{{ template_dir }}/scripts/Installers/Configure-DynamicPort.ps1", "{{ template_dir }}/scripts/Installers/Configure-DynamicPort.ps1"
"{{ template_dir }}/scripts/Installers/Configure-Shell.ps1"
], ],
"elevated_user": "{{user `install_user`}}", "elevated_user": "{{user `install_user`}}",
"elevated_password": "{{user `install_password`}}" "elevated_password": "{{user `install_password`}}"