@devries-cameron20 / t3code Mirror · read-only / commits / c7157d376d
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

fix(server): turn authorship works on Git before 2.36 (#39702)

Julius Marminge committed Nov 20, 2026 at 04:47 UTC c7157d376d828541b86f472d33e2e03f037edc32
2 files changed +123 -5
apps/server/src/vcs/GitVcsDriver.test.ts
+54
@@ -1504,6 +1504,60 @@ it.effect.each(["local", "mixed", "exit"] as const)(
1504 }).pipe(Effect.scoped, Effect.provide(layerGitContract)),
1505 );
1506
1507 +it.effect("checkpoint authorship works with git that rejects --diff-merges=remerge", () =>
1508 + Effect.gen(function* () {
1509 + const fs = yield* FileSystem.FileSystem;
1510 + const path = yield* Path.Path;
1511 + const driver = yield* GitVcsDriver.makeVcsDriverShape();
1512 + const liveProcess = yield* VcsProcess.VcsProcess;
1513 + const cwd = yield* fs.makeTempDirectoryScoped({ prefix: "t3-checkpoint-old-git-" });
1514 + const { git } = yield* makeCheckpointFixture(driver, cwd);
1515 + yield* git(["commit", "-am", "baseline"]);
1516 + const fromCheckpointRef = CheckpointRef.make("refs/t3/checkpoints/old-git/from");
1517 + const toCheckpointRef = CheckpointRef.make("refs/t3/checkpoints/old-git/to");
1518 + yield* driver.checkpoints.captureCheckpoint({ cwd, checkpointRef: fromCheckpointRef });
1519 + yield* fs.writeFileString(path.join(cwd, "local.txt"), "local\n");
1520 + yield* git(["add", "."]);
1521 + yield* git(["commit", "-m", "local"]);
1522 + yield* driver.checkpoints.captureCheckpoint({
1523 + cwd,
1524 + checkpointRef: toCheckpointRef,
1525 + previousCheckpointRef: fromCheckpointRef,
1526 + });
1527 +
1528 + // Git before 2.36 (Ubuntu 22.04 ships 2.34.1) has no remerge diff mode.
1529 + const oldGitDriver = yield* GitVcsDriver.makeVcsDriverShape().pipe(
1530 + Effect.provideService(VcsProcess.VcsProcess, {
1531 + run: (input) => {
1532 + if (input.args.at(-1) === "version" && input.args.length <= 3) {
1533 + return liveProcess
1534 + .run(input)
1535 + .pipe(Effect.map((result) => ({ ...result, stdout: "git version 2.34.1\n" })));
1536 + }
1537 + if (!input.args.includes("--diff-merges=remerge")) return liveProcess.run(input);
1538 + return Effect.fail(
1539 + new VcsProcessExitError({
1540 + operation: input.operation,
1541 + command: input.command,
1542 + cwd: input.cwd,
1543 + exitCode: 128,
1544 + detail: "fatal: unknown value for --diff-merges: remerge",
1545 + }),
1546 + );
1547 + },
1548 + }),
1549 + );
1550 + assert.deepEqual(
1551 + yield* oldGitDriver.checkpoints.listAuthoredPaths({
1552 + cwd,
1553 + fromCheckpointRef,
1554 + toCheckpointRef,
1555 + }),
1556 + new Set(["local.txt"]),
1557 + );
1558 + }).pipe(Effect.scoped, Effect.provide(layerGitContract)),
1559 +);
1560 +
1561 it.effect("a branch switch landing after the snapshot belongs to the next checkpoint", () =>
1562 Effect.gen(function* () {
1563 const fileSystem = yield* FileSystem.FileSystem;
apps/server/src/vcs/GitVcsDriver.ts
+69 -5
@@ -625,6 +625,14 @@ const HEAD_MOVES_SCAN_LIMIT = 512;
625 const HEAD_MARK_TRAILER = "T3-Head-Moved-At";
626 const HEAD_MARK_TRAILER_PATTERN = new RegExp(`^${HEAD_MARK_TRAILER}: (\\d+) (\\d+)$`, "m");
627
628 +// Parses "git version 2.34.1" or "git version 2.45.1.windows.1".
629 +const gitSupportsRemergeDiff = (versionOutput: string): boolean => {
630 + const match = /^git version (\d+)\.(\d+)/.exec(versionOutput);
631 + if (match === null) return false;
632 + const major = Number(match[1]);
633 + return major > 2 || (major === 2 && Number(match[2]) >= 36);
634 +};
635 +
636 export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* () {
637 const fileSystem = yield* FileSystem.FileSystem;
638 const path = yield* Path.Path;
@@ -690,6 +698,23 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* (
698 : {}),
699 });
700
701 + // --diff-merges=remerge needs Git 2.36.
702 + let remergeDiffSupported: boolean | undefined;
703 + const supportsRemergeDiff = Effect.fn("GitVcsDriver.supportsRemergeDiff")(function* (
704 + cwd: string,
705 + ) {
706 + if (remergeDiffSupported === undefined) {
707 + const version = yield* execute({
708 + operation: "GitVcsDriver.version",
709 + cwd,
710 + args: ["version"],
711 + }).pipe(Effect.option);
712 + if (Option.isNone(version)) return false;
713 + remergeDiffSupported = gitSupportsRemergeDiff(version.value.stdout);
714 + }
715 + return remergeDiffSupported;
716 + });
717 +
718 const detectRepository: VcsDriver.VcsDriver["Service"]["detectRepository"] = Effect.fn(
719 "detectRepository",
720 )(function* (cwd) {
@@ -2201,12 +2226,54 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* (
2226 });
2227
2228 // Remerge diffs retain merge conflict fixes while excluding clean upstream changes.
2229 + // Older Git gets dense combined diffs, which miss a conflict resolved to one side's
2230 + // version, so it also keeps every path more than one parent changed since the merge base.
2231 + const remerge = yield* supportsRemergeDiff(input.cwd);
2232 + const listMergeSharedPaths = (args: ReadonlyArray<string>, stdin?: string) =>
2233 + listLines(["rev-list", "--merges", "--parents", ...args], stdin).pipe(
2234 + Effect.flatMap((merges) =>
2235 + Effect.forEach(
2236 + merges,
2237 + Effect.fnUntraced(function* (merge) {
2238 + const parents = merge.split(" ").slice(1);
2239 + const [base] = yield* listLines(["merge-base", "--octopus", ...parents]).pipe(
2240 + // Unrelated histories have no merge base; the combined diff still applies.
2241 + Effect.orElseSucceed((): ReadonlyArray<string> => []),
2242 + );
2243 + if (base === undefined) return [];
2244 + const changed = yield* Effect.forEach(
2245 + parents,
2246 + (parent) => listPaths(["diff", base, parent]),
2247 + { concurrency: "unbounded" },
2248 + );
2249 + const counts = new Map<string, number>();
2250 + for (const path of changed.flatMap((paths) => [...new Set(paths)])) {
2251 + if (path === "") continue;
2252 + counts.set(path, (counts.get(path) ?? 0) + 1);
2253 + }
2254 + return [...counts].flatMap(([path, count]) => (count > 1 ? [path] : []));
2255 + }),
2256 + { concurrency: 4 },
2257 + ),
2258 + ),
2259 + Effect.map((lists) => lists.flat()),
2260 + );
2261 + const listCommitPaths = (args: ReadonlyArray<string>, stdin?: string) =>
2262 + remerge
2263 + ? listPaths(["log", ...args, "--format=", "--diff-merges=remerge"], stdin)
2264 + : Effect.all(
2265 + [
2266 + listPaths(["log", ...args, "--format=", "--cc"], stdin),
2267 + listMergeSharedPaths(args, stdin),
2268 + ],
2269 + { concurrency: "unbounded" },
2270 + ).pipe(Effect.map((lists) => lists.flat()));
2271 const [recentCommits, ...pathLists] = yield* Effect.all(
2272 [
2273 listLines(["rev-list", `--since=@${capturedAt}`, `${startHead}..${endHead}`]),
2274 listPaths(["diff", startHead, `${turnStart}^{commit}`]),
2275 listPaths(["diff", endHead, `${input.toCheckpointRef}^{commit}`]),
2209 - listPaths(["log", "--format=", "--diff-merges=remerge", `${endHead}..${startHead}`]),
2276 + listCommitPaths([`${endHead}..${startHead}`]),
2277 ],
2278 { concurrency: "unbounded" },
2279 );
@@ -2248,10 +2315,7 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* (
2315 const ownCommitPaths =
2316 ownCommits.length === 0
2317 ? []
2251 - : yield* listPaths(
2252 - ["log", "--no-walk=unsorted", "--stdin", "--format=", "--diff-merges=remerge"],
2253 - `${ownCommits.join("\n")}\n`,
2254 - );
2318 + : yield* listCommitPaths(["--no-walk=unsorted", "--stdin"], `${ownCommits.join("\n")}\n`);
2319 return new Set([...pathLists.flat(), ...ownCommitPaths].filter((path) => path.length > 0));
2320 }),
2321