Skip to content

Fix Git sync failing when ssh config has VisualHostKey=yes#309367

Open
yogeshwaran-c wants to merge 1 commit intomicrosoft:mainfrom
yogeshwaran-c:fix/git-ssh-visual-host-key-247862
Open

Fix Git sync failing when ssh config has VisualHostKey=yes#309367
yogeshwaran-c wants to merge 1 commit intomicrosoft:mainfrom
yogeshwaran-c:fix/git-ssh-visual-host-key-247862

Conversation

@yogeshwaran-c
Copy link
Copy Markdown
Contributor

What kind of change does this PR introduce?

Bug fix.

What is the current behavior?

When a user sets VisualHostKey yes in their ~/.ssh/config, OpenSSH
prints an ASCII-art fingerprint of the remote host key to stderr on
every connect. The git extension was treating any stderr output from
certain local git commands as a failure signal, which caused Git: Sync
(and other flows) to fail even though the underlying git command
actually succeeded.

The behavior was most visible when syncing after first publishing a
branch - running the same git push/git pull in a terminal worked,
but the VS Code command surfaced an error dialog.

Fixes #247862.

What is the new behavior?

Three call sites in extensions/git/src/git.ts were using non-empty
stderr as a failure signal regardless of the process exit code:

  • getDefaultBranch (symbolic-ref)
  • revList (rev-list)
  • revParse (rev-parse)

These now rely on the non-zero exit code already surfaced by the shared
exec() helper to detect real failures, and fall back to checking
stdout to decide success. Any informational noise emitted on stderr
by ssh (VisualHostKey output, banners, etc.) is now ignored.

Additional context

  • No behavior change when stderr is empty (the common case) or when the
    command exits non-zero (error is thrown as before).
  • The fix follows the same pattern already used elsewhere in git.ts
    (e.g. checkIfMaybeRebased), which uses result.exitCode rather
    than result.stderr to determine success.

When users set `VisualHostKey yes` in their ssh config, ssh prints an
ASCII-art fingerprint to stderr on connect. Three call sites in the git
extension were treating any stderr content (regardless of exit code) as
a failure signal, causing `Git: Sync` to fail even though the underlying
git command succeeded.

Rely on the non-zero exit code already surfaced by `exec()` to detect
real failures, and only use stdout content to determine success in
`getDefaultBranch`, `revList`, and `revParse`.

Fixes microsoft#247862
@vs-code-engineering
Copy link
Copy Markdown
Contributor

📬 CODENOTIFY

The following users are being notified based on files changed in this PR:

@lszomoru

Matched files:

  • extensions/git/src/git.ts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Git "sync" fails when ssh config has "VisualHostKey=yes"

2 participants