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
29 changes: 29 additions & 0 deletions apps/server/src/vcs/GitVcsDriverCore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3029,6 +3029,35 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
}),
);

it.effect("keeps the review working beside a nested repository with no commits", () =>
Effect.gen(function* () {
const cwd = yield* makeTmpDir();
yield* initRepoWithCommit(cwd);
const driver = yield* GitVcsDriver.GitVcsDriver;
yield* git(cwd, ["init", "scaffold"]);
const committed = `${cwd}/committed`;
yield* (yield* FileSystem.FileSystem).makeDirectory(committed);
yield* initRepoWithCommit(committed);
yield* writeTextFile(cwd, "README.md", "# tracked change\n");
yield* writeTextFile(cwd, "untracked.txt", "untracked contents\n");

const preview = yield* driver.getReviewDiffPreview({ cwd, ignoreWhitespace: false });
const diff = preview.sources.find((source) => source.kind === "working-tree")?.diff ?? "";

assert.include(diff, "+# tracked change");
assert.include(diff, "+untracked contents");
assert.notInclude(diff, "scaffold");
assert.include(diff, "diff --git a/committed b/committed");

const status = yield* driver.statusDetailsLocal(cwd, { includeBranchChanges: true });
assert.deepStrictEqual(status.branchChanges, {
baseRef: null,
insertions: 3,
deletions: 1,
});
}),
);

it.effect("keeps untracked filenames with pathspec magic in the review", () =>
Effect.gen(function* () {
const cwd = yield* makeTmpDir();
Expand Down
16 changes: 15 additions & 1 deletion apps/server/src/vcs/GitVcsDriverCore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3349,7 +3349,21 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
);
const stagedDeletions = new Set(stagedDeletionsStdout.split("\0").filter(Boolean));
// Staged deletions never enter the index, so their worktree copies must not spend the budget.
const candidates = untrackedPaths.filter((relativePath) => !stagedDeletions.has(relativePath));
// A nested repository (listed with a trailing slash) with no commits cannot be indexed:
// Git before 2.53 fails the add, and later versions accept it and then fail every diff.
const candidates = yield* Effect.filter(
untrackedPaths.filter((relativePath) => !stagedDeletions.has(relativePath)),
(relativePath) =>
relativePath.endsWith("/")
? executeGit(
"GitVcsDriver.readUnifiedWorkingTreeReviewDiff.nestedRepositoryHead",
path.resolve(cwd, relativePath),
["rev-parse", "--verify", "--quiet", "HEAD"],
{ allowNonZeroExit: true },
).pipe(Effect.map((result) => result.exitCode !== 1))
: Effect.succeed(true),
{ concurrency: 16 },
);
const sizes = yield* Effect.forEach(
candidates,
(relativePath) =>
Expand Down
Loading