{"record":{"id":"7d424c11c543db7b","repo":"abhigyanpatwari/GitNexus","slug":"refusing-to-delete-storage-the-target-is-the-repository-one","errorCode":null,"errorMessage":"Refusing to delete storage: the target is the repository, one of its parents, or a filesystem root","messagePattern":"Refusing to delete storage: the target is the repository, one of its parents, or a filesystem root","errorType":"exception","errorClass":"StorageDeletionError","httpStatus":null,"severity":"critical","filePath":"gitnexus/src/storage/storage-resolver.ts","lineNumber":701,"sourceCode":"    throw new StorageDeletionError(\n      defaultStoragePath(fallbackRepoPath),\n      rawStoragePath,\n      undefined,\n      error instanceof Error ? error.message : 'the registry storage path is invalid',\n    );\n  }\n\n  const expectedStoragePath = defaultStoragePath(repoPath);\n  const storageIsLocal = isRepositoryLocalStoragePath(repoPath, actualStoragePath);\n  const comparableStorage = comparablePath(actualStoragePath);\n  const comparableRepo = comparablePath(repoPath);\n  const comparableRoot = comparablePath(path.parse(actualStoragePath).root);\n  if (\n    samePath(comparableStorage, comparableRoot) ||\n    samePath(comparableStorage, comparableRepo) ||\n    isPathAncestor(comparableStorage, comparableRepo)\n  ) {\n    throw new StorageDeletionError(\n      expectedStoragePath,\n      actualStoragePath,\n      undefined,\n      'the target is the repository, one of its parents, or a filesystem root',\n    );\n  }\n\n  const inspection = await inspectRegisteredStorage({\n    path: repoPath,\n    storagePath: actualStoragePath,\n  });\n  const allowedStates: readonly StorageState[] = storageIsLocal\n    ? ['missing', 'empty', 'unowned', 'owned', 'foreign']\n    : ['owned'];\n  if (!allowedStates.includes(inspection.state)) {\n    throw new StorageDeletionError(\n      expectedStoragePath,\n      actualStoragePath,","sourceCodeStart":683,"sourceCodeEnd":719,"githubUrl":"https://github.com/abhigyanpatwari/GitNexus/blob/ac9a4e9abd8fd3058c070b72c23402a4f887929a/gitnexus/src/storage/storage-resolver.ts#L683-L719","documentation":"A StorageDeletionError safety guard thrown before any deletion occurs when the resolved storage path is the repository directory itself, one of its parents, or a filesystem root. Deleting such a path would destroy the source tree or the filesystem, so GitNexus hard-refuses regardless of flags.","triggerScenarios":"A registry/lookup produced a storagePath that resolves to the repo root, an ancestor directory (e.g. / or /work), or a mount root — typically via GITNEXUS_STORAGE_PATH set to a root-ish path or a misconfigured external slot.","commonSituations":"Setting GITNEXUS_STORAGE_PATH=/ or to the repo directory itself; typos like GITNEXUS_STORAGE_PATH=~ (home dir is a parent of the repo); running deletion from cwd at a filesystem root with a relative-path resolution edge case.","solutions":["Unset or correct GITNEXUS_STORAGE_PATH so it names a dedicated index subdirectory, not the repo or an ancestor.","Use the default storage location (<repo>/.gitnexus) and retry the deletion.","Verify the intended path with `gitnexus` status/list-repos before re-running deletion.","Never set storage paths to /, the repo root, or the home directory."],"exampleFix":"// before\nGITNEXUS_STORAGE_PATH=/ npx gitnexus clean myrepo\n// after\nunset GITNEXUS_STORAGE_PATH && npx gitnexus clean myrepo","handlingStrategy":"validation","validationCode":"const resolved = path.resolve(storagePath);\nconst repo = path.resolve(repoPath);\nif (resolved === repo || repo.startsWith(resolved + path.sep) || resolved === path.parse(resolved).root) {\n  throw new Error('Storage path would delete the repo or a parent directory');\n}","typeGuard":"const isSafeDeleteTarget = (storagePath: string, repoPath: string): boolean => {\n  const s = path.resolve(storagePath), r = path.resolve(repoPath);\n  return s !== path.parse(s).root && s !== r && !r.startsWith(s + path.sep);\n};","tryCatchPattern":"try {\n  await deleteRepoStorage(repoName);\n} catch (err) {\n  if (err instanceof StorageDeletionError && /repository, one of its parents/.test(err.message)) {\n    console.error('Fix GITNEXUS_STORAGE_PATH: it must be a dedicated subdirectory');\n  } else throw err;\n}","preventionTips":["Never set GITNEXUS_STORAGE_PATH to /, the repo root, or the home directory.","Point storage at a dedicated subdirectory created for index data only.","Dry-run/inspect the resolved path before destructive clean commands.","Keep external slots outside the repository tree's ancestor chain."],"tags":["storage","deletion","safety-guard","destructive-operation"],"backgroundTag":"invalid-config-value","analyzedSha":"ac9a4e9abd8fd3058c070b72c23402a4f887929a","analyzedAt":"2026-09-15T23:29:44.066Z","contentChangedAt":"2026-09-15T23:29:44.066Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}