Skip to content

github: resolve SSH host aliases when classifying remotes#312494

Open
maruthang wants to merge 1 commit intomicrosoft:mainfrom
maruthang:fix/issue-283245-ssh-config-host-alias
Open

github: resolve SSH host aliases when classifying remotes#312494
maruthang wants to merge 1 commit intomicrosoft:mainfrom
maruthang:fix/issue-283245-ssh-config-host-alias

Conversation

@maruthang
Copy link
Copy Markdown
Contributor

Fixes #283245

Problem

When a user's ~/.ssh/config defines a custom Host alias for github.com (e.g. Host gh-personal -> HostName github.com), their git remotes look like git@gh-personal:owner/repo.git. The GitHub extension's getRepositoryFromUrl only matched the literal github.com, so repositoryHasGitHubRemote() returned false and every GitHub feature (Open on GitHub, status-bar Copilot indexed badge, share providers, branch protection, hover commands, etc.) silently disabled for these users.

Fix

  1. New extensions/github/src/sshConfig.ts
    • parseSshConfig(text) - literal-alias parser; skips */?/! patterns.
    • SshConfigHostResolver - lazily reads ~/.ssh/config plus /etc/ssh/ssh_config on POSIX, caches the parsed map, exposes resolveSync(alias).
    • Module-level sharedSshConfigHostResolver singleton.
  2. util.ts - getRepositoryFromUrl(url, sshResolver = sharedSshConfigHostResolver) keeps its synchronous signature and gains a generic git@<host>:<owner>/<repo> fallback that returns { owner, repo } only when <host> resolves to literal github.com via the resolver. The default-injected resolver keeps the function unit-testable.
  3. extension.ts::activate - calls sharedSshConfigHostResolver.load() once on activation so the synchronous lookup has data.

Scope

  • Only aliases mapping to literal github.com are recognized - GitHub Enterprise hosts are intentionally not auto-recognized.
  • Missing or unreadable ~/.ssh/config fails silently, preserving current behavior for users without one.
  • No new dependencies. Only the GitHub extension is touched.

Tests

extensions/github/src/test/sshConfig.test.ts covers:

  • parseSshConfig: simple blocks, multi-block, multi-alias Host lines, wildcard skip, case-insensitive = separators, comments, duplicate-alias precedence.
  • getRepositoryFromUrl with an injected stub resolver: literal github.com, alias -> github.com, alias -> non-github host, unknown alias.

@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/github/src/extension.ts
  • extensions/github/src/sshConfig.ts
  • extensions/github/src/test/sshConfig.test.ts
  • extensions/github/src/util.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.

Better support for GitHub code search in repos with custom remotes

3 participants