fix(ps): drop ssh probe + correct exit-code check in Invoke-GhRepoClone#250
Closed
szymonos wants to merge 2 commits into
Closed
fix(ps): drop ssh probe + correct exit-code check in Invoke-GhRepoClone#250szymonos wants to merge 2 commits into
szymonos wants to merge 2 commits into
Conversation
Two follow-up fixes for code-review feedback on the SSH-first path introduced in #246: 1. Remove the `ssh -T git@github.com` probe in the begin block. It adds a network round-trip before every clone attempt, can block on host-key prompts (no entry in ~/.ssh/known_hosts), slow DNS, or firewall holes, and prompts for passphrase on encrypted keys. The catch block already retries SSH failures over HTTPS, so the probe was redundant defensive-ness. Protocol selection reverts to deriving from the parent repo's remote URL via `getOrigin` - SSH-configured parent repos still trigger SSH-first cloning, with the HTTPS retry as fallback. The Get-Command ssh guard added in #247 (for Windows hosts without OpenSSH) is no longer needed since there's no `ssh` invocation here. 2. Replace `git clone ... | ForEach-Object { ... }` + `if (-not $?)` with non-pipeline capture + `$LASTEXITCODE`. The pipeline made $? reflect ForEach-Object's success (always true), so failed clones were treated as successful: the HTTPS fallback never ran and callers received status=1 (cloned) when nothing was actually fetched. Now $LASTEXITCODE is consulted directly and the captured stdout+stderr is rendered into the warning via Out-String.
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two follow-up fixes for code-review feedback on the SSH-first path introduced in #246 (`modules/InstallUtils/Functions/git.ps1`).
1. Drop the `ssh -T git@github.com` probe
The probe ran on every `Invoke-GhRepoClone` call to decide between SSH and HTTPS. Three problems:
Protocol selection reverts to deriving from the parent repo's remote URL via `getOrigin` (the original pre-#246 behavior). SSH-configured parent repos still trigger SSH-first cloning, and the HTTPS retry remains as fallback.
The `Get-Command ssh` guard added in #247 (for Windows hosts without OpenSSH) is now obsolete — there's no bare `ssh` invocation to guard.
2. Replace pipeline `$?` check with `$LASTEXITCODE`
```powershell$?) { ... } # WRONG: $ ? reflects ForEach-Object (always true)
git clone $cloneUrl "$destPath" --quiet 2>&1 | ForEach-Object { $cloneErr += "$_`n" }
if (-not
```
The pipeline made `$?` reflect the tail (`ForEach-Object`, which always succeeds), so failed clones were treated as successful: the HTTPS fallback never ran and callers received `status=1` (cloned) when nothing was actually fetched. Now `$LASTEXITCODE` is consulted directly and captured stdout+stderr is rendered via `Out-String` for the warning text.
```powershell
$cloneOut = git clone $cloneUrl "$destPath" --quiet 2>&1
$cloneOk = $LASTEXITCODE -eq 0
if (-not $cloneOk -and $gitProtocol -eq 'git@github.com:') {
# ... HTTPS retry ...
}
```
Test plan
🤖 Generated with Claude Code