Skip to content

Commit fb82bd7

Browse files
authored
fix(git): call getNetworkSettings with the origin of the repo (#2295)
1 parent ed9e731 commit fb82bd7

7 files changed

Lines changed: 66 additions & 2 deletions

File tree

.pnp.cjs

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Binary file not shown.

.yarn/versions/9ce056ce.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
releases:
2+
"@yarnpkg/cli": patch
3+
"@yarnpkg/plugin-git": patch
4+
"@yarnpkg/plugin-github": patch
5+
6+
declined:
7+
- "@yarnpkg/plugin-compat"
8+
- "@yarnpkg/plugin-constraints"
9+
- "@yarnpkg/plugin-dlx"
10+
- "@yarnpkg/plugin-essentials"
11+
- "@yarnpkg/plugin-init"
12+
- "@yarnpkg/plugin-interactive-tools"
13+
- "@yarnpkg/plugin-node-modules"
14+
- "@yarnpkg/plugin-npm-cli"
15+
- "@yarnpkg/plugin-pack"
16+
- "@yarnpkg/plugin-patch"
17+
- "@yarnpkg/plugin-pnp"
18+
- "@yarnpkg/plugin-stage"
19+
- "@yarnpkg/plugin-typescript"
20+
- "@yarnpkg/plugin-version"
21+
- "@yarnpkg/plugin-workspace-tools"
22+
- "@yarnpkg/builder"
23+
- "@yarnpkg/core"
24+
- "@yarnpkg/doctor"

packages/acceptance-tests/pkg-tests-specs/sources/features/enableNetwork.test.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,24 @@ describe(`Features`, () => {
3030
await expect(run(`add`, `no-deps`)).resolves.toMatchObject({code: 0, stderr: ``});
3131
})
3232
);
33+
34+
test(
35+
`it should work with git URLs`,
36+
makeTemporaryEnv({}, async ({path, run, source}) => {
37+
await xfs.writeFilePromise(
38+
`${path}/.yarnrc.yml`,
39+
[
40+
`networkSettings:`,
41+
` "github.com":`,
42+
` enableNetwork: false`,
43+
].join(`\n`)
44+
);
45+
46+
await expect(run(`add`, `foo@git@github.com:foo/foo.git`)).rejects.toThrow(
47+
/ has been blocked because of your configuration settings/
48+
);
49+
}
50+
)
51+
);
3352
});
3453
});

packages/plugin-git/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"@yarnpkg/core": "^3.0.0-rc.2"
1515
},
1616
"devDependencies": {
17+
"@types/git-url-parse": "^9.0.0",
1718
"@yarnpkg/core": "workspace:*"
1819
},
1920
"repository": {

packages/plugin-git/sources/gitUtils.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {Configuration, Locator, execUtils, structUtils, httpUtils} from '@yarnpkg/core';
22
import {npath, xfs} from '@yarnpkg/fslib';
3+
import GitUrlParse from 'git-url-parse';
34
import querystring from 'querystring';
45
import semver from 'semver';
56
import urlLib from 'url';
@@ -170,7 +171,7 @@ export function normalizeLocator(locator: Locator) {
170171
export async function lsRemote(repo: string, configuration: Configuration) {
171172
const normalizedRepoUrl = normalizeRepoUrl(repo, {git: true});
172173

173-
const networkSettings = httpUtils.getNetworkSettings(normalizedRepoUrl, {configuration});
174+
const networkSettings = httpUtils.getNetworkSettings(`https://${GitUrlParse(normalizedRepoUrl).resource}`, {configuration});
174175
if (!networkSettings.enableNetwork)
175176
throw new Error(`Request to '${normalizedRepoUrl}' has been blocked because of your configuration settings`);
176177

@@ -298,7 +299,7 @@ export async function clone(url: string, configuration: Configuration) {
298299
throw new Error(`Invalid treeish protocol when cloning`);
299300

300301
const normalizedRepoUrl = normalizeRepoUrl(repo, {git: true});
301-
if (httpUtils.getNetworkSettings(normalizedRepoUrl, {configuration}).enableNetwork === false)
302+
if (httpUtils.getNetworkSettings(`https://${GitUrlParse(normalizedRepoUrl).resource}`, {configuration}).enableNetwork === false)
302303
throw new Error(`Request to '${normalizedRepoUrl}' has been blocked because of your configuration settings`);
303304

304305
const directory = await xfs.mktempPromise();

yarn.lock

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4393,6 +4393,13 @@ __metadata:
43934393
languageName: node
43944394
linkType: hard
43954395

4396+
"@types/git-url-parse@npm:^9.0.0":
4397+
version: 9.0.0
4398+
resolution: "@types/git-url-parse@npm:9.0.0"
4399+
checksum: 3f4dbd6d5ca3ba84221983ceffe4d81c6a79cc85529ba3d54b1d0963f2d91cbcffcd9998e8478ee18df73c9697cf05b8aeddb1349f9e65af0e4b039a89d7fff6
4400+
languageName: node
4401+
linkType: hard
4402+
43964403
"@types/glob@npm:*, @types/glob@npm:^7.1.1":
43974404
version: 7.1.1
43984405
resolution: "@types/glob@npm:7.1.1"
@@ -6021,6 +6028,7 @@ __metadata:
60216028
version: 0.0.0-use.local
60226029
resolution: "@yarnpkg/plugin-git@workspace:packages/plugin-git"
60236030
dependencies:
6031+
"@types/git-url-parse": ^9.0.0
60246032
"@types/semver": ^7.1.0
60256033
"@yarnpkg/core": "workspace:*"
60266034
"@yarnpkg/fslib": "workspace:^2.5.0-rc.2"

0 commit comments

Comments
 (0)