Skip to content

Commit

Permalink
(git.install) Terminate gpg-agent instances within both BeforeModify …
Browse files Browse the repository at this point in the history
…and Install scripts, as workaround for chocolatey/choco#1092
  • Loading branch information
brogers5 committed Jul 5, 2022
1 parent 68acddc commit 0feb48f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 16 deletions.
19 changes: 3 additions & 16 deletions automatic/git.install/tools/chocolateyBeforeModify.ps1
Original file line number Diff line number Diff line change
@@ -1,17 +1,4 @@
$processName = 'gpg-agent*'
$process = Get-Process -Name $processName
$toolsPath = Split-Path $MyInvocation.MyCommand.Definition
. $toolsPath\helpers.ps1

if ($process) {
Write-Warning "Stopping GPG Agent to prevent git upgrade/uninstall failure..."
Stop-Process -InputObject $process

Start-Sleep -Seconds 3

$process = Get-Process -Name $processName
if ($process) {
Write-Warning "Killing GPG Agent to prevent git upgrade/uninstall failure..."
Stop-Process -InputObject $process -Force
}

Write-Warning "GPG Agent will not be started by the package after upgradeing..."
}
Stop-GitGPGAgent
2 changes: 2 additions & 0 deletions automatic/git.install/tools/chocolateyInstall.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ $toolsPath = Split-Path $MyInvocation.MyCommand.Definition
$pp = Get-PackageParameters

Stop-GitSSHAgent
# Workaround for chocolateyBeforeModify.ps1 being bypassed if upgrading via metapackage (chocolatey/choco#1092)
Stop-GitGPGAgent

$fileName32 = 'Git-2.36.1-32-bit.exe'
$fileName64 = 'Git-2.36.1-64-bit.exe'
Expand Down
8 changes: 8 additions & 0 deletions automatic/git.install/tools/helpers.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,11 @@ function Stop-GitSSHAgent()
Write-Host "Killing any running git ssh-agent instances"
Get-Process ssh-agent | Where-Object {$_.Path -ilike "*\git\usr\bin\*"} | Stop-Process
}

function Stop-GitGPGAgent()
{
if (!(Get-Process gpg-agent -ea 0)) { return }

Write-Host "Killing any running gpg-agent instances"
Get-Process gpg-agent | Where-Object {$_.Path -ilike "*\git\usr\bin\*"} | Stop-Process -Force
}

0 comments on commit 0feb48f

Please sign in to comment.