Compare commits

...
Author SHA1 Message Date
Julius Marmingeandcodex c4945aad27 Use structural Git status semantics
Co-authored-by: codex <[email protected]>
2026-06-20 19:21:50 -07:00
2 changed files with 34 additions and 31 deletions

No files matched your search

+32 -5
View File
@@ -638,6 +638,7 @@ function makeManager(input?: {
ghScenario?: FakeGhScenario;
textGeneration?: Partial<FakeGitTextGeneration>;
setupScriptRunner?: ProjectSetupScriptRunner.ProjectSetupScriptRunner["Service"];
vcsDriverLayer?: Layer.Layer<GitVcsDriver.GitVcsDriver>;
}) {
const { service: gitHubCli, ghCalls } = createGitHubCliWithFakeGh(input?.ghScenario);
const textGeneration = createTextGeneration(input?.textGeneration);
@@ -647,11 +648,13 @@ function makeManager(input?: {
const serverSettingsLayer = ServerSettings.ServerSettingsService.layerTest();
const vcsDriverLayer = GitVcsDriver.layer.pipe(
Layer.provideMerge(VcsProcess.layer),
Layer.provideMerge(NodeServices.layer),
Layer.provideMerge(serverConfigLayer),
);
const vcsDriverLayer =
input?.vcsDriverLayer ??
GitVcsDriver.layer.pipe(
Layer.provideMerge(VcsProcess.layer),
Layer.provideMerge(NodeServices.layer),
Layer.provideMerge(serverConfigLayer),
);
const sourceControlRegistryLayer = Layer.effect(
SourceControlProviderRegistry.SourceControlProviderRegistry,
GitHubSourceControlProvider.make.pipe(
@@ -934,6 +937,30 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
}),
);
it.effect("does not classify Git command failures from message text", () =>
Effect.gen(function* () {
const cwd = "/workspace";
const cause = new Error("spawn failed");
const commandError = new GitCommandError({
operation: "GitVcsDriver.statusDetails.status",
command: "git",
cwd,
detail: "not a git repository",
cause,
});
const { manager } = yield* makeManager({
vcsDriverLayer: Layer.mock(GitVcsDriver.GitVcsDriver)({
statusDetailsLocal: () => Effect.fail(commandError),
}),
});
const error = yield* manager.localStatus({ cwd }).pipe(Effect.flip);
expect(error).toBe(commandError);
expect(error.cause).toBe(cause);
}),
);
it.effect("status briefly caches repeated lookups for the same cwd", () =>
Effect.gen(function* () {
const repoDir = yield* makeTempDir("t3code-git-manager-");
+2 -26
View File
@@ -15,7 +15,6 @@ import * as Ref from "effect/Ref";
import {
GitActionProgressEvent,
GitActionProgressPhase,
GitCommandError,
GitPreparePullRequestThreadInput,
GitPreparePullRequestThreadResult,
GitPullRequestRefInput,
@@ -99,10 +98,6 @@ type StripProgressContext<T> = T extends any ? Omit<T, "actionId" | "cwd" | "act
type GitActionProgressPayload = StripProgressContext<GitActionProgressEvent>;
type GitActionProgressEmitter = (event: GitActionProgressPayload) => Effect.Effect<void, never>;
function isNotGitRepositoryError(error: GitCommandError): boolean {
return error.message.toLowerCase().includes("not a git repository");
}
interface OpenPrInfo {
number: number;
title: string;
@@ -727,25 +722,8 @@ export const make = Effect.gen(function* () {
const canonicalizeExistingPath = (value: string) =>
fileSystem.realPath(value).pipe(Effect.orElseSucceed(() => value));
const normalizeStatusCacheKey = canonicalizeExistingPath;
const nonRepositoryStatusDetails = {
isRepo: false,
hasOriginRemote: false,
isDefaultBranch: false,
branch: null,
upstreamRef: null,
hasWorkingTreeChanges: false,
workingTree: { files: [], insertions: 0, deletions: 0 },
hasUpstream: false,
aheadCount: 0,
behindCount: 0,
aheadOfDefaultCount: 0,
} satisfies GitVcsDriver.GitStatusDetails;
const readLocalStatus = Effect.fn("readLocalStatus")(function* (cwd: string) {
const details = yield* gitCore
.statusDetailsLocal(cwd)
.pipe(
Effect.catchIf(isNotGitRepositoryError, () => Effect.succeed(nonRepositoryStatusDetails)),
);
const details = yield* gitCore.statusDetailsLocal(cwd);
const hostingProvider = details.isRepo
? yield* resolveHostingProvider(cwd, details.branch)
: null;
@@ -772,9 +750,7 @@ export const make = Effect.gen(function* () {
cwd: string,
options?: GitVcsDriver.GitRemoteStatusOptions,
) {
const details = yield* gitCore
.statusDetailsRemote(cwd, options)
.pipe(Effect.catchIf(isNotGitRepositoryError, () => Effect.succeed(null)));
const details = yield* gitCore.statusDetailsRemote(cwd, options);
if (details === null || !details.isRepo) {
return null;
}