diff --git a/apps/server/src/git/GitManager.test.ts b/apps/server/src/git/GitManager.test.ts index bd6eb8e6e8..99a7bdb980 100644 --- a/apps/server/src/git/GitManager.test.ts +++ b/apps/server/src/git/GitManager.test.ts @@ -3056,6 +3056,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => { expect.objectContaining({ kind: "hook_finished", hookName: "pre-commit", + exitCode: 0, }), expect.objectContaining({ kind: "action_finished", diff --git a/apps/server/src/vcs/GitVcsDriverCore.ts b/apps/server/src/vcs/GitVcsDriverCore.ts index 40ae6a1dfb..c37dc799ec 100644 --- a/apps/server/src/vcs/GitVcsDriverCore.ts +++ b/apps/server/src/vcs/GitVcsDriverCore.ts @@ -448,7 +448,7 @@ const createTrace2Monitor = Effect.fn("createTrace2Monitor")(function* ( if (event === "child_exit") { hookStartByChildKey.delete(childKey); - const code = traceRecord.success.exitCode; + const code = traceRecord.success.code; const exitCode = typeof code === "number" && Number.isInteger(code) ? code : null; const now = yield* DateTime.now; const durationMs = started diff --git a/apps/server/src/vcs/JjVcsDriver.ts b/apps/server/src/vcs/JjVcsDriver.ts index 052ea36b5f..8c9810f380 100644 --- a/apps/server/src/vcs/JjVcsDriver.ts +++ b/apps/server/src/vcs/JjVcsDriver.ts @@ -1,10 +1,24 @@ -import { Effect, FileSystem, Layer } from "effect"; +import { Context, Effect, FileSystem, Layer } from "effect"; import { VcsOutputDecodeError, VcsProcessExitError } from "@t3tools/contracts"; import { VcsDriver, type VcsDriverShape } from "./VcsDriver.ts"; import { nowFreshness } from "./VcsFreshness.ts"; import { VcsProcess, type VcsProcessShape } from "./VcsProcess.ts"; +export interface JjVcsDriverShape extends VcsDriverShape { + readonly capabilities: VcsDriverShape["capabilities"] & { + readonly kind: "jj"; + readonly supportsBookmarks: true; + readonly supportsAtomicSnapshot: true; + readonly supportsWorktrees: false; + readonly ignoreClassifier: "git-compatible-fallback"; + }; +} + +export class JjVcsDriver extends Context.Service()( + "t3/vcs/JjVcsDriver", +) {} + const WORKSPACE_FILES_MAX_OUTPUT_BYTES = 16 * 1024 * 1024; const CHECK_IGNORE_MAX_STDIN_BYTES = 256 * 1024; @@ -137,10 +151,11 @@ export const makeVcsDriverShape = Effect.fn("makeJjVcsDriverShape")(function* () const fileSystem = yield* FileSystem.FileSystem; const capabilities = { kind: "jj" as const, - supportsWorktrees: true, - supportsBookmarks: true, - supportsAtomicSnapshot: true, - supportsPushDefaultRemote: false, + supportsWorktrees: false as const, + supportsBookmarks: true as const, + supportsAtomicSnapshot: true as const, + supportsPushDefaultRemote: false as const, + ignoreClassifier: "git-compatible-fallback" as const, }; const isInsideWorkTree: VcsDriverShape["isInsideWorkTree"] = (cwd) => @@ -308,12 +323,18 @@ export const makeVcsDriverShape = Effect.fn("makeJjVcsDriverShape")(function* () isInsideWorkTree, listWorkspaceFiles, filterIgnoredPaths, - } satisfies VcsDriverShape; + } satisfies JjVcsDriverShape; }); -export const makeVcsDriver = Effect.fn("makeJjVcsDriver")(function* () { +export const makeJjVcsDriver = Effect.fn("makeJjVcsDriver")(function* () { + const driver = yield* makeVcsDriverShape(); + return JjVcsDriver.of(driver); +}); + +export const makeVcsDriver = Effect.fn("makeJjGenericVcsDriver")(function* () { const driver = yield* makeVcsDriverShape(); return VcsDriver.of(driver); }); +export const layer = Layer.effect(JjVcsDriver, makeJjVcsDriver()); export const vcsLayer = Layer.effect(VcsDriver, makeVcsDriver()); diff --git a/apps/server/src/vcs/VcsDriverRegistry.test.ts b/apps/server/src/vcs/VcsDriverRegistry.test.ts index baf7bbd0c7..8ed36236e6 100644 --- a/apps/server/src/vcs/VcsDriverRegistry.test.ts +++ b/apps/server/src/vcs/VcsDriverRegistry.test.ts @@ -102,7 +102,7 @@ describe("VcsDriverRegistry", () => { }).pipe(Effect.provide(layer)); }); - it.effect("auto-detects jj after git misses", () => { + it.effect("prefers jj auto-detection before git for colocated repositories", () => { const calls: VcsProcessInput[] = []; const layer = Layer.effect(VcsDriverRegistry, makeVcsDriverRegistry()).pipe( Layer.provide( @@ -116,13 +116,13 @@ describe("VcsDriverRegistry", () => { Effect.sync(() => { calls.push(input); const command = input.args.join(" "); - if (input.command === "git" && command === "rev-parse --is-inside-work-tree") { - return processOutput("", 1, "not a git repository"); - } if (input.command === "jj" && command === "--no-pager root") { return processOutput("/repo\n"); } - return processOutput(""); + if (input.command === "git") { + return processOutput("true\n"); + } + return processOutput("", 1, "not found"); }), }), ), @@ -135,10 +135,7 @@ describe("VcsDriverRegistry", () => { assert.equal(handle.kind, "jj"); assert.equal(handle.repository.rootPath, "/repo"); - assert.deepStrictEqual(commandCalls(calls), [ - ["git", "rev-parse", "--is-inside-work-tree"], - ["jj", "--no-pager", "root"], - ]); + assert.deepStrictEqual(commandCalls(calls), [["jj", "--no-pager", "root"]]); }).pipe(Effect.provide(layer)); }); }); diff --git a/apps/server/src/vcs/VcsDriverRegistry.ts b/apps/server/src/vcs/VcsDriverRegistry.ts index f2b5ddd316..4b28b2ab05 100644 --- a/apps/server/src/vcs/VcsDriverRegistry.ts +++ b/apps/server/src/vcs/VcsDriverRegistry.ts @@ -106,12 +106,12 @@ export const make = Effect.fn("makeVcsDriverRegistry")(function* () { return yield* detectWithDriver(requestedKind, driver, input.cwd); } - const gitDetected = yield* detectWithDriver("git", git, input.cwd); - if (gitDetected) { - return gitDetected; + const jjDetected = yield* detectWithDriver("jj", jj, input.cwd); + if (jjDetected) { + return jjDetected; } - return yield* detectWithDriver("jj", jj, input.cwd); + return yield* detectWithDriver("git", git, input.cwd); }); const detectionCache = yield* Cache.makeWith(