diff --git a/src/gitExport.ts b/src/gitExport.ts index db9b400..75b9662 100644 --- a/src/gitExport.ts +++ b/src/gitExport.ts @@ -70,11 +70,11 @@ type GitMirrorPath = Distinct< 'path that goes as MIRROR option to `fossil export`' >; type AutoPushURIUnsafe = Distinct< - Uri, + string, 'URL that goes as --autopush option to `fossil export`' >; type AutoPushURISafe = Distinct< - Uri, + string, 'like `AutoPushURIUnsafe`, but without tokens`' >; type GitExportOptions = { @@ -140,19 +140,23 @@ export async function inputExportOptions( if (where === toUrl) { // ask URL - const urlStr = await window.showInputBox({ + const urlStr = (await window.showInputBox({ prompt: 'The URL of an empty repository', ignoreFocusOut: true, - }); + })) as AutoPushURIUnsafe; if (urlStr) { const url = Uri.parse(urlStr); - const safeAuthority = url.authority.substring( - url.authority.indexOf('@') - ); + const safeUrl = url + .with({ + authority: url.authority.substring( + url.authority.indexOf('@') + ), + }) + .toString() as AutoPushURISafe; return { path: exportPath, - url: url.with({ authority: safeAuthority }) as AutoPushURISafe, - urlUnsafe: url as AutoPushURIUnsafe, + url: safeUrl, + urlUnsafe: urlStr, }; } return; @@ -282,7 +286,7 @@ export async function inputExportOptions( label: '$(github) Use https url with token', }; const withGit = { - label: '$(key) Use git url without token', + label: '$(key) Use ssh url without token', }; const auth = await window.showQuickPick([withToken, withGit]); if (!auth) { @@ -293,14 +297,16 @@ export async function inputExportOptions( let urlUnsafe: AutoPushURIUnsafe; if (auth === withToken) { // add token to url - url = Uri.parse(response.data.html_url) as AutoPushURISafe; - urlUnsafe = url.with({ - authority: `${session.account.label}:${session.accessToken}@${url.authority}`, - }) as AutoPushURIUnsafe; + url = response.data.html_url as AutoPushURISafe; + const urlParsed = Uri.parse(url); + urlUnsafe = urlParsed + .with({ + authority: `${session.account.label}:${session.accessToken}@${urlParsed.authority}`, + }) + .toString() as AutoPushURIUnsafe; } else { - urlUnsafe = (url = Uri.parse( - response.data.git_url - ) as AutoPushURISafe) as unknown as AutoPushURIUnsafe; + urlUnsafe = (url = response.data + .ssh_url as AutoPushURISafe) as unknown as AutoPushURIUnsafe; } return { path: exportPath, url, urlUnsafe }; } diff --git a/src/test/suite/gitExportSuite.ts b/src/test/suite/gitExportSuite.ts index 96d38a8..f2dfb86 100644 --- a/src/test/suite/gitExportSuite.ts +++ b/src/test/suite/gitExportSuite.ts @@ -169,7 +169,7 @@ class GitExportTestHelper { ); assert.equal( items[1].label, - '$(key) Use git url without token' + '$(key) Use ssh url without token' ); return Promise.resolve( (() => { @@ -328,7 +328,7 @@ class GitExportTestHelper { ) => ({ data: { html_url: `https://examplegit.com/theuser/${params.name}`, - git_url: `git:examplegit.com/theuser/${params.name}.git`, + ssh_url: `git@github.com:theuser/${params.name}.git`, }, }) ); @@ -499,7 +499,7 @@ export function GitExportSuite(this: Suite): void { sinon.assert.calledOnceWithExactly( term.fakeTerminal.sendText, ' fossil git export /tmp/gitExport/spn --mainbranch main ' + - '--autopush git:examplegit.com/theuser/spn.git' + '--autopush git@github.com:theuser/spn.git' ); });