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 #968

Open
wants to merge 1 commit into
base: v0
Choose a base branch
from
Open
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
28 changes: 20 additions & 8 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 Down Expand Up @@ -505,12 +517,12 @@ function Find-Ssh($program = 'ssh-agent') {
return
}

$sshLocation = join-path $gitItem.directory.parent.fullname bin/$program
$sshLocation = join-path $gitItem.directory.parent.fullname[0] bin/$program
if (get-command $sshLocation -Erroraction SilentlyContinue) {
return $sshLocation
}

$sshLocation = join-path $gitItem.directory.parent.fullname usr/bin/$program
$sshLocation = join-path $gitItem.directory.parent.fullname[0] usr/bin/$program
if (get-command $sshLocation -Erroraction SilentlyContinue) {
return $sshLocation
}
Expand Down