Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/mobile/src/features/review/useReviewDiffData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ export function useReviewDiffData(input: {
file: {
path: file.path,
previousPath: file.previousPath,
...(file.changeType ? { changeType: file.changeType } : {}),
sourceKind: lazySource.kind,
},
},
Expand Down
54 changes: 53 additions & 1 deletion apps/server/src/vcs/GitVcsDriverCore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3463,7 +3463,12 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
const scoped = yield* driver.getReviewDiffPreview({
cwd: projectDirectory,
baseRef: initialBranch,
file: { path: file.path, previousPath: file.previousPath, sourceKind: source.kind },
file: {
path: file.path,
previousPath: file.previousPath,
sourceKind: source.kind,
...(file.changeType ? { changeType: file.changeType } : {}),
},
});
const patch = scoped.sources.find((item) => item.kind === source.kind)!;
assert.deepStrictEqual(patch.files, [file]);
Expand All @@ -3474,6 +3479,53 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
}),
);

it.effect(
"lists untracked files for a file the preview called tracked only when it is not",
() =>
Effect.gen(function* () {
const cwd = yield* makeTmpDir();
yield* initRepoWithCommit(cwd);
yield* writeTextFile(cwd, "tracked.txt", "one\n");
yield* git(cwd, ["add", "."]);
yield* git(cwd, ["commit", "-m", "tracked"]);
yield* writeTextFile(cwd, "tracked.txt", "two\n");
yield* writeTextFile(cwd, "README.md", "dirty\n");
const delegate = yield* ChildProcessSpawner.ChildProcessSpawner;
let listings = 0;
const spawner = ChildProcessSpawner.make((command) => {
if (ChildProcess.isStandardCommand(command) && command.args.includes("--others")) {
listings++;
}
return delegate.spawn(command);
});
const driver = yield* makeGitVcsDriverCore().pipe(
Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner),
);
const read = (path: string, changeType?: "change") =>
driver
.getReviewDiffPreview({
cwd,
file: {
path,
previousPath: null,
sourceKind: "working-tree",
...(changeType ? { changeType } : {}),
},
})
.pipe(Effect.map((preview) => preview.sources[0]!));

const tracked = yield* read("tracked.txt", "change");
assert.include(tracked.diff, "+two");
assert.equal(listings, 0);

// A stale hint: the file left the index after the preview listed it.
yield* git(cwd, ["rm", "--cached", "-q", "README.md"]);
const stale = yield* read("README.md", "change");
assert.equal(listings, 1);
assert.deepStrictEqual(stale, yield* read("README.md"));
}),
);

it.effect("rejects a file selector for a different source than the request", () =>
Effect.gen(function* () {
const cwd = yield* makeTmpDir();
Expand Down
26 changes: 22 additions & 4 deletions apps/server/src/vcs/GitVcsDriverCore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4655,13 +4655,30 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
exitCode: result.exitCode,
});
});
// A file the preview did not list as new is stat-ed against the real index first. `git diff`
// lists an indexed path as anything but deleted, and `ls-files --others` never lists one.
const indexedRef =
input.file && !input.trackedOnly && input.file.changeType && input.file.changeType !== "new"
? (dirtyRef ?? review.mergeBase)
: null;
const indexedStat = indexedRef === null ? undefined : yield* readStats(indexedRef);
const indexed =
indexedStat?.files.some(
(file) =>
file.path === input.file?.path &&
file.changeType !== undefined &&
file.changeType !== "deleted",
) === true;
const readTrackedDiff = Effect.fn("GitVcsDriver.getReviewDiffPreview.tracked")(function* (
ref: string | null,
env?: NodeJS.ProcessEnv,
metadataOnly = false,
) {
if (ref === null) return { stdout: "", stdoutTruncated: false, files: [] };
const stat = yield* readStats(ref, env);
const stat =
env === undefined && ref === indexedRef && indexedStat !== undefined
? indexedStat
: yield* readStats(ref, env);
if (metadataOnly || stat.files.length === 0) {
return { stdout: "", stdoutTruncated: false, files: stat.files };
}
Expand All @@ -4674,9 +4691,10 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
return { ...patch, files: stat.files };
});
const [dirtyTrackedResult, baseResult] = yield* Effect.gen(function* () {
const untracked = input.trackedOnly
? { env: undefined, omitted: false }
: yield* prepareUntrackedReviewIndex(cwd, pathArgs, input.file?.path);
const untracked =
input.trackedOnly || indexed
? { env: undefined, omitted: false }
: yield* prepareUntrackedReviewIndex(cwd, pathArgs, input.file?.path);
// Untracked files left out make the file list partial, so the bounded patch is sent instead.
const complete = untracked !== null && !untracked.omitted;
// With no untracked files to add, the tracked read already is the complete diff.
Expand Down
1 change: 1 addition & 0 deletions apps/web/src/components/diffs/useReviewFilePatches.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ function reviewFileQueries({
file: {
path: file.path,
previousPath: file.previousPath,
...(file.changeType ? { changeType: file.changeType } : {}),
sourceKind: source.kind,
},
},
Expand Down
20 changes: 11 additions & 9 deletions packages/contracts/src/review.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ const ReviewMergeBase = Schema.String.check(
Schema.isPattern(/^(?:[0-9a-f]{40}|[0-9a-f]{64}|HEAD)$/),
);

export const ReviewDiffChangeType = Schema.Literals([
"change",
"rename-pure",
"rename-changed",
"new",
"deleted",
]);
export type ReviewDiffChangeType = typeof ReviewDiffChangeType.Type;

export const ReviewDiffPreviewInput = Schema.Struct({
cwd: TrimmedNonEmptyString,
baseRef: Schema.optional(TrimmedNonEmptyString),
Expand All @@ -25,6 +34,8 @@ export const ReviewDiffPreviewInput = Schema.Struct({
path: Schema.NonEmptyString,
previousPath: Schema.NullOr(Schema.NonEmptyString),
sourceKind: Schema.Literals(["working-tree", "branch-range", "commit"]),
// The preview's change type; the server still confirms a tracked path before relying on it.
changeType: Schema.optionalKey(ReviewDiffChangeType),
}),
),
});
Expand Down Expand Up @@ -55,15 +66,6 @@ export const ReviewDiffPreviewSourceKind = Schema.Literals([
]);
export type ReviewDiffPreviewSourceKind = typeof ReviewDiffPreviewSourceKind.Type;

export const ReviewDiffChangeType = Schema.Literals([
"change",
"rename-pure",
"rename-changed",
"new",
"deleted",
]);
export type ReviewDiffChangeType = typeof ReviewDiffChangeType.Type;

export const ReviewDiffFileStat = Schema.Struct({
path: Schema.String,
previousPath: Schema.NullOr(Schema.String),
Expand Down
Loading