Skip to content

Commit

Permalink
fix: use 'ssh' url instead of 'git' for export
Browse files Browse the repository at this point in the history
  • Loading branch information
senyai committed May 11, 2024
1 parent ecbca17 commit 6ab26e6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 20 deletions.
40 changes: 23 additions & 17 deletions src/gitExport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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 };
}
Expand Down
6 changes: 3 additions & 3 deletions src/test/suite/gitExportSuite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
(() => {
Expand Down Expand Up @@ -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`,
},
})
);
Expand Down Expand Up @@ -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'
);
});

Expand Down

0 comments on commit 6ab26e6

Please sign in to comment.