diff --git a/.changeset/fair-bears-cry.md b/.changeset/fair-bears-cry.md new file mode 100644 index 0000000000..de236a93d0 --- /dev/null +++ b/.changeset/fair-bears-cry.md @@ -0,0 +1,5 @@ +--- +"@pnpm/git-resolver": patch +--- + +Fixed a bug in which pnpm passed the wrong scheme to `git ls-remote`, causing a fallback to `git+ssh` and resulting in a 'host key verification failed' issue [#6805](https://github.com/pnpm/pnpm/issues/6805) diff --git a/resolving/git-resolver/src/parsePref.ts b/resolving/git-resolver/src/parsePref.ts index d4f799da8e..54ea67c4f4 100644 --- a/resolving/git-resolver/src/parsePref.ts +++ b/resolving/git-resolver/src/parsePref.ts @@ -61,10 +61,10 @@ function urlToFetchSpec (urlparse: URL) { return fetchSpec } -async function fromHostedGit (hosted: any): Promise { // eslint-disable-line +async function fromHostedGit (hosted: HostedGit): Promise { let fetchSpec: string | null = null // try git/https url before fallback to ssh url - const gitUrl = hosted.https({ noCommittish: true }) ?? hosted.ssh({ noCommittish: true }) + const gitUrl = hosted.https({ noCommittish: true, noGitPlus: true }) ?? hosted.ssh({ noCommittish: true }) if (gitUrl && await accessRepository(gitUrl)) { fetchSpec = gitUrl } @@ -77,11 +77,11 @@ async function fromHostedGit (hosted: any): Promise { // esli fetchSpec: httpsUrl, hosted: { ...hosted, - _fill: hosted._fill, + _fill: (hosted as any)._fill, // eslint-disable-line @typescript-eslint/no-explicit-any tarball: undefined, - }, + } as any, // eslint-disable-line @typescript-eslint/no-explicit-any normalizedPref: `git+${httpsUrl}`, - ...setGitCommittish(hosted.committish), + ...setGitCommittish(hosted.committish!), } } else { try { @@ -111,11 +111,11 @@ async function fromHostedGit (hosted: any): Promise { // esli fetchSpec: fetchSpec!, hosted: { ...hosted, - _fill: hosted._fill, + _fill: (hosted as any)._fill, // eslint-disable-line @typescript-eslint/no-explicit-any tarball: hosted.tarball, - }, - normalizedPref: hosted.shortcut(), - ...setGitCommittish(hosted.committish), + } as any, // eslint-disable-line @typescript-eslint/no-explicit-any + normalizedPref: hosted.auth ? fetchSpec! : hosted.shortcut(), + ...setGitCommittish(hosted.committish!), } } diff --git a/resolving/git-resolver/test/index.ts b/resolving/git-resolver/test/index.ts index b0f7f8ee62..ad254f3242 100644 --- a/resolving/git-resolver/test/index.ts +++ b/resolving/git-resolver/test/index.ts @@ -414,11 +414,9 @@ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\trefs/heads/master\ const resolveResult = await resolveFromGit({ pref: 'git+https://0000000000000000000000000000000000000000:x-oauth-basic@github.com/foo/bar.git' }) expect(resolveResult).toStrictEqual({ id: '0000000000000000000000000000000000000000+x-oauth-basic@github.com/foo/bar/0000000000000000000000000000000000000000', - normalizedPref: 'git+https://0000000000000000000000000000000000000000:x-oauth-basic@github.com/foo/bar.git', + normalizedPref: 'https://0000000000000000000000000000000000000000:x-oauth-basic@github.com/foo/bar.git', resolution: { - commit: '0000000000000000000000000000000000000000', - repo: 'https://0000000000000000000000000000000000000000:x-oauth-basic@github.com/foo/bar.git', - type: 'git', + tarball: 'https://codeload.github.com/foo/bar/tar.gz/0000000000000000000000000000000000000000', }, resolvedVia: 'git-repository', })