Skip to content

Commit

Permalink
fix(resolver): Add general support for git-over-protocol URLs (#4759)
Browse files Browse the repository at this point in the history
**Summary**

Yarn can not handle the `git+https://` dependency format correctly, as described for various versions in #1625. The problem is present in Yarn 1.2.1.

A related problem for `git+ssh://` has been described in #573 and fixed in #3425.

This PR extends the solution from #3425 to use the Git fetcher for any [Git-over-protocol](https://git-scm.com/book/en/v2/Git-on-the-Server-The-Protocols) URLs.

**Test plan**

Extended the `package-request` unit tests to verify that the correct remote type (git) is used for `git+https://`, while the tarball remote type continues to be used for regular HTTP(S) URLs.
  • Loading branch information
knuton authored and BYK committed Oct 26, 2017
1 parent 917713d commit 7beaad0
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 16 deletions.
41 changes: 27 additions & 14 deletions __tests__/package-request.js
Expand Up @@ -32,7 +32,7 @@ async function prepareRequest(pattern: string, version: string, resolved: string
return {request, reporter};
}

test('Produce valid remote type for a git private dep', async () => {
test('Produce valid remote type for a git-over-ssh dep', async () => {
const {request, reporter} = await prepareRequest(
'private-dep@github:yarnpkg/private-dep#1.0.0',
'1.0.0',
Expand All @@ -45,6 +45,32 @@ test('Produce valid remote type for a git private dep', async () => {
await reporter.close();
});

test('Produce valid remote type for a git-over-https dep', async () => {
const {request, reporter} = await prepareRequest(
'public-dep@yarnpkg/public-dep#1.0.0',
'1.0.0',
'git+https://github.com/yarnpkg/public-dep#1fde368',
);

expect(request.getLocked('git')._remote.type).toBe('git');
expect(request.getLocked('tarball')._remote.type).toBe('git');

await reporter.close();
});

test('Produce valid remote type for a git public dep', async () => {
const {request, reporter} = await prepareRequest(
'public-dep@yarnpkg/public-dep#1fde368',
'1.0.0',
'https://codeload.github.com/yarnpkg/public-dep/tar.gz/1fde368',
);

expect(request.getLocked('git')._remote.type).toBe('git');
expect(request.getLocked('tarball')._remote.type).toBe('tarball');

await reporter.close();
});

test('Check parentNames flowing in the request', async () => {
const {request: parentRequest, reporter: parentReporter} = await prepareRequest(
'parent@1.0.0',
Expand All @@ -63,16 +89,3 @@ test('Check parentNames flowing in the request', async () => {
await parentReporter.close();
await childReporter.close();
});

test('Produce valid remote type for a git public dep', async () => {
const {request, reporter} = await prepareRequest(
'public-dep@yarnpkg/public-dep#1fde368',
'1.0.0',
'https://codeload.github.com/yarnpkg/public-dep/tar.gz/1fde368',
);

expect(request.getLocked('git')._remote.type).toBe('git');
expect(request.getLocked('tarball')._remote.type).toBe('tarball');

await reporter.close();
});
5 changes: 3 additions & 2 deletions src/package-request.js
Expand Up @@ -60,8 +60,9 @@ export default class PackageRequest {

if (shrunk && shrunk.resolved) {
const resolvedParts = versionUtil.explodeHashedUrl(shrunk.resolved);
// If it's a private git url set remote to 'git'.
const preferredRemoteType = resolvedParts.url.startsWith('git+ssh://') ? 'git' : remoteType;

// Detect Git protocols (git://HOST/PATH or git+PROTOCOL://HOST/PATH)
const preferredRemoteType = /^git(\+[a-z0-9]+)?:\/\//.test(resolvedParts.url) ? 'git' : remoteType;

return {
name: shrunk.name,
Expand Down

0 comments on commit 7beaad0

Please sign in to comment.