{"record":{"id":"544acd7b829963d4","repo":"stablyai/orca","slug":"could-not-find-an-available-remote-name-for-pref","errorCode":null,"errorMessage":"Could not find an available remote name for ${preferred}.","messagePattern":"Could not find an available remote name for (.+?)\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/main/ipc/worktree-push-target-setup.ts","lineNumber":69,"sourceCode":"  preferred: string\n): Promise<string> {\n  const { stdout } = await execGit(['remote'], repoPath)\n  const existing = new Set(\n    stdout\n      .split(/\\r?\\n/)\n      .map((line) => line.trim())\n      .filter(Boolean)\n  )\n  if (!existing.has(preferred)) {\n    return preferred\n  }\n  for (let suffix = 2; suffix < 100; suffix += 1) {\n    const candidate = `${preferred}-${suffix}`\n    if (!existing.has(candidate)) {\n      return candidate\n    }\n  }\n  throw new Error(`Could not find an available remote name for ${preferred}.`)\n}\n\n// Exported for unit tests: the `execGit` seam drives the remote add/reuse/fetch\n// behavior without a real repo. `isRemoteCreatedByKnownWorktree` lets the caller\n// inject the store-aware ownership decision for the reuse case.\nexport async function prepareWorktreePushTargetWithExec(\n  execGit: GitRemoteExec,\n  repoPath: string,\n  target: GitPushTarget,\n  isRemoteCreatedByKnownWorktree: (existingRemote: string) => boolean\n): Promise<GitPushTarget> {\n  const { remoteCreated: _ignoredRemoteCreated, ...sanitizedTarget } = target\n  let remoteName = target.remoteName\n  let remoteCreated = false\n  if (target.remoteUrl) {\n    const existingRemote = await findRemoteForUrl(execGit, repoPath, target.remoteUrl)\n    if (existingRemote) {\n      remoteName = existingRemote","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/stablyai/orca/blob/1136503c6a231a16dce8f921f6fadb63d181e8db/src/main/ipc/worktree-push-target-setup.ts#L51-L87","documentation":"Thrown by ensureUniqueRemoteName when the preferred git remote name and all suffixed variants (preferred-2 through preferred-99) already exist in the repository's remote list. The function lists existing remotes via `git remote`, and only after exhausting 98 candidate names does it give up. This is a guard against flooding a repo with colliding remote names during automated worktree push-target setup.","triggerScenarios":"ensureUniqueRemoteName(execGit, repoPath, preferred) where `git remote` returns a set containing 'preferred', 'preferred-2', ..., 'preferred-99'. The loop from suffix 2..99 finds no gap, so the throw fires.","commonSituations":"A repo accumulated 99+ similarly-named remotes from repeated worktree/push-target setup without cleanup. An automation loop kept adding remotes. A migration/import created many colliding remotes. Realistically this indicates stale-remote accumulation that should be cleaned.","solutions":["Remove stale/unused remotes with `git remote remove <name>` to free up the namespace, then retry.","Choose a different preferred name that does not collide.","If this is expected for your workflow, raise the suffix ceiling or implement a UUID-suffixed fallback in a wrapper."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"const existing = (await execGit(['remote'], repoPath)).stdout.split(/\\r?\\n/).filter(Boolean)\nif (existing.length > 90) {\n  // warn or clean up stale remotes before attempting ensureUniqueRemoteName\n}","typeGuard":null,"tryCatchPattern":"try {\n  remoteName = await ensureUniqueRemoteName(execGit, repoPath, preferred)\n} catch (e) {\n  if (/Could not find an available remote name/.test((e as Error).message)) {\n    remoteName = `${preferred}-${crypto.randomUUID().slice(0, 8)}`\n  } else throw e\n}","preventionTips":["Periodically prune stale remotes created by worktree push-target setup.","Choose a distinctive preferred name to avoid collisions.","Warn the user when the remote count grows large, indicating cleanup is needed."],"tags":["git","remote","worktree","naming","cleanup"],"backgroundTag":null,"analyzedSha":"1136503c6a231a16dce8f921f6fadb63d181e8db","analyzedAt":"2026-08-12T23:15:58.167Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}