@devries-cameron20 / t3code-1 / commits / e5d4322c10
Fork 0

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

fix(server): expand unchanged lines beside Git ident keywords (#36774)

Co-authored-by: Julius Marminge <julius0216@outlook.com>

Wout Stiens committed Nov 14, 2026 at 15:53 UTC e5d4322c10df7f68b590f653f2b5c2a162a007b9
3 files changed +176 -1
apps/server/src/vcs/GitVcsDriverCore.test.ts
+71
@@ -3712,6 +3712,77 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
3712 }),
3713 );
3714
3715 + it.effect("loads working-tree contents as Git diffs them under the ident attribute", () =>
3716 + Effect.gen(function* () {
3717 + const cwd = yield* makeTmpDir();
3718 + yield* initRepoWithCommit(cwd);
3719 + const driver = yield* GitVcsDriver.GitVcsDriver;
3720 + const fileSystem = yield* FileSystem.FileSystem;
3721 + const filePath = (yield* Path.Path).join(cwd, "README.md");
3722 + const committed = "$Id$\nfirst\nsecond\n";
3723 + yield* writeTextFile(cwd, ".gitattributes", "README.md ident\n");
3724 + yield* writeTextFile(cwd, "README.md", committed);
3725 + yield* writeTextFile(cwd, "PLAIN.md", "plain\n");
3726 + yield* git(cwd, ["add", "."]);
3727 + yield* git(cwd, ["commit", "-m", "add ident keyword"]);
3728 + // Checkout smudges the keyword to `$Id: <blob> $`.
3729 + yield* fileSystem.remove(filePath);
3730 + yield* git(cwd, ["checkout-index", "--force", "README.md"]);
3731 + const smudged = yield* fileSystem.readFileString(filePath);
3732 + assert.match(smudged, /^\$Id: [0-9a-f]{40} \$\n/);
3733 + yield* writeTextFile(cwd, "README.md", smudged.replace("first", "edited"));
3734 + yield* writeTextFile(cwd, "PLAIN.md", "$Id: literal $\n");
3735 + const disk = yield* fileSystem.readFile(filePath);
3736 +
3737 + const contents = yield* driver.getReviewDiffFileContents(
3738 + makeReviewDiffFileContentsInput(cwd),
3739 + );
3740 + const plain = yield* driver.getReviewDiffFileContents(
3741 + makeReviewDiffFileContentsInput(cwd, { oldPath: "PLAIN.md", newPath: "PLAIN.md" }),
3742 + );
3743 +
3744 + assert.deepStrictEqual(contents, {
3745 + oldContents: committed,
3746 + newContents: "$Id$\nedited\nsecond\n",
3747 + });
3748 + assert.strictEqual(plain.newContents, "$Id: literal $\n");
3749 + yield* writeTextFile(cwd, "README.md", "$Id: x $Id: y $\n");
3750 + const sharedDollar = yield* driver.getReviewDiffFileContents(
3751 + makeReviewDiffFileContentsInput(cwd),
3752 + );
3753 + assert.strictEqual(sharedDollar.newContents, "$Id$Id: y $\n");
3754 + yield* git(cwd, ["config", "filter.unrelated.clean", "touch filter-ran; cat"]);
3755 + yield* writeTextFile(cwd, ".gitattributes", "README.md ident text eol=lf\n");
3756 + yield* writeTextFile(
3757 + cwd,
3758 + "README.md",
3759 + smudged.replace("first", "edited").replaceAll("\n", "\r\n"),
3760 + );
3761 + const crlf = yield* driver.getReviewDiffFileContents(makeReviewDiffFileContentsInput(cwd));
3762 + assert.strictEqual(crlf.newContents, "$Id$\r\nedited\r\nsecond\r\n");
3763 + yield* fileSystem.writeFile(filePath, disk);
3764 + yield* writeTextFile(cwd, ".gitattributes", "README.md ident=set\n");
3765 + const literal = yield* driver.getReviewDiffFileContents(
3766 + makeReviewDiffFileContentsInput(cwd),
3767 + );
3768 + assert.strictEqual(literal.newContents, smudged.replace("first", "edited"));
3769 + yield* writeTextFile(cwd, ".gitattributes", "README.md ident filter=probe\n");
3770 + yield* git(cwd, ["config", "filter.probe.clean", "touch filter-ran; cat"]);
3771 + const filtered = yield* driver.getReviewDiffFileContents(
3772 + makeReviewDiffFileContentsInput(cwd),
3773 + );
3774 + assert.strictEqual(filtered.newContents, literal.newContents);
3775 + yield* writeTextFile(cwd, ".gitattributes", "README.md ident filter=unspecified\n");
3776 + yield* git(cwd, ["config", "filter.unspecified.clean", "touch filter-ran; cat"]);
3777 + const reservedFilter = yield* driver.getReviewDiffFileContents(
3778 + makeReviewDiffFileContentsInput(cwd),
3779 + );
3780 + assert.strictEqual(reservedFilter.newContents, literal.newContents);
3781 + assert.isFalse(yield* fileSystem.exists((yield* Path.Path).join(cwd, "filter-ran")));
3782 + assert.deepStrictEqual(yield* fileSystem.readFile(filePath), disk);
3783 + }),
3784 + );
3785 +
3786 it.effect("Changes combines commits, uncommitted edits, and untracked files", () =>
3787 Effect.gen(function* () {
3788 const cwd = yield* makeTmpDir();
apps/server/src/vcs/GitVcsDriverCore.ts
+39 -1
@@ -97,6 +97,8 @@ const REVIEW_UNTRACKED_MAX_BYTES = 256 * 1024 * 1024;
97 const UNTRACKED_TOTALS_RETRY_MIN_MS = 60_000;
98 const UNTRACKED_TOTALS_RETRY_MAX_MS = 30 * 60_000;
99 const REVIEW_DIFF_FILE_MAX_OUTPUT_BYTES = 1024 * 1024;
100 +// Git's ident clean step (convert.c ident_to_git): `$Id:` up to the next `$` on the same line.
101 +const GIT_IDENT_KEYWORD = /\$Id:[^$\n]*\$/g;
102 const REVIEW_BRANCH_COMMIT_LIMIT = 100;
103 const REVIEW_BRANCH_SUBJECT_LIMIT = 300;
104 const REVIEW_BRANCH_COMMIT_MAX_OUTPUT_BYTES = 128 * 1024;
@@ -4216,7 +4218,43 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
4218 if (bytes.includes(0)) {
4219 return yield* fileError("fs.readFile", `Cannot expand binary file '${input.newPath}'.`);
4220 }
4219 - return new TextDecoder("utf-8", { ignoreBOM: true }).decode(bytes);
4221 + const contents = new TextDecoder("utf-8", { ignoreBOM: true }).decode(bytes);
4222 + if (!contents.includes("$Id:")) return contents;
4223 + const collapsed = contents.replace(GIT_IDENT_KEYWORD, () => "$Id$");
4224 + if (collapsed === contents) return contents;
4225 + // check-attr reports both boolean ident and literal ident=set as "set".
4226 + const attribute = yield* runGitStdout(
4227 + "GitVcsDriver.getReviewDiffFileContents.workingTree.ident",
4228 + repositoryRoot,
4229 + ["check-attr", "-z", "ident", "filter", "--", input.newPath],
4230 + );
4231 + const attributes = attribute.split("\0");
4232 + if (attributes[2] !== "set" || attributes[5] !== "unspecified") return contents;
4233 +
4234 + // Literal filter=unspecified is indistinguishable from an absent filter in check-attr.
4235 + const filters = yield* executeGit(
4236 + "GitVcsDriver.getReviewDiffFileContents.workingTree.filters",
4237 + repositoryRoot,
4238 + ["config", "--name-only", "--get-regexp", "^filter\\.unspecified\\."],
4239 + { allowNonZeroExit: true },
4240 + );
4241 + if (filters.exitCode !== 1 || filters.stdout.length > 0) return contents;
4242 + // Probe a nonoverlapping keyword so ident conversion runs once on the actual file.
4243 + const [canonicalHash, collapsedHash] = yield* Effect.all([
4244 + runGitStdoutWithOptions(
4245 + "GitVcsDriver.getReviewDiffFileContents.workingTree.canonicalHash",
4246 + repositoryRoot,
4247 + ["hash-object", "--stdin", `--path=${input.newPath}`],
4248 + { stdin: "$Id: probe $" },
4249 + ),
4250 + runGitStdoutWithOptions(
4251 + "GitVcsDriver.getReviewDiffFileContents.workingTree.collapsedHash",
4252 + repositoryRoot,
4253 + ["hash-object", "--stdin", `--path=${input.newPath}`],
4254 + { stdin: "$Id$" },
4255 + ),
4256 + ]);
4257 + return canonicalHash === collapsedHash ? collapsed : contents;
4258 });
4259
4260 const getReviewDiffFileContents = Effect.fn("getReviewDiffFileContents")(function* (
scripts/scenarios/ident-diff-expands-unchanged-lines.e2e.ts new
+66
@@ -0,0 +1,66 @@
1 +/// <reference lib="dom" />
2 +// The DOM lib types the functions this scenario runs in the page.
3 +import { expect } from "e2e";
4 +import * as Effect from "effect/Effect";
5 +import * as FileSystem from "effect/FileSystem";
6 +
7 +import { run } from "./shell.ts";
8 +import { runPromise, test, WEB } from "./t3.ts";
9 +
10 +const LINES = Array.from({ length: 40 }, (_, index) => `line ${index + 1}`);
11 +
12 +test(
13 + "The diff expands unchanged lines beside a Git ident keyword",
14 + WEB,
15 + async ({ t3, app, browser, screen }) => {
16 + const project = await t3.project("demo", {
17 + ".gitattributes": "notes.txt ident\n",
18 + "notes.txt": `$Id$\n${LINES.join("\n")}\n`,
19 + });
20 + const notes = `${project}/notes.txt`;
21 + // Checkout smudges `$Id$` to `$Id: <blob> $`; then edit a line inside its hunk.
22 + await runPromise(
23 + Effect.gen(function* () {
24 + const fs = yield* FileSystem.FileSystem;
25 + yield* fs.remove(notes);
26 + yield* run("git", ["checkout-index", "--force", "notes.txt"], { cwd: project });
27 + const smudged = yield* fs.readFileString(notes);
28 + yield* fs.writeFileString(notes, smudged.replace("line 2\n", "edited 2\n"));
29 + }),
30 + );
31 + const thread = await t3.thread({ project, title: "Ident", messages: ["first"] });
32 +
33 + // The diff renders in shadow roots that locators do not reach.
34 + const diffLines = () =>
35 + browser.evaluate(() =>
36 + Array.from(document.querySelectorAll("*")).flatMap((host) =>
37 + Array.from(host.shadowRoot?.querySelectorAll("[data-line]") ?? [], (line) =>
38 + (line.textContent ?? "").trim(),
39 + ),
40 + ),
41 + );
42 + const expandBelowHunk = () =>
43 + browser.evaluate(() => {
44 + for (const host of document.querySelectorAll("*")) {
45 + const buttons = host.shadowRoot?.querySelectorAll<HTMLElement>("[data-expand-button]");
46 + const last = buttons?.[buttons.length - 1];
47 + if (last) {
48 + last.click();
49 + return true;
50 + }
51 + }
52 + return false;
53 + });
54 +
55 + await t3.open(thread);
56 + await expect(screen.getByText("first fixture turn complete", { exact: false })).toBeVisible();
57 + await screen.getByRole("button", "Toggle right panel").tap();
58 + await screen.getByText("Diff").tap();
59 + await screen.getByRole("button", "Expand notes.txt").tap();
60 + await expect.poll(diffLines).toContain("edited 2");
61 + await expect.poll(expandBelowHunk).toBe(true);
62 + await app.screenshot("after-expand");
63 + await expect.poll(diffLines).toContain("line 30");
64 + await app.screenshot("expanded");
65 + },
66 +);