diff --git a/README.md b/README.md index 19da222..ef455b8 100644 --- a/README.md +++ b/README.md @@ -284,11 +284,20 @@ The repository hash comes from the normalized Git `origin` remote, so Claude Cod Codex, Cursor, and OpenCode use the same container for the same repository. Repositories with the same name but different remotes remain isolated. Without an origin remote, OpenCode falls back to the repository's real filesystem path. +Relative local Git origins are resolved against the repository directory, not +the directory where OpenCode was launched. + +If a relative local origin previously produced a launch-directory-dependent tag, +its corrected tag will differ. Memories in that old container are not automatically +read or migrated: unrelated repositories may have shared the incorrect tag. To +keep a known existing container, explicitly configure `projectContainerTag` only +after verifying that the container belongs to this project. OpenCode also reads previous `user_project_*`, `repo_`, `claudecode_project_*`, `codex_user_*`, `codex_project_*`, `opencode_user_*`, -`opencode_project_*`, `cursor_user_*`, and `cursor_project_*` containers, so upgrading -does not require a migration. +`opencode_project_*`, `cursor_user_*`, and `cursor_project_*` containers. Those +legacy containers remain readable without migration; this does not include the +incorrect relative-origin containers described above. ## Configuration diff --git a/src/services/tags.test.ts b/src/services/tags.test.ts index 6cf8bd7..cb498e6 100644 --- a/src/services/tags.test.ts +++ b/src/services/tags.test.ts @@ -1,5 +1,14 @@ import { describe, expect, test } from "bun:test"; -import { normalizeGitRemote, sanitizeRepoName } from "./tags.js"; +import { execFileSync } from "node:child_process"; +import { mkdtempSync, mkdirSync, rmSync } from "node:fs"; +import { tmpdir } from "node:os"; +import { join } from "node:path"; +import { + getGeneratedProjectTag, + getProjectIdentity, + normalizeGitRemote, + sanitizeRepoName, +} from "./tags.js"; describe("repository identity", () => { test("normalizes equivalent HTTPS and SSH remotes", () => { @@ -17,3 +26,53 @@ describe("repository identity", () => { ); }); }); + +describe("local Git origin identity", () => { + function repository(path: string, origin: string): void { + mkdirSync(path, { recursive: true }); + execFileSync("git", ["init", "--quiet", path]); + execFileSync("git", ["-C", path, "remote", "add", "origin", origin]); + // Git itself must resolve the configured origin successfully. + execFileSync("git", ["-C", path, "ls-remote", "origin"]); + } + + test("relative and absolute origins for the same repository share identity", () => { + const root = mkdtempSync(join(tmpdir(), "supermemory-local-origin-")); + try { + const upstream = join(root, "upstream.git"); + execFileSync("git", ["init", "--bare", "--quiet", upstream]); + const relative = join(root, "relative"); + const absolute = join(root, "absolute"); + repository(relative, "../upstream.git"); + repository(absolute, upstream); + expect(getProjectIdentity(relative)).toBe(getProjectIdentity(absolute)); + expect(getGeneratedProjectTag(relative)).toBe( + getGeneratedProjectTag(absolute), + ); + } finally { + rmSync(root, { recursive: true, force: true }); + } + }); + + test("identical relative origin strings in different roots stay isolated", () => { + const root = mkdtempSync(join(tmpdir(), "supermemory-local-origin-")); + try { + const projects = ["first", "second"].map((name) => { + const parent = join(root, name); + mkdirSync(parent); + execFileSync("git", ["init", "--bare", "--quiet", join(parent, "upstream.git")]); + const project = join(parent, "project"); + repository(project, "../upstream.git"); + return project; + }); + expect(getProjectIdentity(projects[0]!)).not.toBe( + getProjectIdentity(projects[1]!), + ); + expect(getGeneratedProjectTag(projects[0]!)).not.toBe( + getGeneratedProjectTag(projects[1]!), + ); + } finally { + rmSync(root, { recursive: true, force: true }); + } + }); +}); diff --git a/src/services/tags.ts b/src/services/tags.ts index e520f10..c75da1c 100644 --- a/src/services/tags.ts +++ b/src/services/tags.ts @@ -80,7 +80,10 @@ function getGitEmail(directory: string): string | null { } } -export function normalizeGitRemote(remoteUrl: string): string | null { +export function normalizeGitRemote( + remoteUrl: string, + directory: string = process.cwd(), +): string | null { const raw = remoteUrl.trim(); if (!raw) return null; @@ -102,7 +105,7 @@ export function normalizeGitRemote(remoteUrl: string): string | null { normalized = scpStyle?.[1] && scpStyle[2] ? `${scpStyle[1].toLowerCase()}/${scpStyle[2]}` - : `file:${resolve(raw)}`; + : `file:${resolve(directory, raw)}`; } return normalized @@ -127,7 +130,7 @@ function getGitRepoInfo(directory: string): { stdio: ["pipe", "pipe", "pipe"], windowsHide: true, }).trim(); - const normalizedRemote = normalizeGitRemote(remoteUrl); + const normalizedRemote = normalizeGitRemote(remoteUrl, directory); const displayRemote = remoteUrl.replace(/\/+$/, "").replace(/\.git$/i, ""); const separator = Math.max( displayRemote.lastIndexOf("/"),