TypeScript
perf(server): skip unused diffs for user-written commit messages (#19605)
Microcke2cc34f1e47a
diff --git a/apps/server/src/git/GitManager.test.ts b/apps/server/src/git/GitManager.test.tsindex 32337ad4696..bc40c56d6d7 100644--- a/apps/server/src/git/GitManager.test.ts+++ b/apps/server/src/git/GitManager.test.ts@@ -3804,6 +3804,13 @@ it.layer(layerGitManagerTest)("GitManager", (it) => {Effect.gen(function* () {const repoDir = yield* makeTempDir("t3code-git-manager-");yield* initRepo(repoDir);+ // Patch generation would invoke this unavailable converter. A supplied+ // message must commit without generating a patch it will not use.+ NodeFS.writeFileSync(+ NodePath.join(repoDir, ".git/info/attributes"),+ "README.md diff=probe\n",+ );+ yield* runGit(repoDir, ["config", "diff.probe.textconv", "t3-missing-textconv-for-test"]);NodeFS.writeFileSync(NodePath.join(repoDir, "README.md"), "hello\ncustom\n");let generatedCount = 0;diff --git a/apps/server/src/git/GitManager.ts b/apps/server/src/git/GitManager.tsindex f24fc8d43ff..d6eb2458961 100644--- a/apps/server/src/git/GitManager.ts+++ b/apps/server/src/git/GitManager.ts@@ -2037,12 +2037,14 @@ export const make = Effect.gen(function* () {filePaths?: readonly string[];settings: SourceControlTextGenerationSettings;}) {- const context = yield* gitCore.prepareCommitContext(input.cwd, input.filePaths);+ const customCommit = parseCustomCommitMessage(input.commitMessage ?? "");+ const context = yield* gitCore.prepareCommitContext(input.cwd, input.filePaths, {+ includePatch: customCommit === null,+ });if (!context) {return null;}- const customCommit = parseCustomCommitMessage(input.commitMessage ?? "");if (customCommit) {return {subject: customCommit.subject,diff --git a/apps/server/src/vcs/GitVcsDriver.ts b/apps/server/src/vcs/GitVcsDriver.tsindex c1684be0e1c..88642ed9d74 100644--- a/apps/server/src/vcs/GitVcsDriver.ts+++ b/apps/server/src/vcs/GitVcsDriver.ts@@ -306,6 +306,7 @@ export class GitVcsDriver extends Context.Service<readonly prepareCommitContext: (cwd: string,filePaths?: readonly string[],+ options?: { readonly includePatch?: boolean },) => Effect.Effect<GitPreparedCommitContext | null, GitCommandError>;readonly commit: (cwd: string,diff --git a/apps/server/src/vcs/GitVcsDriverCore.test.ts b/apps/server/src/vcs/GitVcsDriverCore.test.tsindex e4d489b69db..7e65262e79c 100644--- a/apps/server/src/vcs/GitVcsDriverCore.test.ts+++ b/apps/server/src/vcs/GitVcsDriverCore.test.ts@@ -3984,6 +3984,29 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {});describe("commit context", () => {+ it.effect("can omit the patch while preserving change detection and the real index", () =>+ Effect.gen(function* () {+ const cwd = yield* makeTmpDir();+ yield* initRepoWithCommit(cwd);+ const driver = yield* GitVcsDriver.GitVcsDriver;+ assert.isNull(yield* driver.prepareCommitContext(cwd, undefined, { includePatch: false }));+ yield* writeTextFile(cwd, "selected.txt", "selected content\n");+ yield* writeTextFile(cwd, "other.txt", "other content\n");+ yield* git(cwd, ["add", "other.txt"]);+ const before = yield* git(cwd, ["diff", "--cached"]);+ const summaryOnly = yield* driver.prepareCommitContext(cwd, ["selected.txt"], {+ includePatch: false,+ });+ assert.include(summaryOnly?.stagedSummary ?? "", "selected.txt");+ assert.notInclude(summaryOnly?.stagedSummary ?? "", "other.txt");+ assert.equal(summaryOnly?.stagedPatch, "");+ const full = yield* driver.prepareCommitContext(cwd, ["selected.txt"]);+ assert.equal(full?.stagedSummary, summaryOnly?.stagedSummary);+ assert.include(full?.stagedPatch ?? "", "+selected content");+ assert.equal(yield* git(cwd, ["diff", "--cached"]), before);+ }),+ );+it.effect("prepares selected files without staging and commits only those files", () =>Effect.gen(function* () {const cwd = yield* makeTmpDir();diff --git a/apps/server/src/vcs/GitVcsDriverCore.ts b/apps/server/src/vcs/GitVcsDriverCore.tsindex 080f3c2024d..3225a7fe455 100644--- a/apps/server/src/vcs/GitVcsDriverCore.ts+++ b/apps/server/src/vcs/GitVcsDriverCore.ts@@ -2235,7 +2235,7 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*});const prepareCommitContext: GitVcsDriver.GitVcsDriver["Service"]["prepareCommitContext"] =- Effect.fn("prepareCommitContext")(function* (cwd, filePaths) {+ Effect.fn("prepareCommitContext")(function* (cwd, filePaths, options) {return yield* Effect.scoped(Effect.gen(function* () {const indexValue = yield* runGitStdout(@@ -2288,6 +2288,9 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*return null;}+ // A user-supplied message needs change detection, but no patch for generation.+ if (options?.includePatch === false) return { stagedSummary, stagedPatch: "" };+const stagedPatch = yield* runGitStdoutWithOptions("GitVcsDriver.prepareCommitContext.stagedPatch",cwd,