This commit is contained in:
NuklearRabbit committed 2026-07-24 20:29:23 +02:00
commit 66060348da
107 files changed
+14771

No files matched your search

+24
View File
@@ -0,0 +1,24 @@
'use strict';
const path = require('node:path');
function cloneDirectoryName(remoteUrl) {
const raw = String(remoteUrl || '').trim().replace(/[?#].*$/, '').replace(/[\\/]+$/, '');
const segment = raw.split(/[\\/:]/).filter(Boolean).at(-1) || 'repository';
return segment.replace(/\.git$/i, '').replace(/[^a-zA-Z0-9._-]/g, '-') || 'repository';
}
function resolveCloneTarget(workspaceRoot, remoteUrl) {
const root = path.resolve(String(workspaceRoot || ''));
if (!String(workspaceRoot || '').trim()) throw new Error('A project root is required.');
const target = path.resolve(root, cloneDirectoryName(remoteUrl));
const normalize = (value) => process.platform === 'win32' ? value.toLowerCase() : value;
const normalizedRoot = normalize(root);
const normalizedTarget = normalize(target);
if (normalizedTarget === normalizedRoot || !normalizedTarget.startsWith(`${normalizedRoot}${path.sep}`)) {
throw new Error('Clone target escapes the selected project root.');
}
return { root, target, directoryName: path.basename(target) };
}
module.exports = { cloneDirectoryName, resolveCloneTarget };