From c4945aad2753b5c0bd27dc3d84caeede2f2f4e61 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Sat, 20 Jun 2026 17:48:51 -0700 Subject: [PATCH] Use structural Git status semantics Co-authored-by: codex --- apps/server/src/git/GitManager.test.ts | 37 ++++++++++++++++++++++---- apps/server/src/git/GitManager.ts | 28 ++----------------- 2 files changed, 34 insertions(+), 31 deletions(-) diff --git a/apps/server/src/git/GitManager.test.ts b/apps/server/src/git/GitManager.test.ts index e1924c03ad..2cc6ef22bc 100644 --- a/apps/server/src/git/GitManager.test.ts +++ b/apps/server/src/git/GitManager.test.ts @@ -638,6 +638,7 @@ function makeManager(input?: { ghScenario?: FakeGhScenario; textGeneration?: Partial; setupScriptRunner?: ProjectSetupScriptRunner.ProjectSetupScriptRunner["Service"]; + vcsDriverLayer?: Layer.Layer; }) { 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-"); diff --git a/apps/server/src/git/GitManager.ts b/apps/server/src/git/GitManager.ts index f1fb03e7e4..61af0217fb 100644 --- a/apps/server/src/git/GitManager.ts +++ b/apps/server/src/git/GitManager.ts @@ -15,7 +15,6 @@ import * as Ref from "effect/Ref"; import { GitActionProgressEvent, GitActionProgressPhase, - GitCommandError, GitPreparePullRequestThreadInput, GitPreparePullRequestThreadResult, GitPullRequestRefInput, @@ -99,10 +98,6 @@ type StripProgressContext = T extends any ? Omit; type GitActionProgressEmitter = (event: GitActionProgressPayload) => Effect.Effect; -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; }