Skip to content

Commit 5b023d4

Browse files
bfarias-godaddyjoyeecheung
authored andcommitted
git-node: warn on unexpected remote repository url
1 parent a992a24 commit 5b023d4

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

lib/landing_session.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22

33
const path = require('path');
4+
const { URL } = require('url');
45

56
const {
67
runAsync, runSync, forceRunAsync, exit
@@ -14,6 +15,33 @@ class LandingSession extends Session {
1415
super(dir, prid, config);
1516
this.cli = cli;
1617
this.req = req;
18+
const { upstream } = this;
19+
const upstreamHref = runSync('git', ['config', '--get',
20+
`remote.${upstream}.url`]);
21+
let warned = false;
22+
try {
23+
const { hostname, pathname } = new URL(upstreamHref);
24+
if (hostname !== 'github.com') {
25+
warned = true;
26+
cli.warn('Remote repository URL does not point to the expected ' +
27+
'host "github.com"');
28+
}
29+
if (/^\/nodejs\/node(?:\.git)?$/.test(pathname) !== true) {
30+
warned = true;
31+
cli.warn('Remote repository URL does not point to the expected ' +
32+
'repository "/nodejs/node"');
33+
}
34+
} catch (e) {
35+
warned = true;
36+
cli.warn('Could not parse remote repository URL %j, this might be ' +
37+
'because it is not a HTTPS URL', upstreamHref);
38+
}
39+
if (warned) {
40+
cli.warn('You might want to change the remote repository URL with ' +
41+
`\`git remote set-url ${
42+
upstream
43+
} "https://github.com/nodejs/node.git"\``);
44+
}
1745
}
1846

1947
async start(metadata) {

0 commit comments

Comments
 (0)