Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make SSH_AGENT_PID mapping to Windows PID #699

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions src/GitUtils.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -401,14 +401,26 @@ function Get-SshAgent() {
else {
$agentPid = $Env:SSH_AGENT_PID
if ($agentPid) {
$sshAgentProcess = Get-Process | Where-Object { ($_.Id -eq $agentPid) -and ($_.Name -eq 'ssh-agent') }
if ($null -ne $sshAgentProcess) {
return $agentPid
# Convert cygwin PID to Windows PID
$ps = Find-Ssh('ps')
if (!$ps) {
Write-Warning 'Could not find ps'
return 0
}
else {
setenv 'SSH_AGENT_PID' $null
setenv 'SSH_AUTH_SOCK' $null
$pidMap = @{ }
(& $ps) | Select-Object -skip 1 | ForEach-Object {
$line = ($_ -split "\s+" -match "\S")
$pidMap[$line[0]] = $line[3]
}
$winPid = $pidMap[$agentPid]
if ($winPid) {
$sshAgentProcess = Get-Process | Where-Object { ($_.Id -eq $winPid) -and ($_.Name -eq 'ssh-agent') }
if ($null -ne $sshAgentProcess) {
return $winPid
}
}
setenv 'SSH_AGENT_PID' $null
setenv 'SSH_AUTH_SOCK' $null
}
}

Expand All @@ -421,7 +433,7 @@ function Get-NativeSshAgent {
# The ssh.exe binary version must include "OpenSSH"
# The windows ssh-agent service must exist
$service = Get-Service ssh-agent -ErrorAction Ignore
$executableMatches = Get-Command ssh.exe | ForEach-Object FileVersionInfo | Where-Object ProductVersion -match OpenSSH
$executableMatches = Get-Command ssh.exe -ErrorAction Ignore | ForEach-Object FileVersionInfo | Where-Object ProductVersion -match OpenSSH
$valid = $service -and $executableMatches
if ($valid) {
return $service;
Expand Down