github: resolve SSH host aliases when classifying remotes#312494
Open
maruthang wants to merge 1 commit intomicrosoft:mainfrom
Open
github: resolve SSH host aliases when classifying remotes#312494maruthang wants to merge 1 commit intomicrosoft:mainfrom
maruthang wants to merge 1 commit intomicrosoft:mainfrom
Conversation
Contributor
📬 CODENOTIFYThe following users are being notified based on files changed in this PR: @lszomoruMatched files:
|
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.
Fixes #283245
Problem
When a user's
~/.ssh/configdefines a customHostalias for github.com (e.g.Host gh-personal->HostName github.com), their git remotes look likegit@gh-personal:owner/repo.git. The GitHub extension'sgetRepositoryFromUrlonly matched the literalgithub.com, sorepositoryHasGitHubRemote()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
extensions/github/src/sshConfig.tsparseSshConfig(text)- literal-alias parser; skips*/?/!patterns.SshConfigHostResolver- lazily reads~/.ssh/configplus/etc/ssh/ssh_configon POSIX, caches the parsed map, exposesresolveSync(alias).sharedSshConfigHostResolversingleton.util.ts-getRepositoryFromUrl(url, sshResolver = sharedSshConfigHostResolver)keeps its synchronous signature and gains a genericgit@<host>:<owner>/<repo>fallback that returns{ owner, repo }only when<host>resolves to literalgithub.comvia the resolver. The default-injected resolver keeps the function unit-testable.extension.ts::activate- callssharedSshConfigHostResolver.load()once on activation so the synchronous lookup has data.Scope
github.comare recognized - GitHub Enterprise hosts are intentionally not auto-recognized.~/.ssh/configfails silently, preserving current behavior for users without one.Tests
extensions/github/src/test/sshConfig.test.tscovers:parseSshConfig: simple blocks, multi-block, multi-aliasHostlines, wildcard skip, case-insensitive=separators, comments, duplicate-alias precedence.getRepositoryFromUrlwith an injected stub resolver: literal github.com, alias -> github.com, alias -> non-github host, unknown alias.