(cwd: string, input: string)
| 110 | |
| 111 | /** Resolve, validate and persist a new link. Idempotent on the resolved path. */ |
| 112 | export function addLink(cwd: string, input: string): LinkResult { |
| 113 | const resolved = resolveLinkTarget(input) |
| 114 | if (!resolved) return { ok: false, message: "Enter a folder path." } |
| 115 | if (path.resolve(cwd) === resolved) return { ok: false, message: "Can't link a repo to itself." } |
| 116 | if (!isDir(resolved)) return { ok: false, message: `Not a directory: ${resolved}` } |
| 117 | |
| 118 | const links = loadLinks(cwd) |
| 119 | if (links.some((l) => l.path === resolved)) return { ok: false, message: "Already linked." } |
| 120 | if (links.length >= MAX_LINKED_REPOS) { |
| 121 | return { ok: false, message: `At most ${MAX_LINKED_REPOS} linked repos.` } |
| 122 | } |
| 123 | |
| 124 | links.push({ input: input.trim(), path: resolved }) |
| 125 | saveLinks(cwd, links) |
| 126 | return { ok: true, message: `Linked ${resolved}` } |
| 127 | } |
| 128 | |
| 129 | /** Remove a link by its resolved path. */ |
| 130 | export function removeLink(cwd: string, targetPath: string): void { |
no test coverage detected