diff --git a/extensions/github/package.json b/extensions/github/package.json index f86f98683af..af7b544f596 100644 --- a/extensions/github/package.json +++ b/extensions/github/package.json @@ -49,6 +49,15 @@ "scope": "resource", "default": true, "description": "%config.gitAuthentication%" + }, + "github.gitProtocol": { + "type": "string", + "enum": [ + "https", + "ssh" + ], + "default": "https", + "description": "%config.gitProtocol%" } } } diff --git a/extensions/github/package.nls.json b/extensions/github/package.nls.json index 472c5ab7e4c..ebebab0e0e2 100644 --- a/extensions/github/package.nls.json +++ b/extensions/github/package.nls.json @@ -2,6 +2,7 @@ "displayName": "GitHub", "description": "GitHub features for VS Code", "config.gitAuthentication": "Controls whether to enable automatic GitHub authentication for git commands within VS Code.", + "config.gitProtocol": "Controls which protocol is used to clone a GitHub repository", "welcome.publishFolder": "You can also directly publish this folder to a GitHub repository. Once published, you'll have access to source control features powered by git and GitHub.\n[$(github) Publish to GitHub](command:github.publish)", "welcome.publishWorkspaceFolder": "You can also directly publish a workspace folder to a GitHub repository. Once published, you'll have access to source control features powered by git and GitHub.\n[$(github) Publish to GitHub](command:github.publish)" } diff --git a/extensions/github/src/auth.ts b/extensions/github/src/auth.ts index a0a0244255a..af91374e91f 100644 --- a/extensions/github/src/auth.ts +++ b/extensions/github/src/auth.ts @@ -53,4 +53,3 @@ export function getOctokit(): Promise { return _octokit; } - diff --git a/extensions/github/src/publish.ts b/extensions/github/src/publish.ts index 0954e2c67ff..fe8a31bbc67 100644 --- a/extensions/github/src/publish.ts +++ b/extensions/github/src/publish.ts @@ -197,7 +197,9 @@ export async function publishRepository(gitAPI: GitAPI, repository?: Repository) progress.report({ message: localize('publishing_uploading', "Uploading files"), increment: 25 }); const branch = await repository.getBranch('HEAD'); - await repository.addRemote('origin', createdGithubRepository.clone_url); + const protocol = vscode.workspace.getConfiguration('github').get<'https' | 'ssh'>('gitProtocol'); + const remoteUrl = protocol === 'https' ? createdGithubRepository.clone_url : createdGithubRepository.ssh_url; + await repository.addRemote('origin', remoteUrl); await repository.push('origin', branch.name, true); return createdGithubRepository; diff --git a/extensions/github/src/pushErrorHandler.ts b/extensions/github/src/pushErrorHandler.ts index 5948c526ea1..9e8af7dbcc9 100644 --- a/extensions/github/src/pushErrorHandler.ts +++ b/extensions/github/src/pushErrorHandler.ts @@ -73,7 +73,9 @@ async function handlePushError(repository: Repository, remote: Remote, refspec: await repository.renameRemote(remote.name, 'upstream'); // Issue: what if there's already another `origin` repo? - await repository.addRemote('origin', ghRepository.clone_url); + const protocol = workspace.getConfiguration('github').get<'https' | 'ssh'>('gitProtocol'); + const remoteUrl = protocol === 'https' ? ghRepository.clone_url : ghRepository.ssh_url; + await repository.addRemote('origin', remoteUrl); try { await repository.fetch('origin', remoteName); diff --git a/extensions/github/src/remoteSourceProvider.ts b/extensions/github/src/remoteSourceProvider.ts index 7f3f9ae41eb..6e0b5fadbf7 100644 --- a/extensions/github/src/remoteSourceProvider.ts +++ b/extensions/github/src/remoteSourceProvider.ts @@ -3,6 +3,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ +import { workspace } from 'vscode'; import { RemoteSourceProvider, RemoteSource } from './typings/git-base'; import { getOctokit } from './auth'; import { Octokit } from '@octokit/rest'; @@ -14,10 +15,11 @@ function parse(url: string): { owner: string; repo: string } | undefined { } function asRemoteSource(raw: any): RemoteSource { + const protocol = workspace.getConfiguration('github').get<'https' | 'ssh'>('gitProtocol'); return { name: `$(github) ${raw.full_name}`, description: raw.description || undefined, - url: raw.clone_url + url: protocol === 'https' ? raw.clone_url : raw.ssh_url }; }