{"record":{"id":"ddc4c2d0b60353b3","repo":"abhigyanpatwari/GitNexus","slug":"refusing-to-adopt-branch-metadata-storage-is-not-owned-by","errorCode":null,"errorMessage":"Refusing to adopt branch metadata: storage is not owned by this repository (${inspection.state}).","messagePattern":"Refusing to adopt branch metadata: storage is not owned by this repository \\((.+?)\\)\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"gitnexus/src/storage/repo-manager.ts","lineNumber":1261,"sourceCode":"  const initialEntries = await readRegistry();\n  const initialIdx = isRegistered(initialEntries);\n  if (initialIdx < 0) return; // no-op, disk included (no self-heal)\n\n  const resolved = path.resolve(repoPath);\n  const storagePath =\n    resolvedStoragePath === undefined\n      ? getStoragePaths(resolved).storagePath\n      : validateConfiguredStoragePath(resolvedStoragePath);\n  const registeredStoragePath = initialEntries[initialIdx].storagePath;\n  if (!registryPathEquals(canonicalizePath(registeredStoragePath), canonicalizePath(storagePath))) {\n    throw new Error(\n      `Refusing to adopt branch metadata: the registry storage path does not match the selected storage directory.`,\n    );\n  }\n  if (resolvedStoragePath !== undefined) {\n    const inspection = await inspectStoragePath(storagePath, resolved);\n    if (inspection.state !== 'owned') {\n      throw new Error(\n        `Refusing to adopt branch metadata: storage is not owned by this repository (${inspection.state}).`,\n      );\n    }\n  }\n  // Remove a shadowed sub-index directory, mirroring `clean --branch`'s\n  // containment guard: the target MUST live under .gitnexus/branches/.\n  const branchesRoot = path.join(storagePath, BRANCHES_DIR);\n  const branchDir = path.join(branchesRoot, branchSlug(branch));\n  const branchRelativePath = path.relative(branchesRoot, branchDir);\n  const branchDirIsContained =\n    branchRelativePath !== '' &&\n    branchRelativePath !== '..' &&\n    !branchRelativePath.startsWith(`..${path.sep}`) &&\n    !path.isAbsolute(branchRelativePath);\n  let dirGone = false;\n  if (branchDirIsContained) {\n    let rmError: NodeJS.ErrnoException | undefined;\n    await fs.rm(branchDir, { recursive: true, force: true }).catch((err: unknown) => {","sourceCodeStart":1243,"sourceCodeEnd":1279,"githubUrl":"https://github.com/abhigyanpatwari/GitNexus/blob/ac9a4e9abd8fd3058c070b72c23402a4f887929a/gitnexus/src/storage/repo-manager.ts#L1243-L1279","documentation":"When an explicit storagePath is provided for branch-metadata adoption, inspectStoragePath is run and must report state 'owned' — i.e. the directory's metadata identifies this repository as owner. Any other state (unowned, owned-by-another-repo, corrupt, empty) aborts the adoption, preventing a branch index from being attached to storage that belongs to someone else or has no valid ownership receipt.","triggerScenarios":"registerRepo branch adoption with resolvedStoragePath defined while inspectStoragePath(storagePath, resolved) returns a state other than 'owned' — e.g. the directory was never analyzed, its metadata names a different repo, or the metadata is missing/corrupt.","commonSituations":"Pointing branch adoption at an external directory another project owns; the external slot was wiped or its metadata deleted; two repos misconfigured with the same GITNEXUS_STORAGE_PATH slot.","solutions":["Run `gitnexus analyze` with that storagePath for this repository first so the ownership metadata exists.","Inspect the metadata file under the storage directory and correct the repoPath/ownership recorded there.","Choose the storage directory this repository actually owns (default .gitnexus or its external slot).","Ensure no two repositories share the same GITNEXUS_STORAGE_PATH slot."],"exampleFix":"// before\nawait adoptBranch(repo, branch, { storagePath: \"/shared/other-repo-slot\" });\n// after\nawait analyze({ repo, storagePath: \"/repos/repo/.gitnexus\" });\nawait adoptBranch(repo, branch, { storagePath: \"/repos/repo/.gitnexus\" });","handlingStrategy":"validation","validationCode":"const meta = JSON.parse(await readFile(path.join(storagePath, \"index-meta.json\"), \"utf8\"));\nif (path.resolve(meta.repoPath) !== path.resolve(repoPath)) {\n  throw new Error(`storage not owned by ${repoPath} (owned by ${meta.repoPath})`);\n}","typeGuard":null,"tryCatchPattern":"try {\n  await adoptBranchMetadata(repo, branch, { storagePath });\n} catch (err) {\n  if (/storage is not owned by this repository/.test(String(err)) && /\\((.+)\\)/.test(String(err))) {\n    const state = err.message.match(/\\((.+)\\)/)[1];\n    if (state === \"unowned\" || state === \"missing\") await analyze({ repo, storagePath });\n  } else throw err;\n}","preventionTips":["Ensure the storage directory has this repo's ownership metadata (analyze there first).","Never point two repositories at the same external storage slot.","Verify storage directories weren't wiped/recreated before branch operations."],"tags":["storage","ownership","branch","validation"],"backgroundTag":"permission-denied","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"}