From 449ccef098df29631fcc6f12868e0f3bfec55431 Mon Sep 17 00:00:00 2001 From: Dan Rose Date: Wed, 29 Jun 2022 18:48:30 -0500 Subject: [PATCH] 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 --- .changeset/hip-sheep-smoke.md | 5 +++++ packages/git-resolver/src/index.ts | 1 + packages/git-resolver/test/index.ts | 12 ++++++++++++ 3 files changed, 18 insertions(+) create mode 100644 .changeset/hip-sheep-smoke.md 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({