MCPcopy
hub / github.com/coder/mux / validateAndPrepareClone

Method validateAndPrepareClone

src/node/services/projectService.ts:532–567  ·  view source on GitHub ↗
(
    input: CloneProjectParams
  )

Source from the content-addressed store, hash-verified

530 }
531
532 private validateAndPrepareClone(
533 input: CloneProjectParams
534 ): Result<{ cloneUrl: string; normalizedPath: string; cloneParentDir: string }> {
535 try {
536 const repoUrl = input.repoUrl.trim();
537 if (!repoUrl) {
538 return Err("Repository URL cannot be empty");
539 }
540
541 const config = this.config.loadConfigOrDefault();
542 const cloneParentDir = resolveProjectParentDir(
543 input.cloneParentDir,
544 config.defaultProjectDir
545 );
546 const repoFolderName = deriveRepoFolderName(repoUrl);
547 const normalizedPath = path.join(cloneParentDir, repoFolderName);
548
549 const normalizedProjects = deriveProjectHierarchy(config.projects);
550 if (findDeepestTopLevelParentProject(normalizedPath, normalizedProjects)) {
551 return Err("Cannot clone a new git repository inside an existing project tree");
552 }
553
554 if (config.projects.has(normalizedPath)) {
555 return Err(`Project already exists at ${normalizedPath}`);
556 }
557
558 return Ok({
559 cloneUrl: normalizeRepoUrlForClone(repoUrl),
560 normalizedPath,
561 cloneParentDir,
562 });
563 } catch (error) {
564 const message = getErrorMessage(error);
565 return Err(message);
566 }
567 }
568
569 async *cloneWithProgress(
570 input: CloneProjectParams,

Callers 1

cloneWithProgressMethod · 0.95

Calls 10

ErrFunction · 0.90
deriveProjectHierarchyFunction · 0.90
OkFunction · 0.90
getErrorMessageFunction · 0.90
resolveProjectParentDirFunction · 0.85
deriveRepoFolderNameFunction · 0.85
normalizeRepoUrlForCloneFunction · 0.85
loadConfigOrDefaultMethod · 0.80
hasMethod · 0.45

Tested by

no test coverage detected