@rathnasgala/cli 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -45,6 +45,7 @@ export function setRepositoryOrigin({ root, owner, repository, spawnProcess = sp
|
|
|
45
45
|
|
|
46
46
|
export function verifyRepositoryOrigin({ root, owner, repository, spawnProcess = spawn }) {
|
|
47
47
|
const expected = `https://github.com/${owner}/${repository}.git`;
|
|
48
|
+
const expectedPath = `/${owner}/${repository}.git`;
|
|
48
49
|
return new Promise((resolve, reject) => {
|
|
49
50
|
const child = spawnProcess('git', ['-C', root, 'remote', 'get-url', 'origin'], {
|
|
50
51
|
cwd: root, shell: false, stdio: ['ignore', 'pipe', 'inherit']
|
|
@@ -56,8 +57,19 @@ export function verifyRepositoryOrigin({ root, owner, repository, spawnProcess =
|
|
|
56
57
|
child.once('exit', (code, signal) => {
|
|
57
58
|
if (signal) reject(new Error(`Git origin verification terminated by signal ${signal}`));
|
|
58
59
|
else if (code !== 0) reject(new Error(`Git origin verification exited with code ${code}`));
|
|
59
|
-
else
|
|
60
|
-
|
|
60
|
+
else {
|
|
61
|
+
let origin;
|
|
62
|
+
try {
|
|
63
|
+
origin = new URL(output.trim());
|
|
64
|
+
} catch {
|
|
65
|
+
reject(new Error(`Existing checkout origin must be ${expected}`));
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
if (origin.protocol !== 'https:' || origin.hostname !== 'github.com' || origin.port !== ''
|
|
69
|
+
|| origin.pathname !== expectedPath || origin.search !== '' || origin.hash !== '') {
|
|
70
|
+
reject(new Error(`Existing checkout origin must be ${expected}`));
|
|
71
|
+
} else resolve(root);
|
|
72
|
+
}
|
|
61
73
|
});
|
|
62
74
|
});
|
|
63
75
|
}
|