mirror of
https://github.com/microsoft/vscode.git
synced 2026-09-28 16:39:00 +01:00
Allow Continue On between repos with HTTPS and SSH remotes (#182352)
* Deduplicate HTTPS and SSH remote URLs * Improve doc
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { CancellationToken, CanonicalUriIdentityProvider, Disposable, Uri, workspace } from 'vscode';
|
||||
|
||||
const SUPPORTED_SCHEMES = ['ssh', 'https'];
|
||||
|
||||
export class GitHubCanonicalUriIdentityProvider implements CanonicalUriIdentityProvider {
|
||||
|
||||
private disposables: Disposable[] = [];
|
||||
constructor() {
|
||||
this.disposables.push(...SUPPORTED_SCHEMES.map((scheme) => workspace.registerCanonicalUriIdentityProvider(scheme, this)));
|
||||
}
|
||||
|
||||
dispose() { this.disposables.forEach((disposable) => disposable.dispose()); }
|
||||
|
||||
async provideCanonicalUriIdentity(uri: Uri, _token: CancellationToken): Promise<Uri | undefined> {
|
||||
switch (uri.scheme) {
|
||||
case 'ssh':
|
||||
// if this is a git@github.com URI, return the HTTPS equivalent
|
||||
if (uri.authority === 'git@github.com') {
|
||||
const [owner, repo] = (uri.path.endsWith('.git') ? uri.path.slice(0, -4) : uri.path).split('/').filter((segment) => segment.length > 0);
|
||||
return Uri.parse(`https://github.com/${owner}/${repo}`);
|
||||
}
|
||||
break;
|
||||
case 'https':
|
||||
if (uri.authority === 'github.com') {
|
||||
return uri;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,7 @@ import { GithubPushErrorHandler } from './pushErrorHandler';
|
||||
import { GitBaseExtension } from './typings/git-base';
|
||||
import { GithubRemoteSourcePublisher } from './remoteSourcePublisher';
|
||||
import { GithubBranchProtectionProviderManager } from './branchProtection';
|
||||
import { GitHubCanonicalUriIdentityProvider } from './canonicalUriIdentityProvider';
|
||||
|
||||
export function activate(context: ExtensionContext): void {
|
||||
const disposables: Disposable[] = [];
|
||||
@@ -29,6 +30,7 @@ export function activate(context: ExtensionContext): void {
|
||||
|
||||
disposables.push(initializeGitBaseExtension());
|
||||
disposables.push(initializeGitExtension(context, logger));
|
||||
disposables.push(new GitHubCanonicalUriIdentityProvider());
|
||||
}
|
||||
|
||||
function initializeGitBaseExtension(): Disposable {
|
||||
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
declare module 'vscode' {
|
||||
|
||||
// https://github.com/microsoft/vscode/issues/180582
|
||||
|
||||
export namespace workspace {
|
||||
/**
|
||||
*
|
||||
* @param scheme The URI scheme that this provider can provide canonical URI identities for.
|
||||
* A canonical URI represents the conversion of a resource's alias into a source of truth URI.
|
||||
* Multiple aliases may convert to the same source of truth URI.
|
||||
* @param provider A provider which can convert URIs for workspace folders of scheme @param scheme to
|
||||
* a canonical URI identifier which is stable across machines.
|
||||
*/
|
||||
export function registerCanonicalUriIdentityProvider(scheme: string, provider: CanonicalUriIdentityProvider): Disposable;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param uri The URI to provide a canonical URI identity for.
|
||||
* @param token A cancellation token for the request.
|
||||
*/
|
||||
export function provideCanonicalUriIdentity(uri: Uri, token: CancellationToken): ProviderResult<Uri>;
|
||||
}
|
||||
|
||||
export interface CanonicalUriIdentityProvider {
|
||||
/**
|
||||
*
|
||||
* @param uri The URI to provide a canonical URI identity for.
|
||||
* @param token A cancellation token for the request.
|
||||
* @returns The canonical URI identity for the requested URI.
|
||||
*/
|
||||
provideCanonicalUriIdentity(uri: Uri, token: CancellationToken): ProviderResult<Uri>;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user