Skip to content
TypeScript

fix(server): commits and PR text see changes outside a subfolder project under diff.relative (#29879)

Alex Southwelle86dc78d6294
diff --git a/apps/server/src/vcs/GitVcsDriverCore.test.ts b/apps/server/src/vcs/GitVcsDriverCore.test.ts
index 53d031a7413..1c3e075d165 100644
--- a/apps/server/src/vcs/GitVcsDriverCore.test.ts
+++ b/apps/server/src/vcs/GitVcsDriverCore.test.ts
@@ -2849,12 +2849,13 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
}),
);
- it.effect("reads range patches from source without textconv or color", () =>
+ it.effect("reads range patches from source without textconv, color, or diff.relative", () =>
Effect.gen(function* () {
const cwd = yield* makeTmpDir();
const { initialBranch } = yield* initRepoWithCommit(cwd);
yield* git(cwd, ["config", "diff.probe.textconv", "touch textconv-ran; echo converted"]);
yield* git(cwd, ["config", "color.ui", "always"]);
+ yield* git(cwd, ["config", "diff.relative", "true"]);
yield* git(cwd, ["checkout", "-b", "feature/range"]);
yield* writeTextFile(cwd, ".gitattributes", "*.doc diff=probe\n");
yield* writeTextFile(cwd, "notes.doc", "source line\n");
@@ -2864,8 +2865,10 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
yield* git(cwd, ["commit", "-m", "range files"]);
const driver = yield* GitVcsDriver.GitVcsDriver;
const fileSystem = yield* FileSystem.FileSystem;
+ const projectCwd = `${cwd}/app`;
+ yield* fileSystem.makeDirectory(projectCwd);
- const context = yield* driver.readRangeContext(cwd, initialBranch);
+ const context = yield* driver.readRangeContext(projectCwd, initialBranch);
assert.include(context.diffPatch, "+source line");
assert.notInclude(context.diffPatch, "converted");
@@ -2878,7 +2881,7 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
assert.isFalse(yield* fileSystem.exists(`${cwd}/textconv-ran`));
yield* writeTextFile(cwd, "notes.doc", "updated source line\n");
- const staged = yield* driver.prepareCommitContext(cwd, ["notes.doc"]);
+ const staged = yield* driver.prepareCommitContext(projectCwd, ["notes.doc"]);
assert.include(staged?.stagedPatch ?? "", "+updated source line");
assert.notInclude(staged?.stagedPatch ?? "", "converted");
assert.notInclude(staged?.stagedPatch ?? "", "\u001b[");
diff --git a/apps/server/src/vcs/GitVcsDriverCore.ts b/apps/server/src/vcs/GitVcsDriverCore.ts
index 4ace91f8017..2736cbc6d4f 100644
--- a/apps/server/src/vcs/GitVcsDriverCore.ts
+++ b/apps/server/src/vcs/GitVcsDriverCore.ts
@@ -2525,7 +2525,8 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
const stagedSummary = yield* runGitStdoutWithOptions(
"GitVcsDriver.prepareCommitContext.stagedSummary",
cwd,
- ["diff", "--cached", "--name-status"],
+ // cwd can be a subdirectory; diff.relative would hide changes outside it.
+ ["-c", "diff.relative=false", "diff", "--cached", "--name-status"],
{ env, maxOutputBytes: REVIEW_METADATA_MAX_OUTPUT_BYTES },
).pipe(Effect.map((stdout) => stdout.trim()));
if (stagedSummary.length === 0) {
@@ -2539,6 +2540,8 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
"GitVcsDriver.prepareCommitContext.stagedPatch",
cwd,
[
+ "-c",
+ "diff.relative=false",
"diff",
"--no-color",
"--no-ext-diff",
@@ -2948,7 +2951,15 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
runGitStdoutWithOptions(
"GitVcsDriver.readRangeContext.diffStat",
cwd,
- ["diff", "--stat", "--no-color", "--end-of-options", diffRange],
+ [
+ "-c",
+ "diff.relative=false",
+ "diff",
+ "--stat",
+ "--no-color",
+ "--end-of-options",
+ diffRange,
+ ],
{
maxOutputBytes: RANGE_DIFF_SUMMARY_MAX_OUTPUT_BYTES,
appendTruncationMarker: true,
@@ -2958,6 +2969,8 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
"GitVcsDriver.readRangeContext.diffPatch",
cwd,
[
+ "-c",
+ "diff.relative=false",
"diff",
"--no-color",
"--no-ext-diff",