feat: add "refs/" as a git resolution prefix (#4953)

Previously, if you wanted to check out a git PR branch,
you needed to specify the url as:
`github:pnpm/pnpm#refs/pull/123/merge`.
Now this will resolve without the leading "refs":
`github:pnpm/pnpm#pull/123/merge`

close #2045
This commit is contained in:
Dan Rose
2022-06-29 18:48:30 -05:00
committed by GitHub
parent ab684d77eb
commit 449ccef098
3 changed files with 18 additions and 0 deletions

View File

@@ -0,0 +1,5 @@
---
"@pnpm/git-resolver": minor
---
Add `refs/` to git resolution prefixes

View File

@@ -87,6 +87,7 @@ function resolveRefFromRefs (refs: {[ref: string]: string}, repo: string, ref: s
if (!range) {
const commitId =
refs[ref] ||
refs[`refs/${ref}`] ||
refs[`refs/tags/${ref}^{}`] || // prefer annotated tags
refs[`refs/tags/${ref}`] ||
refs[`refs/heads/${ref}`]

View File

@@ -72,6 +72,18 @@ test('resolveFromGit() with branch', async () => {
})
})
test('resolveFromGit() with branch relative to refs', async () => {
const resolveResult = await resolveFromGit({ pref: 'zkochan/is-negative#heads/canary' })
expect(resolveResult).toStrictEqual({
id: 'github.com/zkochan/is-negative/4c39fbc124cd4944ee51cb082ad49320fab58121',
normalizedPref: 'github:zkochan/is-negative#heads/canary',
resolution: {
tarball: 'https://codeload.github.com/zkochan/is-negative/tar.gz/4c39fbc124cd4944ee51cb082ad49320fab58121',
},
resolvedVia: 'git-repository',
})
})
test('resolveFromGit() with tag', async () => {
const resolveResult = await resolveFromGit({ pref: 'zkochan/is-negative#2.0.1' })
expect(resolveResult).toStrictEqual({