Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(git-resolver): wrong scheme to git ls-remote #6806

Merged
merged 7 commits into from
Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fair-bears-cry.md
Original file line number Diff line number Diff line change
@@ -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)
18 changes: 9 additions & 9 deletions resolving/git-resolver/src/parsePref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ function urlToFetchSpec (urlparse: URL) {
return fetchSpec
}

async function fromHostedGit (hosted: any): Promise<HostedPackageSpec> { // eslint-disable-line
async function fromHostedGit (hosted: HostedGit): Promise<HostedPackageSpec> {
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
}
Expand All @@ -77,11 +77,11 @@ async function fromHostedGit (hosted: any): Promise<HostedPackageSpec> { // 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 {
Expand Down Expand Up @@ -111,11 +111,11 @@ async function fromHostedGit (hosted: any): Promise<HostedPackageSpec> { // 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!),
}
}

Expand Down
6 changes: 2 additions & 4 deletions resolving/git-resolver/test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
})
Expand Down