diff --git a/.changeset/hip-sheep-smoke.md b/.changeset/hip-sheep-smoke.md new file mode 100644 index 0000000000..f7cadee19b --- /dev/null +++ b/.changeset/hip-sheep-smoke.md @@ -0,0 +1,5 @@ +--- +"@pnpm/git-resolver": minor +--- + +Add `refs/` to git resolution prefixes diff --git a/packages/git-resolver/src/index.ts b/packages/git-resolver/src/index.ts index eff21c9372..9cad5084f2 100644 --- a/packages/git-resolver/src/index.ts +++ b/packages/git-resolver/src/index.ts @@ -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}`] diff --git a/packages/git-resolver/test/index.ts b/packages/git-resolver/test/index.ts index 0a190bc9ba..d8ba782a62 100644 --- a/packages/git-resolver/test/index.ts +++ b/packages/git-resolver/test/index.ts @@ -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({