Skip to content

Commit

Permalink
fix(resolution): Allow github dependency refs of type "#pull/1/head" (y…
Browse files Browse the repository at this point in the history
…arnpkg#5673)

**Summary**

Fixes yarnpkg#1610. Previously yarn would allow a dependency on a GitHub pull request with "yarnpkg#1/head" where 1 is the PR number. npm allows the format "#pull/1/head" as well. For compatibility, allowing Yarn to fall back to this format.

**Test plan**

Added a test to `git-ref-resolver` to test the case `"pull/10/head"`
  • Loading branch information
rally25rs authored and BYK committed Apr 15, 2018
1 parent 1522cde commit 25742bb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions __tests__/util/git/git-ref-resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ test('resolveVersion', async () => {
sha: '6e97e0159f10c275f227d0f067d99f2a97331cef',
ref: 'refs/pull/100/head',
});
expect(await resolve('pull/100/head')).toEqual({
sha: '6e97e0159f10c275f227d0f067d99f2a97331cef',
ref: 'refs/pull/100/head',
});
// not-existing sha
expect(await resolve('0123456')).toEqual(null);

Expand Down
5 changes: 5 additions & 0 deletions src/util/git/git-ref-resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export type ResolveVersionOptions = {
};
type Names = {tags: Array<string>, heads: Array<string>};

const REF_PREFIX = 'refs/';
const REF_TAG_PREFIX = 'refs/tags/';
const REF_BRANCH_PREFIX = 'refs/heads/';
const REF_PR_PREFIX = 'refs/pull/';
Expand Down Expand Up @@ -69,6 +70,9 @@ const tryVersionAsPullRequestNo = ({version, refs}: ResolveVersionOptions): ?Res
const tryVersionAsBranchName = ({version, refs}: ResolveVersionOptions): ?ResolvedSha =>
tryRef(refs, `${REF_BRANCH_PREFIX}${version}`);

const tryVersionAsDirectRef = ({version, refs}: ResolveVersionOptions): ?ResolvedSha =>
tryRef(refs, `${REF_PREFIX}${version}`);

const computeSemverNames = ({config, refs}: ResolveVersionOptions): Names => {
const names = {
tags: [],
Expand Down Expand Up @@ -120,6 +124,7 @@ const VERSION_RESOLUTION_STEPS: Array<(ResolveVersionOptions) => ?ResolvedSha |
tryVersionAsBranchName,
tryVersionAsSemverRange,
tryWildcardVersionAsDefaultBranch,
tryVersionAsDirectRef,
];

/**
Expand Down

0 comments on commit 25742bb

Please sign in to comment.