Compare commits
10
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
87975b1c96 | ||
|
|
d75f5dfc60 | ||
|
|
9d44e5495e | ||
|
|
65d20e7edf | ||
|
|
f5b465cba2 | ||
|
|
8d0ef79c6f | ||
|
|
96bd5cedb4 | ||
|
|
87ad5b4810 | ||
|
|
3ab1bab388 | ||
|
|
e0acfc58ad |
No files matched your search
@@ -0,0 +1,49 @@
|
|||||||
|
name: Setup Jujutsu
|
||||||
|
description: Install the jj CLI from the official jj-vcs release artifacts.
|
||||||
|
|
||||||
|
inputs:
|
||||||
|
version:
|
||||||
|
description: Jujutsu release tag to install.
|
||||||
|
required: false
|
||||||
|
default: v0.40.0
|
||||||
|
|
||||||
|
runs:
|
||||||
|
using: composite
|
||||||
|
steps:
|
||||||
|
- name: Install jj
|
||||||
|
shell: bash
|
||||||
|
env:
|
||||||
|
JJ_VERSION: ${{ inputs.version }}
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
case "${RUNNER_OS}-${RUNNER_ARCH}" in
|
||||||
|
Linux-X64)
|
||||||
|
asset="jj-${JJ_VERSION}-x86_64-unknown-linux-musl.tar.gz"
|
||||||
|
;;
|
||||||
|
Linux-ARM64)
|
||||||
|
asset="jj-${JJ_VERSION}-aarch64-unknown-linux-musl.tar.gz"
|
||||||
|
;;
|
||||||
|
macOS-X64)
|
||||||
|
asset="jj-${JJ_VERSION}-x86_64-apple-darwin.tar.gz"
|
||||||
|
;;
|
||||||
|
macOS-ARM64)
|
||||||
|
asset="jj-${JJ_VERSION}-aarch64-apple-darwin.tar.gz"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "Unsupported runner for jj install: ${RUNNER_OS}-${RUNNER_ARCH}" >&2
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
install_dir="${RUNNER_TEMP}/jj-${JJ_VERSION}"
|
||||||
|
mkdir -p "$install_dir"
|
||||||
|
|
||||||
|
curl -fsSL \
|
||||||
|
"https://github.com/jj-vcs/jj/releases/download/${JJ_VERSION}/${asset}" \
|
||||||
|
-o "${RUNNER_TEMP}/${asset}"
|
||||||
|
tar -xzf "${RUNNER_TEMP}/${asset}" -C "$install_dir"
|
||||||
|
|
||||||
|
chmod +x "${install_dir}/jj"
|
||||||
|
echo "$install_dir" >> "$GITHUB_PATH"
|
||||||
|
"${install_dir}/jj" --version
|
||||||
@@ -25,6 +25,9 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
node-version-file: package.json
|
node-version-file: package.json
|
||||||
|
|
||||||
|
- name: Setup Jujutsu
|
||||||
|
uses: ./.github/actions/setup-jj
|
||||||
|
|
||||||
- name: Cache Bun and Turbo
|
- name: Cache Bun and Turbo
|
||||||
uses: actions/cache@v5
|
uses: actions/cache@v5
|
||||||
with:
|
with:
|
||||||
|
|||||||
@@ -95,6 +95,9 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
node-version-file: package.json
|
node-version-file: package.json
|
||||||
|
|
||||||
|
- name: Setup Jujutsu
|
||||||
|
uses: ./.github/actions/setup-jj
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: bun install --frozen-lockfile
|
run: bun install --frozen-lockfile
|
||||||
|
|
||||||
|
|||||||
@@ -331,6 +331,7 @@ export const makeOrchestrationIntegrationHarness = (
|
|||||||
refreshLocalStatus: () =>
|
refreshLocalStatus: () =>
|
||||||
Effect.succeed({
|
Effect.succeed({
|
||||||
isRepo: true,
|
isRepo: true,
|
||||||
|
kind: "git",
|
||||||
hasPrimaryRemote: false,
|
hasPrimaryRemote: false,
|
||||||
isDefaultRef: true,
|
isDefaultRef: true,
|
||||||
refName: "main",
|
refName: "main",
|
||||||
|
|||||||
@@ -868,6 +868,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
|
|||||||
|
|
||||||
expect(status).toEqual({
|
expect(status).toEqual({
|
||||||
isRepo: false,
|
isRepo: false,
|
||||||
|
kind: "unknown",
|
||||||
hasPrimaryRemote: false,
|
hasPrimaryRemote: false,
|
||||||
isDefaultRef: false,
|
isDefaultRef: false,
|
||||||
refName: null,
|
refName: null,
|
||||||
@@ -897,6 +898,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
|
|||||||
|
|
||||||
expect(status).toEqual({
|
expect(status).toEqual({
|
||||||
isRepo: false,
|
isRepo: false,
|
||||||
|
kind: "unknown",
|
||||||
hasPrimaryRemote: false,
|
hasPrimaryRemote: false,
|
||||||
isDefaultRef: false,
|
isDefaultRef: false,
|
||||||
refName: null,
|
refName: null,
|
||||||
@@ -3041,6 +3043,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
|
|||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
kind: "hook_finished",
|
kind: "hook_finished",
|
||||||
hookName: "pre-commit",
|
hookName: "pre-commit",
|
||||||
|
exitCode: 0,
|
||||||
}),
|
}),
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
kind: "action_finished",
|
kind: "action_finished",
|
||||||
|
|||||||
@@ -702,6 +702,7 @@ export const makeGitManager = Effect.fn("makeGitManager")(function* () {
|
|||||||
: null;
|
: null;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
kind: details.isRepo ? ("git" as const) : ("unknown" as const),
|
||||||
isRepo: details.isRepo,
|
isRepo: details.isRepo,
|
||||||
...(hostingProvider ? { sourceControlProvider: hostingProvider } : {}),
|
...(hostingProvider ? { sourceControlProvider: hostingProvider } : {}),
|
||||||
hasPrimaryRemote: details.hasOriginRemote,
|
hasPrimaryRemote: details.hasOriginRemote,
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ describe("GitWorkflowService", () => {
|
|||||||
const status = yield* workflow.localStatus({ cwd: "/not-a-repo" });
|
const status = yield* workflow.localStatus({ cwd: "/not-a-repo" });
|
||||||
|
|
||||||
assert.deepStrictEqual(status, {
|
assert.deepStrictEqual(status, {
|
||||||
|
kind: "unknown",
|
||||||
isRepo: false,
|
isRepo: false,
|
||||||
hasPrimaryRemote: false,
|
hasPrimaryRemote: false,
|
||||||
isDefaultRef: false,
|
isDefaultRef: false,
|
||||||
@@ -52,6 +53,7 @@ describe("GitWorkflowService", () => {
|
|||||||
const status = yield* workflow.status({ cwd: "/not-a-repo" });
|
const status = yield* workflow.status({ cwd: "/not-a-repo" });
|
||||||
|
|
||||||
assert.deepStrictEqual(status, {
|
assert.deepStrictEqual(status, {
|
||||||
|
kind: "unknown",
|
||||||
isRepo: false,
|
isRepo: false,
|
||||||
hasPrimaryRemote: false,
|
hasPrimaryRemote: false,
|
||||||
isDefaultRef: false,
|
isDefaultRef: false,
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { Context, Effect, Layer } from "effect";
|
|||||||
import {
|
import {
|
||||||
GitManagerError,
|
GitManagerError,
|
||||||
GitCommandError,
|
GitCommandError,
|
||||||
|
type VcsDriverKind,
|
||||||
type VcsSwitchRefInput,
|
type VcsSwitchRefInput,
|
||||||
type VcsSwitchRefResult,
|
type VcsSwitchRefResult,
|
||||||
type VcsCreateRefInput,
|
type VcsCreateRefInput,
|
||||||
@@ -29,6 +30,7 @@ import {
|
|||||||
import { GitManager, type GitRunStackedActionOptions } from "./GitManager.ts";
|
import { GitManager, type GitRunStackedActionOptions } from "./GitManager.ts";
|
||||||
import { GitVcsDriver } from "../vcs/GitVcsDriver.ts";
|
import { GitVcsDriver } from "../vcs/GitVcsDriver.ts";
|
||||||
import { VcsDriverRegistry } from "../vcs/VcsDriverRegistry.ts";
|
import { VcsDriverRegistry } from "../vcs/VcsDriverRegistry.ts";
|
||||||
|
import { mergeGitStatusParts } from "@t3tools/shared/git";
|
||||||
|
|
||||||
export interface GitWorkflowServiceShape {
|
export interface GitWorkflowServiceShape {
|
||||||
readonly status: (
|
readonly status: (
|
||||||
@@ -91,30 +93,7 @@ const unsupportedGitCommand = (operation: string, cwd: string, detail: string) =
|
|||||||
detail,
|
detail,
|
||||||
});
|
});
|
||||||
|
|
||||||
function nonRepositoryLocalStatus(): VcsStatusLocalResult {
|
const emptyWorkingTree = { files: [], insertions: 0, deletions: 0 } as const;
|
||||||
return {
|
|
||||||
isRepo: false,
|
|
||||||
hasPrimaryRemote: false,
|
|
||||||
isDefaultRef: false,
|
|
||||||
refName: null,
|
|
||||||
hasWorkingTreeChanges: false,
|
|
||||||
workingTree: {
|
|
||||||
files: [],
|
|
||||||
insertions: 0,
|
|
||||||
deletions: 0,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
function nonRepositoryStatus(): VcsStatusResult {
|
|
||||||
return {
|
|
||||||
...nonRepositoryLocalStatus(),
|
|
||||||
hasUpstream: false,
|
|
||||||
aheadCount: 0,
|
|
||||||
behindCount: 0,
|
|
||||||
pr: null,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
function nonRepositoryListRefs(): VcsListRefsResult {
|
function nonRepositoryListRefs(): VcsListRefsResult {
|
||||||
return {
|
return {
|
||||||
@@ -126,6 +105,16 @@ function nonRepositoryListRefs(): VcsListRefsResult {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const nonGitLocalStatus = (kind: VcsDriverKind, isRepo: boolean): VcsStatusLocalResult => ({
|
||||||
|
kind,
|
||||||
|
isRepo,
|
||||||
|
hasPrimaryRemote: false,
|
||||||
|
isDefaultRef: false,
|
||||||
|
refName: null,
|
||||||
|
hasWorkingTreeChanges: false,
|
||||||
|
workingTree: emptyWorkingTree,
|
||||||
|
});
|
||||||
|
|
||||||
export const make = Effect.fn("makeGitWorkflowService")(function* () {
|
export const make = Effect.fn("makeGitWorkflowService")(function* () {
|
||||||
const registry = yield* VcsDriverRegistry;
|
const registry = yield* VcsDriverRegistry;
|
||||||
const git = yield* GitVcsDriver;
|
const git = yield* GitVcsDriver;
|
||||||
@@ -179,33 +168,6 @@ export const make = Effect.fn("makeGitWorkflowService")(function* () {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const detectGitRepositoryForStatus = Effect.fn("GitWorkflowService.detectGitRepositoryForStatus")(
|
|
||||||
function* (operation: string, cwd: string) {
|
|
||||||
const handle = yield* registry
|
|
||||||
.detect({ cwd })
|
|
||||||
.pipe(
|
|
||||||
Effect.mapError((error) =>
|
|
||||||
unsupportedGitWorkflow(
|
|
||||||
operation,
|
|
||||||
cwd,
|
|
||||||
error instanceof Error ? error.message : String(error),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
if (!handle) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (handle.kind !== "git") {
|
|
||||||
return yield* unsupportedGitWorkflow(
|
|
||||||
operation,
|
|
||||||
cwd,
|
|
||||||
`The ${operation} workflow currently supports Git repositories only; detected ${handle.kind}.`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
const detectGitRepositoryForCommand = Effect.fn(
|
const detectGitRepositoryForCommand = Effect.fn(
|
||||||
"GitWorkflowService.detectGitRepositoryForCommand",
|
"GitWorkflowService.detectGitRepositoryForCommand",
|
||||||
)(function* (operation: string, cwd: string) {
|
)(function* (operation: string, cwd: string) {
|
||||||
@@ -241,27 +203,60 @@ export const make = Effect.fn("makeGitWorkflowService")(function* () {
|
|||||||
(input: Input) =>
|
(input: Input) =>
|
||||||
ensureGit(operation, input.cwd).pipe(Effect.andThen(run(input)));
|
ensureGit(operation, input.cwd).pipe(Effect.andThen(run(input)));
|
||||||
|
|
||||||
|
const localStatus: GitWorkflowServiceShape["localStatus"] = Effect.fn(
|
||||||
|
"GitWorkflowService.localStatus",
|
||||||
|
)(function* (input) {
|
||||||
|
const handle = yield* registry
|
||||||
|
.detect({ cwd: input.cwd })
|
||||||
|
.pipe(
|
||||||
|
Effect.mapError((error) =>
|
||||||
|
unsupportedGitWorkflow(
|
||||||
|
"GitWorkflowService.localStatus",
|
||||||
|
input.cwd,
|
||||||
|
error instanceof Error ? error.message : String(error),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
if (!handle) {
|
||||||
|
return nonGitLocalStatus("unknown", false);
|
||||||
|
}
|
||||||
|
if (handle.kind === "git") {
|
||||||
|
return yield* gitManager.localStatus(input);
|
||||||
|
}
|
||||||
|
return nonGitLocalStatus(handle.kind, true);
|
||||||
|
});
|
||||||
|
|
||||||
|
const remoteStatus: GitWorkflowServiceShape["remoteStatus"] = Effect.fn(
|
||||||
|
"GitWorkflowService.remoteStatus",
|
||||||
|
)(function* (input) {
|
||||||
|
const handle = yield* registry
|
||||||
|
.detect({ cwd: input.cwd })
|
||||||
|
.pipe(
|
||||||
|
Effect.mapError((error) =>
|
||||||
|
unsupportedGitWorkflow(
|
||||||
|
"GitWorkflowService.remoteStatus",
|
||||||
|
input.cwd,
|
||||||
|
error instanceof Error ? error.message : String(error),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
if (handle?.kind === "git") {
|
||||||
|
return yield* gitManager.remoteStatus(input);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
|
||||||
|
const status: GitWorkflowServiceShape["status"] = Effect.fn("GitWorkflowService.status")(
|
||||||
|
function* (input) {
|
||||||
|
const [local, remote] = yield* Effect.all([localStatus(input), remoteStatus(input)]);
|
||||||
|
return mergeGitStatusParts(local, remote);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
return GitWorkflowService.of({
|
return GitWorkflowService.of({
|
||||||
status: (input) =>
|
status,
|
||||||
detectGitRepositoryForStatus("GitWorkflowService.status", input.cwd).pipe(
|
localStatus,
|
||||||
Effect.flatMap((isGitRepository) =>
|
remoteStatus,
|
||||||
isGitRepository ? gitManager.status(input) : Effect.succeed(nonRepositoryStatus()),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
localStatus: (input) =>
|
|
||||||
detectGitRepositoryForStatus("GitWorkflowService.localStatus", input.cwd).pipe(
|
|
||||||
Effect.flatMap((isGitRepository) =>
|
|
||||||
isGitRepository
|
|
||||||
? gitManager.localStatus(input)
|
|
||||||
: Effect.succeed(nonRepositoryLocalStatus()),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
remoteStatus: (input) =>
|
|
||||||
detectGitRepositoryForStatus("GitWorkflowService.remoteStatus", input.cwd).pipe(
|
|
||||||
Effect.flatMap((isGitRepository) =>
|
|
||||||
isGitRepository ? gitManager.remoteStatus(input) : Effect.succeed(null),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
invalidateLocalStatus: gitManager.invalidateLocalStatus,
|
invalidateLocalStatus: gitManager.invalidateLocalStatus,
|
||||||
invalidateRemoteStatus: gitManager.invalidateRemoteStatus,
|
invalidateRemoteStatus: gitManager.invalidateRemoteStatus,
|
||||||
invalidateStatus: gitManager.invalidateStatus,
|
invalidateStatus: gitManager.invalidateStatus,
|
||||||
|
|||||||
@@ -291,6 +291,7 @@ describe("CheckpointReactor", () => {
|
|||||||
}).pipe(
|
}).pipe(
|
||||||
Effect.as({
|
Effect.as({
|
||||||
isRepo: true,
|
isRepo: true,
|
||||||
|
kind: "git",
|
||||||
hasPrimaryRemote: false,
|
hasPrimaryRemote: false,
|
||||||
isDefaultRef: true,
|
isDefaultRef: true,
|
||||||
refName: "main",
|
refName: "main",
|
||||||
|
|||||||
@@ -240,6 +240,7 @@ describe("ProviderCommandReactor", () => {
|
|||||||
const refreshStatus = vi.fn((_: string) =>
|
const refreshStatus = vi.fn((_: string) =>
|
||||||
Effect.succeed({
|
Effect.succeed({
|
||||||
isRepo: true,
|
isRepo: true,
|
||||||
|
kind: "git" as const,
|
||||||
hasPrimaryRemote: true,
|
hasPrimaryRemote: true,
|
||||||
isDefaultRef: false,
|
isDefaultRef: false,
|
||||||
refName: "renamed-branch",
|
refName: "renamed-branch",
|
||||||
|
|||||||
@@ -54,6 +54,17 @@ import { vi } from "vitest";
|
|||||||
|
|
||||||
const TEST_EPOCH = DateTime.makeUnsafe("1970-01-01T00:00:00.000Z");
|
const TEST_EPOCH = DateTime.makeUnsafe("1970-01-01T00:00:00.000Z");
|
||||||
|
|
||||||
|
const testGitRepository = (rootPath: string) => ({
|
||||||
|
kind: "git" as const,
|
||||||
|
rootPath,
|
||||||
|
metadataPath: null,
|
||||||
|
freshness: {
|
||||||
|
source: "live-local" as const,
|
||||||
|
observedAt: TEST_EPOCH,
|
||||||
|
expiresAt: Option.none(),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
import type { ServerConfigShape } from "./config.ts";
|
import type { ServerConfigShape } from "./config.ts";
|
||||||
import { deriveServerPaths, ServerConfig } from "./config.ts";
|
import { deriveServerPaths, ServerConfig } from "./config.ts";
|
||||||
import { makeRoutesLayer } from "./server.ts";
|
import { makeRoutesLayer } from "./server.ts";
|
||||||
@@ -2373,6 +2384,10 @@ it.layer(NodeServices.layer)("server router seam", (it) => {
|
|||||||
Effect.gen(function* () {
|
Effect.gen(function* () {
|
||||||
yield* buildAppUnderTest({
|
yield* buildAppUnderTest({
|
||||||
layers: {
|
layers: {
|
||||||
|
vcsDriver: {
|
||||||
|
detectRepository: () => Effect.succeed(testGitRepository("/tmp/repo")),
|
||||||
|
isInsideWorkTree: () => Effect.succeed(true),
|
||||||
|
},
|
||||||
gitManager: {
|
gitManager: {
|
||||||
invalidateLocalStatus: () => Effect.void,
|
invalidateLocalStatus: () => Effect.void,
|
||||||
invalidateRemoteStatus: () => Effect.void,
|
invalidateRemoteStatus: () => Effect.void,
|
||||||
@@ -2380,6 +2395,7 @@ it.layer(NodeServices.layer)("server router seam", (it) => {
|
|||||||
localStatus: () =>
|
localStatus: () =>
|
||||||
Effect.succeed({
|
Effect.succeed({
|
||||||
isRepo: true,
|
isRepo: true,
|
||||||
|
kind: "git",
|
||||||
hasPrimaryRemote: true,
|
hasPrimaryRemote: true,
|
||||||
isDefaultRef: true,
|
isDefaultRef: true,
|
||||||
refName: "main",
|
refName: "main",
|
||||||
@@ -2396,6 +2412,7 @@ it.layer(NodeServices.layer)("server router seam", (it) => {
|
|||||||
status: () =>
|
status: () =>
|
||||||
Effect.succeed({
|
Effect.succeed({
|
||||||
isRepo: true,
|
isRepo: true,
|
||||||
|
kind: "git",
|
||||||
hasPrimaryRemote: true,
|
hasPrimaryRemote: true,
|
||||||
isDefaultRef: true,
|
isDefaultRef: true,
|
||||||
refName: "main",
|
refName: "main",
|
||||||
@@ -2509,9 +2526,6 @@ it.layer(NodeServices.layer)("server router seam", (it) => {
|
|||||||
createRef: (input) => Effect.succeed({ refName: input.refName }),
|
createRef: (input) => Effect.succeed({ refName: input.refName }),
|
||||||
switchRef: (input) => Effect.succeed({ refName: input.refName }),
|
switchRef: (input) => Effect.succeed({ refName: input.refName }),
|
||||||
},
|
},
|
||||||
vcsDriver: {
|
|
||||||
isInsideWorkTree: () => Effect.succeed(true),
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -2652,6 +2666,7 @@ it.layer(NodeServices.layer)("server router seam", (it) => {
|
|||||||
localStatus: () =>
|
localStatus: () =>
|
||||||
Effect.succeed({
|
Effect.succeed({
|
||||||
isRepo: true,
|
isRepo: true,
|
||||||
|
kind: "git",
|
||||||
hasPrimaryRemote: true,
|
hasPrimaryRemote: true,
|
||||||
isDefaultRef: true,
|
isDefaultRef: true,
|
||||||
refName: "main",
|
refName: "main",
|
||||||
@@ -2673,6 +2688,7 @@ it.layer(NodeServices.layer)("server router seam", (it) => {
|
|||||||
statusCalls += 1;
|
statusCalls += 1;
|
||||||
return {
|
return {
|
||||||
isRepo: true,
|
isRepo: true,
|
||||||
|
kind: "git",
|
||||||
hasPrimaryRemote: true,
|
hasPrimaryRemote: true,
|
||||||
isDefaultRef: true,
|
isDefaultRef: true,
|
||||||
refName: "main",
|
refName: "main",
|
||||||
@@ -2729,6 +2745,7 @@ it.layer(NodeServices.layer)("server router seam", (it) => {
|
|||||||
localStatus: () =>
|
localStatus: () =>
|
||||||
Effect.succeed({
|
Effect.succeed({
|
||||||
isRepo: true,
|
isRepo: true,
|
||||||
|
kind: "git",
|
||||||
hasPrimaryRemote: true,
|
hasPrimaryRemote: true,
|
||||||
isDefaultRef: false,
|
isDefaultRef: false,
|
||||||
refName: "feature/demo",
|
refName: "feature/demo",
|
||||||
@@ -2750,6 +2767,7 @@ it.layer(NodeServices.layer)("server router seam", (it) => {
|
|||||||
statusCalls += 1;
|
statusCalls += 1;
|
||||||
return {
|
return {
|
||||||
isRepo: true,
|
isRepo: true,
|
||||||
|
kind: "git",
|
||||||
hasPrimaryRemote: true,
|
hasPrimaryRemote: true,
|
||||||
isDefaultRef: false,
|
isDefaultRef: false,
|
||||||
refName: "feature/demo",
|
refName: "feature/demo",
|
||||||
@@ -2787,6 +2805,9 @@ it.layer(NodeServices.layer)("server router seam", (it) => {
|
|||||||
Effect.gen(function* () {
|
Effect.gen(function* () {
|
||||||
yield* buildAppUnderTest({
|
yield* buildAppUnderTest({
|
||||||
layers: {
|
layers: {
|
||||||
|
vcsDriver: {
|
||||||
|
detectRepository: () => Effect.succeed(testGitRepository("/tmp/repo")),
|
||||||
|
},
|
||||||
gitVcsDriver: {
|
gitVcsDriver: {
|
||||||
pullCurrentBranch: () =>
|
pullCurrentBranch: () =>
|
||||||
Effect.succeed({
|
Effect.succeed({
|
||||||
@@ -2801,6 +2822,7 @@ it.layer(NodeServices.layer)("server router seam", (it) => {
|
|||||||
localStatus: () =>
|
localStatus: () =>
|
||||||
Effect.succeed({
|
Effect.succeed({
|
||||||
isRepo: true,
|
isRepo: true,
|
||||||
|
kind: "git",
|
||||||
hasPrimaryRemote: true,
|
hasPrimaryRemote: true,
|
||||||
isDefaultRef: true,
|
isDefaultRef: true,
|
||||||
refName: "main",
|
refName: "main",
|
||||||
@@ -2840,6 +2862,7 @@ it.layer(NodeServices.layer)("server router seam", (it) => {
|
|||||||
layers: {
|
layers: {
|
||||||
vcsDriver: {
|
vcsDriver: {
|
||||||
isInsideWorkTree: () => Effect.succeed(true),
|
isInsideWorkTree: () => Effect.succeed(true),
|
||||||
|
detectRepository: () => Effect.succeed(testGitRepository("/tmp/repo")),
|
||||||
},
|
},
|
||||||
gitManager: {
|
gitManager: {
|
||||||
invalidateLocalStatus: () => Effect.void,
|
invalidateLocalStatus: () => Effect.void,
|
||||||
@@ -2847,6 +2870,7 @@ it.layer(NodeServices.layer)("server router seam", (it) => {
|
|||||||
localStatus: () =>
|
localStatus: () =>
|
||||||
Effect.succeed({
|
Effect.succeed({
|
||||||
isRepo: true,
|
isRepo: true,
|
||||||
|
kind: "git",
|
||||||
hasPrimaryRemote: true,
|
hasPrimaryRemote: true,
|
||||||
isDefaultRef: false,
|
isDefaultRef: false,
|
||||||
refName: "feature/demo",
|
refName: "feature/demo",
|
||||||
@@ -2916,6 +2940,7 @@ it.layer(NodeServices.layer)("server router seam", (it) => {
|
|||||||
layers: {
|
layers: {
|
||||||
vcsDriver: {
|
vcsDriver: {
|
||||||
isInsideWorkTree: () => Effect.succeed(true),
|
isInsideWorkTree: () => Effect.succeed(true),
|
||||||
|
detectRepository: () => Effect.succeed(testGitRepository("/tmp/repo")),
|
||||||
},
|
},
|
||||||
gitManager: {
|
gitManager: {
|
||||||
invalidateLocalStatus: () => Effect.void,
|
invalidateLocalStatus: () => Effect.void,
|
||||||
@@ -2926,6 +2951,7 @@ it.layer(NodeServices.layer)("server router seam", (it) => {
|
|||||||
Effect.andThen(
|
Effect.andThen(
|
||||||
Effect.succeed({
|
Effect.succeed({
|
||||||
isRepo: true,
|
isRepo: true,
|
||||||
|
kind: "git" as const,
|
||||||
hasPrimaryRemote: true,
|
hasPrimaryRemote: true,
|
||||||
isDefaultRef: false,
|
isDefaultRef: false,
|
||||||
refName: "feature/demo",
|
refName: "feature/demo",
|
||||||
@@ -3592,6 +3618,7 @@ it.layer(NodeServices.layer)("server router seam", (it) => {
|
|||||||
const refreshStatus = vi.fn((_: string) =>
|
const refreshStatus = vi.fn((_: string) =>
|
||||||
Effect.succeed({
|
Effect.succeed({
|
||||||
isRepo: true,
|
isRepo: true,
|
||||||
|
kind: "git" as const,
|
||||||
hasPrimaryRemote: true,
|
hasPrimaryRemote: true,
|
||||||
isDefaultRef: false,
|
isDefaultRef: false,
|
||||||
refName: "t3code/bootstrap-refName",
|
refName: "t3code/bootstrap-refName",
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ Logged in to github.com account juliusmarminge (keyring)
|
|||||||
})),
|
})),
|
||||||
[
|
[
|
||||||
{ kind: "git", implemented: true, status: "available" },
|
{ kind: "git", implemented: true, status: "available" },
|
||||||
{ kind: "jj", implemented: false, status: "missing" },
|
{ kind: "jj", implemented: true, status: "missing" },
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
assert.deepStrictEqual(
|
assert.deepStrictEqual(
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ const VCS_PROBES: ReadonlyArray<VcsProbe> = [
|
|||||||
label: "Jujutsu",
|
label: "Jujutsu",
|
||||||
executable: "jj",
|
executable: "jj",
|
||||||
versionArgs: ["--version"],
|
versionArgs: ["--version"],
|
||||||
implemented: false,
|
implemented: true,
|
||||||
installHint: "Install Jujutsu with `brew install jj` or from https://github.com/jj-vcs/jj.",
|
installHint: "Install Jujutsu with `brew install jj` or from https://github.com/jj-vcs/jj.",
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { Context, DateTime, Effect, Layer, Option } from "effect";
|
import { Context, Effect, Layer, Option } from "effect";
|
||||||
import { ChildProcessSpawner } from "effect/unstable/process";
|
import { ChildProcessSpawner } from "effect/unstable/process";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@@ -20,6 +20,7 @@ import {
|
|||||||
} from "@t3tools/contracts";
|
} from "@t3tools/contracts";
|
||||||
import { makeGitVcsDriverCore } from "./GitVcsDriverCore.ts";
|
import { makeGitVcsDriverCore } from "./GitVcsDriverCore.ts";
|
||||||
import { VcsDriver, type VcsDriverShape } from "./VcsDriver.ts";
|
import { VcsDriver, type VcsDriverShape } from "./VcsDriver.ts";
|
||||||
|
import { nowFreshness } from "./VcsFreshness.ts";
|
||||||
import { VcsProcess, type VcsProcessShape } from "./VcsProcess.ts";
|
import { VcsProcess, type VcsProcessShape } from "./VcsProcess.ts";
|
||||||
|
|
||||||
export interface ExecuteGitInput {
|
export interface ExecuteGitInput {
|
||||||
@@ -209,15 +210,6 @@ const WORKSPACE_GIT_HARDENED_CONFIG_ARGS = [
|
|||||||
"core.untrackedCache=false",
|
"core.untrackedCache=false",
|
||||||
] as const;
|
] as const;
|
||||||
|
|
||||||
const nowFreshness = Effect.fn("GitVcsDriver.nowFreshness")(function* () {
|
|
||||||
const now = yield* DateTime.now;
|
|
||||||
return {
|
|
||||||
source: "live-local" as const,
|
|
||||||
observedAt: now,
|
|
||||||
expiresAt: Option.none(),
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
function splitNullSeparatedPaths(input: string, truncated: boolean): string[] {
|
function splitNullSeparatedPaths(input: string, truncated: boolean): string[] {
|
||||||
const parts = input.split("\0");
|
const parts = input.split("\0");
|
||||||
if (parts.length === 0) return [];
|
if (parts.length === 0) return [];
|
||||||
|
|||||||
@@ -448,7 +448,7 @@ const createTrace2Monitor = Effect.fn("createTrace2Monitor")(function* (
|
|||||||
|
|
||||||
if (event === "child_exit") {
|
if (event === "child_exit") {
|
||||||
hookStartByChildKey.delete(childKey);
|
hookStartByChildKey.delete(childKey);
|
||||||
const code = traceRecord.success.exitCode;
|
const code = traceRecord.success.code;
|
||||||
const exitCode = typeof code === "number" && Number.isInteger(code) ? code : null;
|
const exitCode = typeof code === "number" && Number.isInteger(code) ? code : null;
|
||||||
const now = yield* DateTime.now;
|
const now = yield* DateTime.now;
|
||||||
const durationMs = started
|
const durationMs = started
|
||||||
@@ -1314,6 +1314,7 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
|
|||||||
const status: GitVcsDriverShape["status"] = (input) =>
|
const status: GitVcsDriverShape["status"] = (input) =>
|
||||||
statusDetails(input.cwd).pipe(
|
statusDetails(input.cwd).pipe(
|
||||||
Effect.map((details) => ({
|
Effect.map((details) => ({
|
||||||
|
kind: "git" as const,
|
||||||
isRepo: details.isRepo,
|
isRepo: details.isRepo,
|
||||||
hasPrimaryRemote: details.hasOriginRemote,
|
hasPrimaryRemote: details.hasOriginRemote,
|
||||||
isDefaultRef: details.isDefaultBranch,
|
isDefaultRef: details.isDefaultBranch,
|
||||||
|
|||||||
@@ -0,0 +1,193 @@
|
|||||||
|
import * as NodeServices from "@effect/platform-node/NodeServices";
|
||||||
|
import { assert, it } from "@effect/vitest";
|
||||||
|
import { Effect, FileSystem, Layer, Path, PlatformError } from "effect";
|
||||||
|
import { ChildProcessSpawner } from "effect/unstable/process";
|
||||||
|
import { describe } from "vitest";
|
||||||
|
|
||||||
|
import type { VcsError } from "@t3tools/contracts";
|
||||||
|
import type { VcsProcessInput, VcsProcessOutput } from "./VcsProcess.ts";
|
||||||
|
import { VcsProcess, layer as VcsProcessLayer } from "./VcsProcess.ts";
|
||||||
|
import * as JjVcsDriver from "./JjVcsDriver.ts";
|
||||||
|
import { runVcsDriverContractSuite } from "./testing/VcsDriverContractHarness.ts";
|
||||||
|
|
||||||
|
const JjContractLayer = JjVcsDriver.vcsLayer.pipe(
|
||||||
|
Layer.provideMerge(VcsProcessLayer),
|
||||||
|
Layer.provideMerge(NodeServices.layer),
|
||||||
|
);
|
||||||
|
|
||||||
|
const commandCalls = (calls: ReadonlyArray<VcsProcessInput>) =>
|
||||||
|
calls.map((call) => [call.command].concat(call.args));
|
||||||
|
|
||||||
|
const processOutput = (stdout: string, exitCode = 0, stderr = ""): VcsProcessOutput => ({
|
||||||
|
exitCode: ChildProcessSpawner.ExitCode(exitCode),
|
||||||
|
stdout,
|
||||||
|
stderr,
|
||||||
|
stdoutTruncated: false,
|
||||||
|
stderrTruncated: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
const runJj = (cwd: string, args: ReadonlyArray<string>) =>
|
||||||
|
Effect.gen(function* () {
|
||||||
|
const process = yield* VcsProcess;
|
||||||
|
yield* process.run({
|
||||||
|
operation: "JjVcsDriver.contract.jj",
|
||||||
|
command: "jj",
|
||||||
|
cwd,
|
||||||
|
args,
|
||||||
|
timeoutMs: 10_000,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
type JjContractError = PlatformError.PlatformError | VcsError;
|
||||||
|
|
||||||
|
runVcsDriverContractSuite<VcsProcess, JjContractError>({
|
||||||
|
name: "JJ",
|
||||||
|
kind: "jj",
|
||||||
|
layer: JjContractLayer,
|
||||||
|
fixture: {
|
||||||
|
createRepo: (cwd) => runJj(cwd, ["git", "init", "--colocate"]),
|
||||||
|
writeFile: (cwd, relativePath, contents) =>
|
||||||
|
Effect.gen(function* () {
|
||||||
|
const fileSystem = yield* FileSystem.FileSystem;
|
||||||
|
const path = yield* Path.Path;
|
||||||
|
const absolutePath = path.join(cwd, relativePath);
|
||||||
|
yield* fileSystem.makeDirectory(path.dirname(absolutePath), { recursive: true });
|
||||||
|
yield* fileSystem.writeFileString(absolutePath, contents);
|
||||||
|
}),
|
||||||
|
ignorePath: (cwd, pattern) =>
|
||||||
|
Effect.gen(function* () {
|
||||||
|
const fileSystem = yield* FileSystem.FileSystem;
|
||||||
|
const path = yield* Path.Path;
|
||||||
|
yield* fileSystem.writeFileString(path.join(cwd, ".gitignore"), `${pattern}\n`);
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("JjVcsDriver", () => {
|
||||||
|
it.effect("detects repository identity with jj root", () => {
|
||||||
|
const calls: VcsProcessInput[] = [];
|
||||||
|
|
||||||
|
return Effect.gen(function* () {
|
||||||
|
const driver = yield* JjVcsDriver.makeVcsDriverShape();
|
||||||
|
const identity = yield* driver.detectRepository("/repo/src");
|
||||||
|
|
||||||
|
assert.equal(identity?.kind, "jj");
|
||||||
|
assert.equal(identity?.rootPath, "/repo");
|
||||||
|
assert.equal(identity?.metadataPath, "/repo/.jj");
|
||||||
|
assert.deepStrictEqual(commandCalls(calls), [["jj", "--no-pager", "root"]]);
|
||||||
|
}).pipe(
|
||||||
|
Effect.provide(
|
||||||
|
Layer.mergeAll(
|
||||||
|
Layer.mock(VcsProcess)({
|
||||||
|
run: (input) =>
|
||||||
|
Effect.sync(() => {
|
||||||
|
calls.push(input);
|
||||||
|
return processOutput("/repo\n");
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
NodeServices.layer,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it.effect("lists workspace files using jj file list", () => {
|
||||||
|
let observedInput: VcsProcessInput | null = null;
|
||||||
|
|
||||||
|
return Effect.gen(function* () {
|
||||||
|
const driver = yield* JjVcsDriver.makeVcsDriverShape();
|
||||||
|
const result = yield* driver.listWorkspaceFiles("/repo");
|
||||||
|
|
||||||
|
assert.deepStrictEqual(result.paths, ["README.md", "src/index.ts"]);
|
||||||
|
assert.deepStrictEqual(observedInput?.args, ["--no-pager", "file", "list"]);
|
||||||
|
}).pipe(
|
||||||
|
Effect.provide(
|
||||||
|
Layer.mergeAll(
|
||||||
|
Layer.mock(VcsProcess)({
|
||||||
|
run: (input) =>
|
||||||
|
Effect.sync(() => {
|
||||||
|
observedInput = input;
|
||||||
|
return processOutput("README.md\nsrc/index.ts\n");
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
NodeServices.layer,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it.effect("filters paths with the git ignore oracle", () => {
|
||||||
|
const calls: VcsProcessInput[] = [];
|
||||||
|
|
||||||
|
return Effect.gen(function* () {
|
||||||
|
const driver = yield* JjVcsDriver.makeVcsDriverShape();
|
||||||
|
const result = yield* driver.filterIgnoredPaths("/repo", [
|
||||||
|
"keep.ts",
|
||||||
|
"debug.log",
|
||||||
|
"src/index.ts",
|
||||||
|
]);
|
||||||
|
|
||||||
|
assert.deepStrictEqual(result, ["keep.ts", "src/index.ts"]);
|
||||||
|
assert.equal(calls[0]?.command, "git");
|
||||||
|
assert.deepStrictEqual(calls[0]?.args.slice(-2), ["init", "--bare"]);
|
||||||
|
assert.equal(calls[1]?.command, "git");
|
||||||
|
assert.deepStrictEqual(calls[1]?.args.slice(-4), [
|
||||||
|
"check-ignore",
|
||||||
|
"--no-index",
|
||||||
|
"-z",
|
||||||
|
"--stdin",
|
||||||
|
]);
|
||||||
|
assert.equal(calls[1]?.stdin, "keep.ts\0debug.log\0src/index.ts\0");
|
||||||
|
}).pipe(
|
||||||
|
Effect.provide(
|
||||||
|
Layer.mergeAll(
|
||||||
|
Layer.mock(VcsProcess)({
|
||||||
|
run: (input) =>
|
||||||
|
Effect.sync(() => {
|
||||||
|
calls.push(input);
|
||||||
|
if (input.command === "git" && input.args.includes("check-ignore")) {
|
||||||
|
return processOutput("debug.log\0");
|
||||||
|
}
|
||||||
|
return processOutput("");
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
NodeServices.layer,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it.effect("forwards execute env to the VCS process", () => {
|
||||||
|
let observedEnv: NodeJS.ProcessEnv | undefined;
|
||||||
|
|
||||||
|
return Effect.gen(function* () {
|
||||||
|
const driver = yield* JjVcsDriver.makeVcsDriverShape();
|
||||||
|
|
||||||
|
yield* driver.execute({
|
||||||
|
operation: "JjVcsDriver.test.env",
|
||||||
|
cwd: "/repo",
|
||||||
|
args: ["status"],
|
||||||
|
env: {
|
||||||
|
JJ_CONFIG: "/tmp/t3-jj-config.toml",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.deepStrictEqual(observedEnv, {
|
||||||
|
JJ_CONFIG: "/tmp/t3-jj-config.toml",
|
||||||
|
});
|
||||||
|
}).pipe(
|
||||||
|
Effect.provide(
|
||||||
|
Layer.mergeAll(
|
||||||
|
Layer.mock(VcsProcess)({
|
||||||
|
run: (input) =>
|
||||||
|
Effect.sync(() => {
|
||||||
|
observedEnv = input.env;
|
||||||
|
return processOutput("");
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
NodeServices.layer,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,517 @@
|
|||||||
|
import { Context, Effect, FileSystem, Layer, Option } from "effect";
|
||||||
|
|
||||||
|
import { VcsOutputDecodeError, VcsProcessExitError, type VcsError } 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";
|
||||||
|
};
|
||||||
|
readonly currentChange: (cwd: string) => Effect.Effect<JjCurrentChange | null, VcsError>;
|
||||||
|
readonly listBookmarks: (cwd: string) => Effect.Effect<ReadonlyArray<JjBookmark>, VcsError>;
|
||||||
|
readonly listWorkspaces: (cwd: string) => Effect.Effect<ReadonlyArray<JjWorkspace>, VcsError>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface JjCurrentChange {
|
||||||
|
readonly changeId: string;
|
||||||
|
readonly commitId: string | null;
|
||||||
|
readonly description: string | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface JjBookmark {
|
||||||
|
readonly name: string;
|
||||||
|
readonly target: string | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface JjWorkspace {
|
||||||
|
readonly name: string;
|
||||||
|
readonly path: string | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class JjVcsDriver extends Context.Service<JjVcsDriver, JjVcsDriverShape>()(
|
||||||
|
"t3/vcs/JjVcsDriver",
|
||||||
|
) {}
|
||||||
|
|
||||||
|
const WORKSPACE_FILES_MAX_OUTPUT_BYTES = 16 * 1024 * 1024;
|
||||||
|
const CHECK_IGNORE_MAX_STDIN_BYTES = 256 * 1024;
|
||||||
|
|
||||||
|
function splitNullSeparatedPaths(input: string, truncated: boolean): string[] {
|
||||||
|
const parts = input.split("\0");
|
||||||
|
if (parts.length === 0) return [];
|
||||||
|
|
||||||
|
if (truncated && parts[parts.length - 1]?.length) {
|
||||||
|
parts.pop();
|
||||||
|
}
|
||||||
|
|
||||||
|
return parts.filter((value) => value.length > 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
function splitLineSeparatedPaths(input: string, truncated: boolean): string[] {
|
||||||
|
const lines = input.split(/\r?\n/g);
|
||||||
|
if (truncated && lines[lines.length - 1]?.length) {
|
||||||
|
lines.pop();
|
||||||
|
}
|
||||||
|
|
||||||
|
return lines.map((line) => line.trim()).filter((line) => line.length > 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseJjRemoteList(output: string): Array<{ name: string; url: string }> {
|
||||||
|
return output
|
||||||
|
.split(/\r?\n/g)
|
||||||
|
.map((line) => line.trim())
|
||||||
|
.flatMap((line) => {
|
||||||
|
if (line.length === 0) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
const [name, ...urlParts] = line.split(/\s+/g);
|
||||||
|
const url = urlParts.join(" ").trim();
|
||||||
|
return name && url ? [{ name, url }] : [];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseNullRecord(record: string): string[] {
|
||||||
|
return record.split("\0").map((value) => value.trim());
|
||||||
|
}
|
||||||
|
|
||||||
|
function decodeJjCurrentChange(raw: string, cwd: string): JjCurrentChange | null {
|
||||||
|
const trimmed = raw.trim();
|
||||||
|
if (trimmed.length === 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const [changeId, commitId, description] = parseNullRecord(trimmed);
|
||||||
|
if (!changeId) {
|
||||||
|
throw new VcsOutputDecodeError({
|
||||||
|
operation: "JjVcsDriver.currentChange",
|
||||||
|
command: "jj log",
|
||||||
|
cwd,
|
||||||
|
detail: "jj current change output did not include a change id",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
changeId,
|
||||||
|
commitId: commitId || null,
|
||||||
|
description: description || null,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function decodeJjBookmarkList(raw: string): ReadonlyArray<JjBookmark> {
|
||||||
|
return raw
|
||||||
|
.split(/\r?\n/g)
|
||||||
|
.map((line) => line.trim())
|
||||||
|
.filter((line) => line.length > 0)
|
||||||
|
.map((line) => {
|
||||||
|
const [name, target] = parseNullRecord(line);
|
||||||
|
return {
|
||||||
|
name: name ?? line,
|
||||||
|
target: target || null,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function decodeJjWorkspaceList(raw: string): ReadonlyArray<JjWorkspace> {
|
||||||
|
return raw
|
||||||
|
.split(/\r?\n/g)
|
||||||
|
.map((line) => line.trim())
|
||||||
|
.filter((line) => line.length > 0)
|
||||||
|
.map((line) => {
|
||||||
|
const [name, path] = parseNullRecord(line);
|
||||||
|
return {
|
||||||
|
name: name ?? line,
|
||||||
|
path: path || null,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function chunkPathsForCheckIgnore(relativePaths: ReadonlyArray<string>): string[][] {
|
||||||
|
const chunks: string[][] = [];
|
||||||
|
let chunk: string[] = [];
|
||||||
|
let chunkBytes = 0;
|
||||||
|
|
||||||
|
for (const relativePath of relativePaths) {
|
||||||
|
const relativePathBytes = Buffer.byteLength(relativePath) + 1;
|
||||||
|
if (chunk.length > 0 && chunkBytes + relativePathBytes > CHECK_IGNORE_MAX_STDIN_BYTES) {
|
||||||
|
chunks.push(chunk);
|
||||||
|
chunk = [];
|
||||||
|
chunkBytes = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
chunk.push(relativePath);
|
||||||
|
chunkBytes += relativePathBytes;
|
||||||
|
|
||||||
|
if (chunkBytes >= CHECK_IGNORE_MAX_STDIN_BYTES) {
|
||||||
|
chunks.push(chunk);
|
||||||
|
chunk = [];
|
||||||
|
chunkBytes = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (chunk.length > 0) {
|
||||||
|
chunks.push(chunk);
|
||||||
|
}
|
||||||
|
|
||||||
|
return chunks;
|
||||||
|
}
|
||||||
|
|
||||||
|
const processCommand = (
|
||||||
|
process: VcsProcessShape,
|
||||||
|
command: string,
|
||||||
|
operation: string,
|
||||||
|
cwd: string,
|
||||||
|
args: ReadonlyArray<string>,
|
||||||
|
options?: {
|
||||||
|
readonly stdin?: string;
|
||||||
|
readonly env?: NodeJS.ProcessEnv;
|
||||||
|
readonly allowNonZeroExit?: boolean;
|
||||||
|
readonly timeoutMs?: number;
|
||||||
|
readonly maxOutputBytes?: number;
|
||||||
|
readonly truncateOutputAtMaxBytes?: boolean;
|
||||||
|
},
|
||||||
|
) =>
|
||||||
|
process.run({
|
||||||
|
operation,
|
||||||
|
command,
|
||||||
|
args,
|
||||||
|
cwd,
|
||||||
|
...(options?.stdin !== undefined ? { stdin: options.stdin } : {}),
|
||||||
|
...(options?.env !== undefined ? { env: options.env } : {}),
|
||||||
|
...(options?.allowNonZeroExit !== undefined
|
||||||
|
? { allowNonZeroExit: options.allowNonZeroExit }
|
||||||
|
: {}),
|
||||||
|
...(options?.timeoutMs !== undefined ? { timeoutMs: options.timeoutMs } : {}),
|
||||||
|
...(options?.maxOutputBytes !== undefined ? { maxOutputBytes: options.maxOutputBytes } : {}),
|
||||||
|
...(options?.truncateOutputAtMaxBytes !== undefined
|
||||||
|
? { truncateOutputAtMaxBytes: options.truncateOutputAtMaxBytes }
|
||||||
|
: {}),
|
||||||
|
});
|
||||||
|
|
||||||
|
const jjCommand = (
|
||||||
|
process: VcsProcessShape,
|
||||||
|
operation: string,
|
||||||
|
cwd: string,
|
||||||
|
args: ReadonlyArray<string>,
|
||||||
|
options?: {
|
||||||
|
readonly stdin?: string;
|
||||||
|
readonly env?: NodeJS.ProcessEnv;
|
||||||
|
readonly allowNonZeroExit?: boolean;
|
||||||
|
readonly timeoutMs?: number;
|
||||||
|
readonly maxOutputBytes?: number;
|
||||||
|
readonly truncateOutputAtMaxBytes?: boolean;
|
||||||
|
},
|
||||||
|
) => processCommand(process, "jj", operation, cwd, ["--no-pager", ...args], options);
|
||||||
|
|
||||||
|
const gitCommand = (
|
||||||
|
process: VcsProcessShape,
|
||||||
|
operation: string,
|
||||||
|
cwd: string,
|
||||||
|
args: ReadonlyArray<string>,
|
||||||
|
options?: Parameters<typeof processCommand>[5],
|
||||||
|
) => processCommand(process, "git", operation, cwd, args, options);
|
||||||
|
|
||||||
|
function fileSystemError(operation: string, cwd: string, detail: string, cause: unknown) {
|
||||||
|
return new VcsOutputDecodeError({
|
||||||
|
operation,
|
||||||
|
command: "git check-ignore",
|
||||||
|
cwd,
|
||||||
|
detail,
|
||||||
|
cause,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const makeScopedTempGitDir = (fileSystem: FileSystem.FileSystem, operation: string, cwd: string) =>
|
||||||
|
fileSystem
|
||||||
|
.makeTempDirectoryScoped({ prefix: "t3-jj-check-ignore-" })
|
||||||
|
.pipe(
|
||||||
|
Effect.mapError((cause) =>
|
||||||
|
fileSystemError(operation, cwd, "failed to create temp git dir", cause),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
export const makeVcsDriverShape = Effect.fn("makeJjVcsDriverShape")(function* () {
|
||||||
|
const process = yield* VcsProcess;
|
||||||
|
const fileSystem = yield* FileSystem.FileSystem;
|
||||||
|
const capabilities = {
|
||||||
|
kind: "jj" as const,
|
||||||
|
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) =>
|
||||||
|
jjCommand(process, "JjVcsDriver.isInsideWorkTree", cwd, ["root"], {
|
||||||
|
allowNonZeroExit: true,
|
||||||
|
timeoutMs: 5_000,
|
||||||
|
maxOutputBytes: 4_096,
|
||||||
|
}).pipe(
|
||||||
|
Effect.map((result) => result.exitCode === 0 && result.stdout.trim().length > 0),
|
||||||
|
Effect.catch(() => Effect.succeed(false)),
|
||||||
|
);
|
||||||
|
|
||||||
|
const execute: VcsDriverShape["execute"] = (input) =>
|
||||||
|
jjCommand(process, input.operation, input.cwd, input.args, {
|
||||||
|
...(input.stdin !== undefined ? { stdin: input.stdin } : {}),
|
||||||
|
...(input.env !== undefined ? { env: input.env } : {}),
|
||||||
|
...(input.allowNonZeroExit !== undefined ? { allowNonZeroExit: input.allowNonZeroExit } : {}),
|
||||||
|
...(input.timeoutMs !== undefined ? { timeoutMs: input.timeoutMs } : {}),
|
||||||
|
...(input.maxOutputBytes !== undefined ? { maxOutputBytes: input.maxOutputBytes } : {}),
|
||||||
|
...(input.truncateOutputAtMaxBytes !== undefined
|
||||||
|
? { truncateOutputAtMaxBytes: input.truncateOutputAtMaxBytes }
|
||||||
|
: {}),
|
||||||
|
});
|
||||||
|
|
||||||
|
const initRepository: VcsDriverShape["initRepository"] = (input) =>
|
||||||
|
jjCommand(process, "JjVcsDriver.initRepository", input.cwd, ["git", "init"]);
|
||||||
|
|
||||||
|
const detectRepository: VcsDriverShape["detectRepository"] = Effect.fn("detectRepository")(
|
||||||
|
function* (cwd) {
|
||||||
|
const root = yield* jjCommand(process, "JjVcsDriver.detectRepository.root", cwd, ["root"], {
|
||||||
|
allowNonZeroExit: true,
|
||||||
|
timeoutMs: 5_000,
|
||||||
|
maxOutputBytes: 4_096,
|
||||||
|
}).pipe(Effect.catch(() => Effect.succeed(null)));
|
||||||
|
if (!root || root.exitCode !== 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const rootPath = root.stdout.trim();
|
||||||
|
if (rootPath.length === 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
kind: "jj" as const,
|
||||||
|
rootPath,
|
||||||
|
metadataPath: `${rootPath.replace(/[\\/]$/g, "")}/.jj`,
|
||||||
|
freshness: yield* nowFreshness(),
|
||||||
|
};
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
const listWorkspaceFiles: VcsDriverShape["listWorkspaceFiles"] = (cwd) =>
|
||||||
|
jjCommand(process, "JjVcsDriver.listWorkspaceFiles", cwd, ["file", "list"], {
|
||||||
|
allowNonZeroExit: true,
|
||||||
|
timeoutMs: 20_000,
|
||||||
|
maxOutputBytes: WORKSPACE_FILES_MAX_OUTPUT_BYTES,
|
||||||
|
truncateOutputAtMaxBytes: true,
|
||||||
|
}).pipe(
|
||||||
|
Effect.flatMap((result) =>
|
||||||
|
result.exitCode === 0
|
||||||
|
? Effect.gen(function* () {
|
||||||
|
return {
|
||||||
|
paths: splitLineSeparatedPaths(result.stdout, result.stdoutTruncated),
|
||||||
|
truncated: result.stdoutTruncated,
|
||||||
|
freshness: yield* nowFreshness(),
|
||||||
|
};
|
||||||
|
})
|
||||||
|
: Effect.fail(
|
||||||
|
new VcsProcessExitError({
|
||||||
|
operation: "JjVcsDriver.listWorkspaceFiles",
|
||||||
|
command: "jj file list",
|
||||||
|
cwd,
|
||||||
|
exitCode: result.exitCode,
|
||||||
|
detail: result.stderr.trim() || "jj file list failed",
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
const listRemotes: VcsDriverShape["listRemotes"] = Effect.fn("listRemotes")(function* (cwd) {
|
||||||
|
const result = yield* jjCommand(
|
||||||
|
process,
|
||||||
|
"JjVcsDriver.listRemotes",
|
||||||
|
cwd,
|
||||||
|
["git", "remote", "list"],
|
||||||
|
{
|
||||||
|
allowNonZeroExit: true,
|
||||||
|
timeoutMs: 5_000,
|
||||||
|
maxOutputBytes: 64 * 1024,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
if (result.exitCode !== 0) {
|
||||||
|
return {
|
||||||
|
remotes: [],
|
||||||
|
freshness: yield* nowFreshness(),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
remotes: parseJjRemoteList(result.stdout).map((remote) => ({
|
||||||
|
name: remote.name,
|
||||||
|
url: remote.url,
|
||||||
|
pushUrl: Option.none(),
|
||||||
|
isPrimary: remote.name === "origin",
|
||||||
|
})),
|
||||||
|
freshness: yield* nowFreshness(),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
const currentChange: JjVcsDriverShape["currentChange"] = (cwd) =>
|
||||||
|
jjCommand(
|
||||||
|
process,
|
||||||
|
"JjVcsDriver.currentChange",
|
||||||
|
cwd,
|
||||||
|
[
|
||||||
|
"log",
|
||||||
|
"-r",
|
||||||
|
"@",
|
||||||
|
"--no-graph",
|
||||||
|
"--template",
|
||||||
|
'change_id ++ "\\0" ++ commit_id ++ "\\0" ++ description.first_line()',
|
||||||
|
],
|
||||||
|
{
|
||||||
|
timeoutMs: 5_000,
|
||||||
|
maxOutputBytes: 64 * 1024,
|
||||||
|
},
|
||||||
|
).pipe(Effect.map((result) => decodeJjCurrentChange(result.stdout, cwd)));
|
||||||
|
|
||||||
|
const listBookmarks: JjVcsDriverShape["listBookmarks"] = (cwd) =>
|
||||||
|
jjCommand(
|
||||||
|
process,
|
||||||
|
"JjVcsDriver.listBookmarks",
|
||||||
|
cwd,
|
||||||
|
["bookmark", "list", "--template", 'name ++ "\\0" ++ target.commit_id() ++ "\\n"'],
|
||||||
|
{
|
||||||
|
allowNonZeroExit: true,
|
||||||
|
timeoutMs: 5_000,
|
||||||
|
maxOutputBytes: 256 * 1024,
|
||||||
|
},
|
||||||
|
).pipe(
|
||||||
|
Effect.map((result) => (result.exitCode === 0 ? decodeJjBookmarkList(result.stdout) : [])),
|
||||||
|
);
|
||||||
|
|
||||||
|
const listWorkspaces: JjVcsDriverShape["listWorkspaces"] = (cwd) =>
|
||||||
|
jjCommand(
|
||||||
|
process,
|
||||||
|
"JjVcsDriver.listWorkspaces",
|
||||||
|
cwd,
|
||||||
|
["workspace", "list", "--template", 'name ++ "\\0" ++ root ++ "\\n"'],
|
||||||
|
{
|
||||||
|
allowNonZeroExit: true,
|
||||||
|
timeoutMs: 5_000,
|
||||||
|
maxOutputBytes: 256 * 1024,
|
||||||
|
},
|
||||||
|
).pipe(
|
||||||
|
Effect.map((result) => (result.exitCode === 0 ? decodeJjWorkspaceList(result.stdout) : [])),
|
||||||
|
);
|
||||||
|
|
||||||
|
const filterIgnoredPaths: VcsDriverShape["filterIgnoredPaths"] = Effect.fn("filterIgnoredPaths")(
|
||||||
|
function* (cwd, relativePaths) {
|
||||||
|
if (relativePaths.length === 0) {
|
||||||
|
return relativePaths;
|
||||||
|
}
|
||||||
|
|
||||||
|
const operation = "JjVcsDriver.filterIgnoredPaths";
|
||||||
|
const ignoredPaths = new Set<string>();
|
||||||
|
|
||||||
|
yield* Effect.scoped(
|
||||||
|
Effect.gen(function* () {
|
||||||
|
const gitDir = yield* makeScopedTempGitDir(fileSystem, operation, cwd);
|
||||||
|
const initResult = yield* gitCommand(
|
||||||
|
process,
|
||||||
|
operation,
|
||||||
|
cwd,
|
||||||
|
["--git-dir", gitDir, "init", "--bare"],
|
||||||
|
{
|
||||||
|
allowNonZeroExit: true,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
if (initResult.exitCode !== 0) {
|
||||||
|
return yield* new VcsProcessExitError({
|
||||||
|
operation,
|
||||||
|
command: "git init --bare",
|
||||||
|
cwd,
|
||||||
|
exitCode: initResult.exitCode,
|
||||||
|
detail: initResult.stderr.trim() || "git init --bare failed",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const chunk of chunkPathsForCheckIgnore(relativePaths)) {
|
||||||
|
const result = yield* gitCommand(
|
||||||
|
process,
|
||||||
|
operation,
|
||||||
|
cwd,
|
||||||
|
[
|
||||||
|
"--git-dir",
|
||||||
|
gitDir,
|
||||||
|
"--work-tree",
|
||||||
|
cwd,
|
||||||
|
"check-ignore",
|
||||||
|
"--no-index",
|
||||||
|
"-z",
|
||||||
|
"--stdin",
|
||||||
|
],
|
||||||
|
{
|
||||||
|
stdin: `${chunk.join("\0")}\0`,
|
||||||
|
allowNonZeroExit: true,
|
||||||
|
timeoutMs: 20_000,
|
||||||
|
maxOutputBytes: WORKSPACE_FILES_MAX_OUTPUT_BYTES,
|
||||||
|
truncateOutputAtMaxBytes: true,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
if (result.exitCode !== 0 && result.exitCode !== 1) {
|
||||||
|
return yield* new VcsProcessExitError({
|
||||||
|
operation,
|
||||||
|
command: "git check-ignore",
|
||||||
|
cwd,
|
||||||
|
exitCode: result.exitCode,
|
||||||
|
detail: result.stderr.trim() || "git check-ignore failed",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const ignoredPath of splitNullSeparatedPaths(
|
||||||
|
result.stdout,
|
||||||
|
result.stdoutTruncated,
|
||||||
|
)) {
|
||||||
|
ignoredPaths.add(ignoredPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
if (ignoredPaths.size === 0) {
|
||||||
|
return relativePaths;
|
||||||
|
}
|
||||||
|
|
||||||
|
return relativePaths.filter((relativePath) => !ignoredPaths.has(relativePath));
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
return {
|
||||||
|
capabilities,
|
||||||
|
execute,
|
||||||
|
initRepository,
|
||||||
|
detectRepository,
|
||||||
|
isInsideWorkTree,
|
||||||
|
listWorkspaceFiles,
|
||||||
|
listRemotes,
|
||||||
|
filterIgnoredPaths,
|
||||||
|
currentChange,
|
||||||
|
listBookmarks,
|
||||||
|
listWorkspaces,
|
||||||
|
} satisfies JjVcsDriverShape;
|
||||||
|
});
|
||||||
|
|
||||||
|
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());
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import * as NodeServices from "@effect/platform-node/NodeServices";
|
||||||
import { assert, it } from "@effect/vitest";
|
import { assert, it } from "@effect/vitest";
|
||||||
import { Effect, Layer } from "effect";
|
import { Effect, Layer } from "effect";
|
||||||
import { ChildProcessSpawner } from "effect/unstable/process";
|
import { ChildProcessSpawner } from "effect/unstable/process";
|
||||||
@@ -7,10 +8,13 @@ import { VcsProcess, type VcsProcessInput, type VcsProcessOutput } from "./VcsPr
|
|||||||
import { VcsProjectConfig } from "./VcsProjectConfig.ts";
|
import { VcsProjectConfig } from "./VcsProjectConfig.ts";
|
||||||
import { VcsDriverRegistry, make as makeVcsDriverRegistry } from "./VcsDriverRegistry.ts";
|
import { VcsDriverRegistry, make as makeVcsDriverRegistry } from "./VcsDriverRegistry.ts";
|
||||||
|
|
||||||
const processOutput = (stdout: string): VcsProcessOutput => ({
|
const commandCalls = (calls: ReadonlyArray<VcsProcessInput>) =>
|
||||||
exitCode: ChildProcessSpawner.ExitCode(0),
|
calls.map((call) => [call.command].concat(call.args));
|
||||||
|
|
||||||
|
const processOutput = (stdout: string, exitCode = 0, stderr = ""): VcsProcessOutput => ({
|
||||||
|
exitCode: ChildProcessSpawner.ExitCode(exitCode),
|
||||||
stdout,
|
stdout,
|
||||||
stderr: "",
|
stderr,
|
||||||
stdoutTruncated: false,
|
stdoutTruncated: false,
|
||||||
stderrTruncated: false,
|
stderrTruncated: false,
|
||||||
});
|
});
|
||||||
@@ -28,6 +32,7 @@ describe("VcsDriverRegistry", () => {
|
|||||||
run: () => Effect.succeed(processOutput("")),
|
run: () => Effect.succeed(processOutput("")),
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
|
Layer.provide(NodeServices.layer),
|
||||||
);
|
);
|
||||||
|
|
||||||
return Effect.gen(function* () {
|
return Effect.gen(function* () {
|
||||||
@@ -65,6 +70,7 @@ describe("VcsDriverRegistry", () => {
|
|||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
|
Layer.provide(NodeServices.layer),
|
||||||
);
|
);
|
||||||
|
|
||||||
return Effect.gen(function* () {
|
return Effect.gen(function* () {
|
||||||
@@ -84,4 +90,75 @@ describe("VcsDriverRegistry", () => {
|
|||||||
);
|
);
|
||||||
}).pipe(Effect.provide(layer));
|
}).pipe(Effect.provide(layer));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it.effect("resolves an explicitly requested jj repository", () => {
|
||||||
|
const calls: VcsProcessInput[] = [];
|
||||||
|
const layer = Layer.effect(VcsDriverRegistry, makeVcsDriverRegistry()).pipe(
|
||||||
|
Layer.provide(
|
||||||
|
Layer.mock(VcsProjectConfig)({
|
||||||
|
resolveKind: (input) => Effect.succeed(input.requestedKind ?? "auto"),
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
Layer.provide(
|
||||||
|
Layer.mock(VcsProcess)({
|
||||||
|
run: (input) =>
|
||||||
|
Effect.sync(() => {
|
||||||
|
calls.push(input);
|
||||||
|
const command = input.args.join(" ");
|
||||||
|
if (input.command === "jj" && command === "--no-pager root") {
|
||||||
|
return processOutput("/repo\n");
|
||||||
|
}
|
||||||
|
return processOutput("", 1, "not found");
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
Layer.provide(NodeServices.layer),
|
||||||
|
);
|
||||||
|
|
||||||
|
return Effect.gen(function* () {
|
||||||
|
const registry = yield* VcsDriverRegistry;
|
||||||
|
const handle = yield* registry.resolve({ cwd: "/repo", requestedKind: "jj" });
|
||||||
|
|
||||||
|
assert.equal(handle.kind, "jj");
|
||||||
|
assert.equal(handle.repository.rootPath, "/repo");
|
||||||
|
assert.deepStrictEqual(commandCalls(calls), [["jj", "--no-pager", "root"]]);
|
||||||
|
}).pipe(Effect.provide(layer));
|
||||||
|
});
|
||||||
|
|
||||||
|
it.effect("prefers jj auto-detection before git for colocated repositories", () => {
|
||||||
|
const calls: VcsProcessInput[] = [];
|
||||||
|
const layer = Layer.effect(VcsDriverRegistry, makeVcsDriverRegistry()).pipe(
|
||||||
|
Layer.provide(
|
||||||
|
Layer.mock(VcsProjectConfig)({
|
||||||
|
resolveKind: (input) => Effect.succeed(input.requestedKind ?? "auto"),
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
Layer.provide(
|
||||||
|
Layer.mock(VcsProcess)({
|
||||||
|
run: (input) =>
|
||||||
|
Effect.sync(() => {
|
||||||
|
calls.push(input);
|
||||||
|
const command = input.args.join(" ");
|
||||||
|
if (input.command === "jj" && command === "--no-pager root") {
|
||||||
|
return processOutput("/repo\n");
|
||||||
|
}
|
||||||
|
if (input.command === "git") {
|
||||||
|
return processOutput("true\n");
|
||||||
|
}
|
||||||
|
return processOutput("", 1, "not found");
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
Layer.provide(NodeServices.layer),
|
||||||
|
);
|
||||||
|
|
||||||
|
return Effect.gen(function* () {
|
||||||
|
const registry = yield* VcsDriverRegistry;
|
||||||
|
const handle = yield* registry.resolve({ cwd: "/repo" });
|
||||||
|
|
||||||
|
assert.equal(handle.kind, "jj");
|
||||||
|
assert.equal(handle.repository.rootPath, "/repo");
|
||||||
|
assert.deepStrictEqual(commandCalls(calls), [["jj", "--no-pager", "root"]]);
|
||||||
|
}).pipe(Effect.provide(layer));
|
||||||
|
});
|
||||||
});
|
});
|
||||||
@@ -3,6 +3,7 @@ import { Cache, Context, Duration, Effect, Exit, Layer } from "effect";
|
|||||||
import type { VcsDriverKind, VcsError, VcsRepositoryIdentity } from "@t3tools/contracts";
|
import type { VcsDriverKind, VcsError, VcsRepositoryIdentity } from "@t3tools/contracts";
|
||||||
import { VcsUnsupportedOperationError } from "@t3tools/contracts";
|
import { VcsUnsupportedOperationError } from "@t3tools/contracts";
|
||||||
import * as GitVcsDriver from "./GitVcsDriver.ts";
|
import * as GitVcsDriver from "./GitVcsDriver.ts";
|
||||||
|
import * as JjVcsDriver from "./JjVcsDriver.ts";
|
||||||
import * as VcsProjectConfig from "./VcsProjectConfig.ts";
|
import * as VcsProjectConfig from "./VcsProjectConfig.ts";
|
||||||
import type { VcsDriverShape } from "./VcsDriver.ts";
|
import type { VcsDriverShape } from "./VcsDriver.ts";
|
||||||
|
|
||||||
@@ -66,8 +67,10 @@ function parseDetectionCacheKey(key: string): {
|
|||||||
export const make = Effect.fn("makeVcsDriverRegistry")(function* () {
|
export const make = Effect.fn("makeVcsDriverRegistry")(function* () {
|
||||||
const projectConfig = yield* VcsProjectConfig.VcsProjectConfig;
|
const projectConfig = yield* VcsProjectConfig.VcsProjectConfig;
|
||||||
const git = yield* GitVcsDriver.makeVcsDriverShape();
|
const git = yield* GitVcsDriver.makeVcsDriverShape();
|
||||||
|
const jj = yield* JjVcsDriver.makeVcsDriverShape();
|
||||||
const drivers: Partial<Record<VcsDriverKind, VcsDriverShape>> = {
|
const drivers: Partial<Record<VcsDriverKind, VcsDriverShape>> = {
|
||||||
git,
|
git,
|
||||||
|
jj,
|
||||||
};
|
};
|
||||||
|
|
||||||
const get: VcsDriverRegistryShape["get"] = (kind) => {
|
const get: VcsDriverRegistryShape["get"] = (kind) => {
|
||||||
@@ -107,6 +110,11 @@ export const make = Effect.fn("makeVcsDriverRegistry")(function* () {
|
|||||||
return yield* detectWithDriver(requestedKind, driver, input.cwd);
|
return yield* detectWithDriver(requestedKind, driver, input.cwd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const jjDetected = yield* detectWithDriver("jj", jj, input.cwd);
|
||||||
|
if (jjDetected) {
|
||||||
|
return jjDetected;
|
||||||
|
}
|
||||||
|
|
||||||
return yield* detectWithDriver("git", git, input.cwd);
|
return yield* detectWithDriver("git", git, input.cwd);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
import { DateTime, Effect, Option } from "effect";
|
||||||
|
|
||||||
|
export const nowFreshness = Effect.fn("VcsFreshness.nowFreshness")(function* () {
|
||||||
|
const now = yield* DateTime.now;
|
||||||
|
return {
|
||||||
|
source: "live-local" as const,
|
||||||
|
observedAt: now,
|
||||||
|
expiresAt: Option.none(),
|
||||||
|
};
|
||||||
|
});
|
||||||
@@ -16,6 +16,7 @@ import {
|
|||||||
import { GitWorkflowService, type GitWorkflowServiceShape } from "../git/GitWorkflowService.ts";
|
import { GitWorkflowService, type GitWorkflowServiceShape } from "../git/GitWorkflowService.ts";
|
||||||
|
|
||||||
const baseLocalStatus: VcsStatusLocalResult = {
|
const baseLocalStatus: VcsStatusLocalResult = {
|
||||||
|
kind: "git",
|
||||||
isRepo: true,
|
isRepo: true,
|
||||||
sourceControlProvider: {
|
sourceControlProvider: {
|
||||||
kind: "github",
|
kind: "github",
|
||||||
@@ -49,29 +50,30 @@ function makeTestLayer(state: {
|
|||||||
localInvalidationCalls: number;
|
localInvalidationCalls: number;
|
||||||
remoteInvalidationCalls: number;
|
remoteInvalidationCalls: number;
|
||||||
}) {
|
}) {
|
||||||
return VcsStatusBroadcasterLayer.pipe(
|
const gitWorkflowLayer = Layer.mock(GitWorkflowService)({
|
||||||
Layer.provide(
|
localStatus: () =>
|
||||||
Layer.mock(GitWorkflowService)({
|
Effect.sync(() => {
|
||||||
localStatus: () =>
|
state.localStatusCalls += 1;
|
||||||
Effect.sync(() => {
|
return state.currentLocalStatus;
|
||||||
state.localStatusCalls += 1;
|
|
||||||
return state.currentLocalStatus;
|
|
||||||
}),
|
|
||||||
remoteStatus: () =>
|
|
||||||
Effect.sync(() => {
|
|
||||||
state.remoteStatusCalls += 1;
|
|
||||||
return state.currentRemoteStatus;
|
|
||||||
}),
|
|
||||||
invalidateLocalStatus: () =>
|
|
||||||
Effect.sync(() => {
|
|
||||||
state.localInvalidationCalls += 1;
|
|
||||||
}),
|
|
||||||
invalidateRemoteStatus: () =>
|
|
||||||
Effect.sync(() => {
|
|
||||||
state.remoteInvalidationCalls += 1;
|
|
||||||
}),
|
|
||||||
}),
|
}),
|
||||||
),
|
remoteStatus: () =>
|
||||||
|
Effect.sync(() => {
|
||||||
|
state.remoteStatusCalls += 1;
|
||||||
|
return state.currentRemoteStatus;
|
||||||
|
}),
|
||||||
|
invalidateLocalStatus: () =>
|
||||||
|
Effect.sync(() => {
|
||||||
|
state.localInvalidationCalls += 1;
|
||||||
|
}),
|
||||||
|
invalidateRemoteStatus: () =>
|
||||||
|
Effect.sync(() => {
|
||||||
|
state.remoteInvalidationCalls += 1;
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
|
return VcsStatusBroadcasterLayer.pipe(
|
||||||
|
Layer.provideMerge(NodeServices.layer),
|
||||||
|
Layer.provide(gitWorkflowLayer),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -188,31 +190,31 @@ describe("VcsStatusBroadcaster", () => {
|
|||||||
localInvalidationCalls: 0,
|
localInvalidationCalls: 0,
|
||||||
remoteInvalidationCalls: 0,
|
remoteInvalidationCalls: 0,
|
||||||
};
|
};
|
||||||
|
const gitWorkflowLayer = Layer.mock(GitWorkflowService)({
|
||||||
|
localStatus: (input) =>
|
||||||
|
Effect.sync(() => {
|
||||||
|
seenCwds.push(input.cwd);
|
||||||
|
state.localStatusCalls += 1;
|
||||||
|
return state.currentLocalStatus;
|
||||||
|
}),
|
||||||
|
remoteStatus: (input) =>
|
||||||
|
Effect.sync(() => {
|
||||||
|
seenCwds.push(input.cwd);
|
||||||
|
state.remoteStatusCalls += 1;
|
||||||
|
return state.currentRemoteStatus;
|
||||||
|
}),
|
||||||
|
invalidateLocalStatus: () =>
|
||||||
|
Effect.sync(() => {
|
||||||
|
state.localInvalidationCalls += 1;
|
||||||
|
}),
|
||||||
|
invalidateRemoteStatus: () =>
|
||||||
|
Effect.sync(() => {
|
||||||
|
state.remoteInvalidationCalls += 1;
|
||||||
|
}),
|
||||||
|
} satisfies Partial<GitWorkflowServiceShape>);
|
||||||
const testLayer = VcsStatusBroadcasterLayer.pipe(
|
const testLayer = VcsStatusBroadcasterLayer.pipe(
|
||||||
Layer.provide(
|
Layer.provideMerge(NodeServices.layer),
|
||||||
Layer.mock(GitWorkflowService)({
|
Layer.provide(gitWorkflowLayer),
|
||||||
localStatus: (input) =>
|
|
||||||
Effect.sync(() => {
|
|
||||||
seenCwds.push(input.cwd);
|
|
||||||
state.localStatusCalls += 1;
|
|
||||||
return state.currentLocalStatus;
|
|
||||||
}),
|
|
||||||
remoteStatus: (input) =>
|
|
||||||
Effect.sync(() => {
|
|
||||||
seenCwds.push(input.cwd);
|
|
||||||
state.remoteStatusCalls += 1;
|
|
||||||
return state.currentRemoteStatus;
|
|
||||||
}),
|
|
||||||
invalidateLocalStatus: () =>
|
|
||||||
Effect.sync(() => {
|
|
||||||
state.localInvalidationCalls += 1;
|
|
||||||
}),
|
|
||||||
invalidateRemoteStatus: () =>
|
|
||||||
Effect.sync(() => {
|
|
||||||
state.remoteInvalidationCalls += 1;
|
|
||||||
}),
|
|
||||||
} satisfies Partial<GitWorkflowServiceShape>),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
return Effect.gen(function* () {
|
return Effect.gen(function* () {
|
||||||
@@ -235,7 +237,7 @@ describe("VcsStatusBroadcaster", () => {
|
|||||||
assert.deepStrictEqual(seenCwds, [realPath, realPath]);
|
assert.deepStrictEqual(seenCwds, [realPath, realPath]);
|
||||||
assert.equal(state.localStatusCalls, 1);
|
assert.equal(state.localStatusCalls, 1);
|
||||||
assert.equal(state.remoteStatusCalls, 1);
|
assert.equal(state.remoteStatusCalls, 1);
|
||||||
}).pipe(Effect.provide(Layer.mergeAll(testLayer, NodeServices.layer)));
|
}).pipe(Effect.provide(testLayer));
|
||||||
});
|
});
|
||||||
|
|
||||||
it.effect("streams a local snapshot first and remote updates later", () => {
|
it.effect("streams a local snapshot first and remote updates later", () => {
|
||||||
@@ -289,40 +291,40 @@ describe("VcsStatusBroadcaster", () => {
|
|||||||
};
|
};
|
||||||
let remoteInterruptedDeferred: Deferred.Deferred<void, never> | null = null;
|
let remoteInterruptedDeferred: Deferred.Deferred<void, never> | null = null;
|
||||||
let remoteStartedDeferred: Deferred.Deferred<void, never> | null = null;
|
let remoteStartedDeferred: Deferred.Deferred<void, never> | null = null;
|
||||||
|
const gitWorkflowLayer = Layer.mock(GitWorkflowService)({
|
||||||
|
localStatus: () =>
|
||||||
|
Effect.sync(() => {
|
||||||
|
state.localStatusCalls += 1;
|
||||||
|
return state.currentLocalStatus;
|
||||||
|
}),
|
||||||
|
remoteStatus: () =>
|
||||||
|
Effect.sync(() => {
|
||||||
|
state.remoteStatusCalls += 1;
|
||||||
|
}).pipe(
|
||||||
|
Effect.andThen(
|
||||||
|
remoteStartedDeferred
|
||||||
|
? Deferred.succeed(remoteStartedDeferred, undefined).pipe(Effect.ignore)
|
||||||
|
: Effect.void,
|
||||||
|
),
|
||||||
|
Effect.andThen(Effect.never as Effect.Effect<VcsStatusRemoteResult | null, never>),
|
||||||
|
Effect.onInterrupt(() =>
|
||||||
|
remoteInterruptedDeferred
|
||||||
|
? Deferred.succeed(remoteInterruptedDeferred, undefined).pipe(Effect.ignore)
|
||||||
|
: Effect.void,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
invalidateLocalStatus: () =>
|
||||||
|
Effect.sync(() => {
|
||||||
|
state.localInvalidationCalls += 1;
|
||||||
|
}),
|
||||||
|
invalidateRemoteStatus: () =>
|
||||||
|
Effect.sync(() => {
|
||||||
|
state.remoteInvalidationCalls += 1;
|
||||||
|
}),
|
||||||
|
} satisfies Partial<GitWorkflowServiceShape>);
|
||||||
const testLayer = VcsStatusBroadcasterLayer.pipe(
|
const testLayer = VcsStatusBroadcasterLayer.pipe(
|
||||||
Layer.provide(
|
Layer.provideMerge(NodeServices.layer),
|
||||||
Layer.mock(GitWorkflowService)({
|
Layer.provide(gitWorkflowLayer),
|
||||||
localStatus: () =>
|
|
||||||
Effect.sync(() => {
|
|
||||||
state.localStatusCalls += 1;
|
|
||||||
return state.currentLocalStatus;
|
|
||||||
}),
|
|
||||||
remoteStatus: () =>
|
|
||||||
Effect.sync(() => {
|
|
||||||
state.remoteStatusCalls += 1;
|
|
||||||
}).pipe(
|
|
||||||
Effect.andThen(
|
|
||||||
remoteStartedDeferred
|
|
||||||
? Deferred.succeed(remoteStartedDeferred, undefined).pipe(Effect.ignore)
|
|
||||||
: Effect.void,
|
|
||||||
),
|
|
||||||
Effect.andThen(Effect.never as Effect.Effect<VcsStatusRemoteResult | null, never>),
|
|
||||||
Effect.onInterrupt(() =>
|
|
||||||
remoteInterruptedDeferred
|
|
||||||
? Deferred.succeed(remoteInterruptedDeferred, undefined).pipe(Effect.ignore)
|
|
||||||
: Effect.void,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
invalidateLocalStatus: () =>
|
|
||||||
Effect.sync(() => {
|
|
||||||
state.localInvalidationCalls += 1;
|
|
||||||
}),
|
|
||||||
invalidateRemoteStatus: () =>
|
|
||||||
Effect.sync(() => {
|
|
||||||
state.remoteInvalidationCalls += 1;
|
|
||||||
}),
|
|
||||||
} satisfies Partial<GitWorkflowServiceShape>),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
return Effect.gen(function* () {
|
return Effect.gen(function* () {
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
import { realpathSync } from "node:fs";
|
|
||||||
|
|
||||||
import {
|
import {
|
||||||
Duration,
|
Duration,
|
||||||
Effect,
|
Effect,
|
||||||
Exit,
|
Exit,
|
||||||
|
FileSystem,
|
||||||
Fiber,
|
Fiber,
|
||||||
Layer,
|
Layer,
|
||||||
PubSub,
|
PubSub,
|
||||||
@@ -69,18 +68,11 @@ function fingerprintStatusPart(status: unknown): string {
|
|||||||
return JSON.stringify(status);
|
return JSON.stringify(status);
|
||||||
}
|
}
|
||||||
|
|
||||||
function normalizeCwd(cwd: string): string {
|
|
||||||
try {
|
|
||||||
return realpathSync.native(cwd);
|
|
||||||
} catch {
|
|
||||||
return cwd;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export const layer = Layer.effect(
|
export const layer = Layer.effect(
|
||||||
VcsStatusBroadcaster,
|
VcsStatusBroadcaster,
|
||||||
Effect.gen(function* () {
|
Effect.gen(function* () {
|
||||||
const workflow = yield* GitWorkflowService;
|
const workflow = yield* GitWorkflowService;
|
||||||
|
const fileSystem = yield* FileSystem.FileSystem;
|
||||||
const changesPubSub = yield* Effect.acquireRelease(
|
const changesPubSub = yield* Effect.acquireRelease(
|
||||||
PubSub.unbounded<VcsStatusChange>(),
|
PubSub.unbounded<VcsStatusChange>(),
|
||||||
(pubsub) => PubSub.shutdown(pubsub),
|
(pubsub) => PubSub.shutdown(pubsub),
|
||||||
@@ -91,6 +83,9 @@ export const layer = Layer.effect(
|
|||||||
const cacheRef = yield* Ref.make(new Map<string, CachedVcsStatus>());
|
const cacheRef = yield* Ref.make(new Map<string, CachedVcsStatus>());
|
||||||
const pollersRef = yield* SynchronizedRef.make(new Map<string, ActiveRemotePoller>());
|
const pollersRef = yield* SynchronizedRef.make(new Map<string, ActiveRemotePoller>());
|
||||||
|
|
||||||
|
const normalizeCwd = (cwd: string) =>
|
||||||
|
fileSystem.realPath(cwd).pipe(Effect.catch(() => Effect.succeed(cwd)));
|
||||||
|
|
||||||
const getCachedStatus = Effect.fn("VcsStatusBroadcaster.getCachedStatus")(function* (
|
const getCachedStatus = Effect.fn("VcsStatusBroadcaster.getCachedStatus")(function* (
|
||||||
cwd: string,
|
cwd: string,
|
||||||
) {
|
) {
|
||||||
@@ -198,7 +193,7 @@ export const layer = Layer.effect(
|
|||||||
const getStatus: VcsStatusBroadcasterShape["getStatus"] = Effect.fn(
|
const getStatus: VcsStatusBroadcasterShape["getStatus"] = Effect.fn(
|
||||||
"VcsStatusBroadcaster.getStatus",
|
"VcsStatusBroadcaster.getStatus",
|
||||||
)(function* (input) {
|
)(function* (input) {
|
||||||
const cwd = normalizeCwd(input.cwd);
|
const cwd = yield* normalizeCwd(input.cwd);
|
||||||
const [local, remote] = yield* Effect.all([
|
const [local, remote] = yield* Effect.all([
|
||||||
getOrLoadLocalStatus(cwd),
|
getOrLoadLocalStatus(cwd),
|
||||||
getOrLoadRemoteStatus(cwd),
|
getOrLoadRemoteStatus(cwd),
|
||||||
@@ -206,13 +201,19 @@ export const layer = Layer.effect(
|
|||||||
return mergeGitStatusParts(local, remote);
|
return mergeGitStatusParts(local, remote);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const refreshLocalStatusCore = Effect.fn("VcsStatusBroadcaster.refreshLocalStatusCore")(
|
||||||
|
function* (cwd: string) {
|
||||||
|
yield* workflow.invalidateLocalStatus(cwd);
|
||||||
|
const local = yield* workflow.localStatus({ cwd });
|
||||||
|
return yield* updateCachedLocalStatus(cwd, local, { publish: true });
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
const refreshLocalStatus: VcsStatusBroadcasterShape["refreshLocalStatus"] = Effect.fn(
|
const refreshLocalStatus: VcsStatusBroadcasterShape["refreshLocalStatus"] = Effect.fn(
|
||||||
"VcsStatusBroadcaster.refreshLocalStatus",
|
"VcsStatusBroadcaster.refreshLocalStatus",
|
||||||
)(function* (rawCwd) {
|
)(function* (rawCwd) {
|
||||||
const cwd = normalizeCwd(rawCwd);
|
const cwd = yield* normalizeCwd(rawCwd);
|
||||||
yield* workflow.invalidateLocalStatus(cwd);
|
return yield* refreshLocalStatusCore(cwd);
|
||||||
const local = yield* workflow.localStatus({ cwd });
|
|
||||||
return yield* updateCachedLocalStatus(cwd, local, { publish: true });
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const refreshRemoteStatus = Effect.fn("VcsStatusBroadcaster.refreshRemoteStatus")(function* (
|
const refreshRemoteStatus = Effect.fn("VcsStatusBroadcaster.refreshRemoteStatus")(function* (
|
||||||
@@ -226,9 +227,9 @@ export const layer = Layer.effect(
|
|||||||
const refreshStatus: VcsStatusBroadcasterShape["refreshStatus"] = Effect.fn(
|
const refreshStatus: VcsStatusBroadcasterShape["refreshStatus"] = Effect.fn(
|
||||||
"VcsStatusBroadcaster.refreshStatus",
|
"VcsStatusBroadcaster.refreshStatus",
|
||||||
)(function* (rawCwd) {
|
)(function* (rawCwd) {
|
||||||
const cwd = normalizeCwd(rawCwd);
|
const cwd = yield* normalizeCwd(rawCwd);
|
||||||
const [local, remote] = yield* Effect.all([
|
const [local, remote] = yield* Effect.all([
|
||||||
refreshLocalStatus(cwd),
|
refreshLocalStatusCore(cwd),
|
||||||
refreshRemoteStatus(cwd),
|
refreshRemoteStatus(cwd),
|
||||||
]);
|
]);
|
||||||
return mergeGitStatusParts(local, remote);
|
return mergeGitStatusParts(local, remote);
|
||||||
@@ -312,7 +313,7 @@ export const layer = Layer.effect(
|
|||||||
const streamStatus: VcsStatusBroadcasterShape["streamStatus"] = (input) =>
|
const streamStatus: VcsStatusBroadcasterShape["streamStatus"] = (input) =>
|
||||||
Stream.unwrap(
|
Stream.unwrap(
|
||||||
Effect.gen(function* () {
|
Effect.gen(function* () {
|
||||||
const cwd = normalizeCwd(input.cwd);
|
const cwd = yield* normalizeCwd(input.cwd);
|
||||||
const subscription = yield* PubSub.subscribe(changesPubSub);
|
const subscription = yield* PubSub.subscribe(changesPubSub);
|
||||||
const initialLocal = yield* getOrLoadLocalStatus(cwd);
|
const initialLocal = yield* getOrLoadLocalStatus(cwd);
|
||||||
const initialRemote = (yield* getCachedStatus(cwd))?.remote?.value ?? null;
|
const initialRemote = (yield* getCachedStatus(cwd))?.remote?.value ?? null;
|
||||||
|
|||||||
@@ -56,9 +56,11 @@ export function runVcsDriverContractSuite<R, E>(input: VcsDriverContractSuiteInp
|
|||||||
|
|
||||||
yield* input.fixture.createRepo(cwd);
|
yield* input.fixture.createRepo(cwd);
|
||||||
yield* input.fixture.writeFile(cwd, "src/index.ts", "export const value = 1;\n");
|
yield* input.fixture.writeFile(cwd, "src/index.ts", "export const value = 1;\n");
|
||||||
|
const fileSystem = yield* FileSystem.FileSystem;
|
||||||
|
const realCwd = yield* fileSystem.realPath(cwd);
|
||||||
const identity = yield* driver.detectRepository(cwd);
|
const identity = yield* driver.detectRepository(cwd);
|
||||||
assert.equal(identity?.kind, input.kind);
|
assert.equal(identity?.kind, input.kind);
|
||||||
assert.isTrue(identity?.rootPath.endsWith(cwd));
|
assert.isTrue(identity?.rootPath.endsWith(realCwd));
|
||||||
assert.equal(identity?.freshness.source, "live-local");
|
assert.equal(identity?.freshness.source, "live-local");
|
||||||
assert.isTrue(DateTime.isDateTime(identity?.freshness.observedAt));
|
assert.isTrue(DateTime.isDateTime(identity?.freshness.observedAt));
|
||||||
assert.isTrue(Option.isNone(identity?.freshness.expiresAt ?? Option.none()));
|
assert.isTrue(Option.isNone(identity?.freshness.expiresAt ?? Option.none()));
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import { parsePullRequestReference } from "../pullRequestReference";
|
|||||||
import { getSourceControlPresentation } from "../sourceControlPresentation";
|
import { getSourceControlPresentation } from "../sourceControlPresentation";
|
||||||
import { useStore } from "../store";
|
import { useStore } from "../store";
|
||||||
import { createProjectSelectorByRef, createThreadSelectorByRef } from "../storeSelectors";
|
import { createProjectSelectorByRef, createThreadSelectorByRef } from "../storeSelectors";
|
||||||
|
import { resolveVcsTerms } from "../vcsPresentation";
|
||||||
import {
|
import {
|
||||||
deriveLocalBranchNameFromRemoteRef,
|
deriveLocalBranchNameFromRemoteRef,
|
||||||
resolveBranchSelectionTarget,
|
resolveBranchSelectionTarget,
|
||||||
@@ -67,10 +68,11 @@ function getBranchTriggerLabel(input: {
|
|||||||
activeWorktreePath: string | null;
|
activeWorktreePath: string | null;
|
||||||
effectiveEnvMode: "local" | "worktree";
|
effectiveEnvMode: "local" | "worktree";
|
||||||
resolvedActiveBranch: string | null;
|
resolvedActiveBranch: string | null;
|
||||||
|
refNoun: string;
|
||||||
}): string {
|
}): string {
|
||||||
const { activeWorktreePath, effectiveEnvMode, resolvedActiveBranch } = input;
|
const { activeWorktreePath, effectiveEnvMode, resolvedActiveBranch, refNoun } = input;
|
||||||
if (!resolvedActiveBranch) {
|
if (!resolvedActiveBranch) {
|
||||||
return "Select ref";
|
return `Select ${refNoun}`;
|
||||||
}
|
}
|
||||||
if (effectiveEnvMode === "worktree" && !activeWorktreePath) {
|
if (effectiveEnvMode === "worktree" && !activeWorktreePath) {
|
||||||
return `From ${resolvedActiveBranch}`;
|
return `From ${resolvedActiveBranch}`;
|
||||||
@@ -202,6 +204,7 @@ export function BranchToolbarBranchSelector({
|
|||||||
const deferredBranchQuery = useDeferredValue(branchQuery);
|
const deferredBranchQuery = useDeferredValue(branchQuery);
|
||||||
|
|
||||||
const branchStatusQuery = useGitStatus({ environmentId, cwd: branchCwd });
|
const branchStatusQuery = useGitStatus({ environmentId, cwd: branchCwd });
|
||||||
|
const vcsTerms = resolveVcsTerms(branchStatusQuery.data?.kind);
|
||||||
const trimmedBranchQuery = branchQuery.trim();
|
const trimmedBranchQuery = branchQuery.trim();
|
||||||
const deferredTrimmedBranchQuery = deferredBranchQuery.trim();
|
const deferredTrimmedBranchQuery = deferredBranchQuery.trim();
|
||||||
|
|
||||||
@@ -295,11 +298,11 @@ export function BranchToolbarBranchSelector({
|
|||||||
const shouldVirtualizeBranchList = filteredBranchPickerItems.length > 40;
|
const shouldVirtualizeBranchList = filteredBranchPickerItems.length > 40;
|
||||||
const totalBranchCount = branchesSearchData?.pages[0]?.totalCount ?? 0;
|
const totalBranchCount = branchesSearchData?.pages[0]?.totalCount ?? 0;
|
||||||
const branchStatusText = isBranchesSearchPending
|
const branchStatusText = isBranchesSearchPending
|
||||||
? "Loading refs..."
|
? `Loading ${vcsTerms.refNounPlural}...`
|
||||||
: isFetchingNextPage
|
: isFetchingNextPage
|
||||||
? "Loading more refs..."
|
? `Loading more ${vcsTerms.refNounPlural}...`
|
||||||
: hasNextPage
|
: hasNextPage
|
||||||
? `Showing ${refs.length} of ${totalBranchCount} refs`
|
? `Showing ${refs.length} of ${totalBranchCount} ${vcsTerms.refNounPlural}`
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
@@ -363,7 +366,7 @@ export function BranchToolbarBranchSelector({
|
|||||||
toastManager.add(
|
toastManager.add(
|
||||||
stackedThreadToast({
|
stackedThreadToast({
|
||||||
type: "error",
|
type: "error",
|
||||||
title: "Failed to switch ref.",
|
title: `Failed to switch ${vcsTerms.refNoun}.`,
|
||||||
description: toBranchActionErrorMessage(error),
|
description: toBranchActionErrorMessage(error),
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
@@ -395,7 +398,7 @@ export function BranchToolbarBranchSelector({
|
|||||||
toastManager.add(
|
toastManager.add(
|
||||||
stackedThreadToast({
|
stackedThreadToast({
|
||||||
type: "error",
|
type: "error",
|
||||||
title: "Failed to create and switch ref.",
|
title: `Failed to create and switch ${vcsTerms.refNoun}.`,
|
||||||
description: toBranchActionErrorMessage(error),
|
description: toBranchActionErrorMessage(error),
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
@@ -494,6 +497,7 @@ export function BranchToolbarBranchSelector({
|
|||||||
activeWorktreePath,
|
activeWorktreePath,
|
||||||
effectiveEnvMode,
|
effectiveEnvMode,
|
||||||
resolvedActiveBranch,
|
resolvedActiveBranch,
|
||||||
|
refNoun: vcsTerms.refNoun,
|
||||||
});
|
});
|
||||||
|
|
||||||
function renderPickerItem(itemValue: string, index: number) {
|
function renderPickerItem(itemValue: string, index: number) {
|
||||||
@@ -535,7 +539,9 @@ export function BranchToolbarBranchSelector({
|
|||||||
value={itemValue}
|
value={itemValue}
|
||||||
onClick={() => createRef(trimmedBranchQuery)}
|
onClick={() => createRef(trimmedBranchQuery)}
|
||||||
>
|
>
|
||||||
<span className="truncate">Create new ref "{trimmedBranchQuery}"</span>
|
<span className="truncate">
|
||||||
|
Create new {vcsTerms.refNoun} "{trimmedBranchQuery}"
|
||||||
|
</span>
|
||||||
</ComboboxItem>
|
</ComboboxItem>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1458,7 +1458,8 @@ export default function ChatView(props: ChatViewProps) {
|
|||||||
? terminalLaunchContext
|
? terminalLaunchContext
|
||||||
: (storeServerTerminalLaunchContext ?? null);
|
: (storeServerTerminalLaunchContext ?? null);
|
||||||
// Default true while loading to avoid toolbar flicker.
|
// Default true while loading to avoid toolbar flicker.
|
||||||
const isGitRepo = gitStatusQuery.data?.isRepo ?? true;
|
const vcsKind = gitStatusQuery.data?.kind ?? null;
|
||||||
|
const isVcsRepo = gitStatusQuery.data?.isRepo ?? true;
|
||||||
const terminalShortcutLabelOptions = useMemo(
|
const terminalShortcutLabelOptions = useMemo(
|
||||||
() => ({
|
() => ({
|
||||||
context: {
|
context: {
|
||||||
@@ -2136,7 +2137,7 @@ export default function ChatView(props: ChatViewProps) {
|
|||||||
: (activeThread?.branch ?? null);
|
: (activeThread?.branch ?? null);
|
||||||
const sendEnvMode = resolveSendEnvMode({
|
const sendEnvMode = resolveSendEnvMode({
|
||||||
requestedEnvMode: envMode,
|
requestedEnvMode: envMode,
|
||||||
isGitRepo,
|
isGitRepo: isVcsRepo,
|
||||||
});
|
});
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -3297,7 +3298,8 @@ export default function ChatView(props: ChatViewProps) {
|
|||||||
{...(routeKind === "draft" && draftId ? { draftId } : {})}
|
{...(routeKind === "draft" && draftId ? { draftId } : {})}
|
||||||
activeThreadTitle={activeThread.title}
|
activeThreadTitle={activeThread.title}
|
||||||
activeProjectName={activeProject?.name}
|
activeProjectName={activeProject?.name}
|
||||||
isGitRepo={isGitRepo}
|
isVcsRepo={isVcsRepo}
|
||||||
|
vcsKind={vcsKind}
|
||||||
openInCwd={gitCwd}
|
openInCwd={gitCwd}
|
||||||
activeProjectScripts={activeProject?.scripts}
|
activeProjectScripts={activeProject?.scripts}
|
||||||
preferredScriptId={
|
preferredScriptId={
|
||||||
@@ -3377,7 +3379,7 @@ export default function ChatView(props: ChatViewProps) {
|
|||||||
<div
|
<div
|
||||||
className={cn(
|
className={cn(
|
||||||
"pl-[calc(env(safe-area-inset-left)+0.75rem)] pr-[calc(env(safe-area-inset-right)+0.75rem)] pt-1.5 sm:pl-[calc(env(safe-area-inset-left)+1.25rem)] sm:pr-[calc(env(safe-area-inset-right)+1.25rem)] sm:pt-2",
|
"pl-[calc(env(safe-area-inset-left)+0.75rem)] pr-[calc(env(safe-area-inset-right)+0.75rem)] pt-1.5 sm:pl-[calc(env(safe-area-inset-left)+1.25rem)] sm:pr-[calc(env(safe-area-inset-right)+1.25rem)] sm:pt-2",
|
||||||
isGitRepo
|
isVcsRepo
|
||||||
? "pb-[calc(env(safe-area-inset-bottom)+0.25rem)]"
|
? "pb-[calc(env(safe-area-inset-bottom)+0.25rem)]"
|
||||||
: "pb-[calc(env(safe-area-inset-bottom)+0.75rem)] sm:pb-[calc(env(safe-area-inset-bottom)+1rem)]",
|
: "pb-[calc(env(safe-area-inset-bottom)+0.75rem)] sm:pb-[calc(env(safe-area-inset-bottom)+1rem)]",
|
||||||
)}
|
)}
|
||||||
@@ -3450,7 +3452,7 @@ export default function ChatView(props: ChatViewProps) {
|
|||||||
setThreadError={setThreadError}
|
setThreadError={setThreadError}
|
||||||
onExpandImage={onExpandTimelineImage}
|
onExpandImage={onExpandTimelineImage}
|
||||||
/>
|
/>
|
||||||
{isGitRepo && (
|
{isVcsRepo && (
|
||||||
<BranchToolbar
|
<BranchToolbar
|
||||||
environmentId={activeThread.environmentId}
|
environmentId={activeThread.environmentId}
|
||||||
threadId={activeThread.id}
|
threadId={activeThread.id}
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ import { createThreadSelectorByRef } from "../storeSelectors";
|
|||||||
import { buildThreadRouteParams, resolveThreadRouteRef } from "../threadRoutes";
|
import { buildThreadRouteParams, resolveThreadRouteRef } from "../threadRoutes";
|
||||||
import { useSettings } from "../hooks/useSettings";
|
import { useSettings } from "../hooks/useSettings";
|
||||||
import { formatShortTimestamp } from "../timestampFormat";
|
import { formatShortTimestamp } from "../timestampFormat";
|
||||||
|
import { resolveVcsTerms } from "../vcsPresentation";
|
||||||
import { DiffPanelLoadingState, DiffPanelShell, type DiffPanelMode } from "./DiffPanelShell";
|
import { DiffPanelLoadingState, DiffPanelShell, type DiffPanelMode } from "./DiffPanelShell";
|
||||||
import { ToggleGroup, Toggle } from "./ui/toggle-group";
|
import { ToggleGroup, Toggle } from "./ui/toggle-group";
|
||||||
|
|
||||||
@@ -201,7 +202,8 @@ export default function DiffPanel({ mode = "inline" }: DiffPanelProps) {
|
|||||||
environmentId: activeThread?.environmentId ?? null,
|
environmentId: activeThread?.environmentId ?? null,
|
||||||
cwd: activeCwd ?? null,
|
cwd: activeCwd ?? null,
|
||||||
});
|
});
|
||||||
const isGitRepo = gitStatusQuery.data?.isRepo ?? true;
|
const isVcsRepo = gitStatusQuery.data?.isRepo ?? true;
|
||||||
|
const vcsTerms = resolveVcsTerms(gitStatusQuery.data?.kind);
|
||||||
const { turnDiffSummaries, inferredCheckpointTurnCountByTurnId } =
|
const { turnDiffSummaries, inferredCheckpointTurnCountByTurnId } =
|
||||||
useTurnDiffSummaries(activeThread);
|
useTurnDiffSummaries(activeThread);
|
||||||
const orderedTurnDiffSummaries = useMemo(
|
const orderedTurnDiffSummaries = useMemo(
|
||||||
@@ -278,7 +280,7 @@ export default function DiffPanel({ mode = "inline" }: DiffPanelProps) {
|
|||||||
fromTurnCount: activeCheckpointRange?.fromTurnCount ?? null,
|
fromTurnCount: activeCheckpointRange?.fromTurnCount ?? null,
|
||||||
toTurnCount: activeCheckpointRange?.toTurnCount ?? null,
|
toTurnCount: activeCheckpointRange?.toTurnCount ?? null,
|
||||||
cacheScope: selectedTurn ? `turn:${selectedTurn.turnId}` : conversationCacheScope,
|
cacheScope: selectedTurn ? `turn:${selectedTurn.turnId}` : conversationCacheScope,
|
||||||
enabled: isGitRepo,
|
enabled: isVcsRepo,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
const selectedTurnCheckpointDiff = selectedTurn
|
const selectedTurnCheckpointDiff = selectedTurn
|
||||||
@@ -561,9 +563,9 @@ export default function DiffPanel({ mode = "inline" }: DiffPanelProps) {
|
|||||||
<div className="flex flex-1 items-center justify-center px-5 text-center text-xs text-muted-foreground/70">
|
<div className="flex flex-1 items-center justify-center px-5 text-center text-xs text-muted-foreground/70">
|
||||||
Select a thread to inspect turn diffs.
|
Select a thread to inspect turn diffs.
|
||||||
</div>
|
</div>
|
||||||
) : !isGitRepo ? (
|
) : !isVcsRepo ? (
|
||||||
<div className="flex flex-1 items-center justify-center px-5 text-center text-xs text-muted-foreground/70">
|
<div className="flex flex-1 items-center justify-center px-5 text-center text-xs text-muted-foreground/70">
|
||||||
Turn diffs are unavailable because this project is not a git repository.
|
Turn diffs are unavailable because this project is not a {vcsTerms.repositoryNoun}.
|
||||||
</div>
|
</div>
|
||||||
) : orderedTurnDiffSummaries.length === 0 ? (
|
) : orderedTurnDiffSummaries.length === 0 ? (
|
||||||
<div className="flex flex-1 items-center justify-center px-5 text-center text-xs text-muted-foreground/70">
|
<div className="flex flex-1 items-center justify-center px-5 text-center text-xs text-muted-foreground/70">
|
||||||
|
|||||||
@@ -113,6 +113,7 @@ vi.mock("~/lib/gitStatusState", () => ({
|
|||||||
resetGitStatusStateForTests: () => undefined,
|
resetGitStatusStateForTests: () => undefined,
|
||||||
useGitStatus: vi.fn(() => ({
|
useGitStatus: vi.fn(() => ({
|
||||||
data: {
|
data: {
|
||||||
|
kind: "git",
|
||||||
isRepo: true,
|
isRepo: true,
|
||||||
sourceControlProvider: {
|
sourceControlProvider: {
|
||||||
kind: "github",
|
kind: "github",
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import {
|
|||||||
|
|
||||||
function status(overrides: Partial<VcsStatusResult> = {}): VcsStatusResult {
|
function status(overrides: Partial<VcsStatusResult> = {}): VcsStatusResult {
|
||||||
return {
|
return {
|
||||||
|
kind: "git",
|
||||||
isRepo: true,
|
isRepo: true,
|
||||||
hasPrimaryRemote: true,
|
hasPrimaryRemote: true,
|
||||||
isDefaultRef: false,
|
isDefaultRef: false,
|
||||||
|
|||||||
@@ -54,6 +54,7 @@ import { readLocalApi } from "~/localApi";
|
|||||||
import { getSourceControlPresentation } from "~/sourceControlPresentation";
|
import { getSourceControlPresentation } from "~/sourceControlPresentation";
|
||||||
import { useStore } from "~/store";
|
import { useStore } from "~/store";
|
||||||
import { createThreadSelectorByRef } from "~/storeSelectors";
|
import { createThreadSelectorByRef } from "~/storeSelectors";
|
||||||
|
import { resolveVcsActionPresentation, resolveVcsTerms } from "~/vcsPresentation";
|
||||||
|
|
||||||
interface GitActionsControlProps {
|
interface GitActionsControlProps {
|
||||||
gitCwd: string | null;
|
gitCwd: string | null;
|
||||||
@@ -343,8 +344,12 @@ export default function GitActionsControl({
|
|||||||
const SourceControlIcon = sourceControlPresentation.Icon;
|
const SourceControlIcon = sourceControlPresentation.Icon;
|
||||||
// Default to true while loading so we don't flash init controls.
|
// Default to true while loading so we don't flash init controls.
|
||||||
const isRepo = gitStatus?.isRepo ?? true;
|
const isRepo = gitStatus?.isRepo ?? true;
|
||||||
|
const vcsKind = gitStatus?.kind ?? null;
|
||||||
|
const vcsTerms = resolveVcsTerms(vcsKind);
|
||||||
|
const vcsActionPresentation = resolveVcsActionPresentation(vcsKind);
|
||||||
|
const supportsGitWorkflowActions = !isRepo || vcsActionPresentation.supportsGitWorkflowActions;
|
||||||
const hasPrimaryRemote = gitStatus?.hasPrimaryRemote ?? false;
|
const hasPrimaryRemote = gitStatus?.hasPrimaryRemote ?? false;
|
||||||
const gitStatusForActions = gitStatus;
|
const gitStatusForActions = supportsGitWorkflowActions ? gitStatus : null;
|
||||||
|
|
||||||
const allFiles = gitStatusForActions?.workingTree.files ?? [];
|
const allFiles = gitStatusForActions?.workingTree.files ?? [];
|
||||||
const selectedFiles = allFiles.filter((f) => !excludedFiles.has(f.path));
|
const selectedFiles = allFiles.filter((f) => !excludedFiles.has(f.path));
|
||||||
@@ -895,6 +900,25 @@ export default function GitActionsControl({
|
|||||||
>
|
>
|
||||||
{initMutation.isPending ? "Initializing..." : "Initialize Git"}
|
{initMutation.isPending ? "Initializing..." : "Initialize Git"}
|
||||||
</Button>
|
</Button>
|
||||||
|
) : !supportsGitWorkflowActions ? (
|
||||||
|
<Popover>
|
||||||
|
<PopoverTrigger
|
||||||
|
openOnHover
|
||||||
|
render={
|
||||||
|
<Button
|
||||||
|
aria-disabled="true"
|
||||||
|
className="cursor-not-allowed opacity-70"
|
||||||
|
size="xs"
|
||||||
|
variant="outline"
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{vcsTerms.systemName} {vcsTerms.repositoryNoun}
|
||||||
|
</PopoverTrigger>
|
||||||
|
<PopoverPopup tooltipStyle side="bottom" align="end">
|
||||||
|
{vcsActionPresentation.unsupportedGitWorkflowDescription}
|
||||||
|
</PopoverPopup>
|
||||||
|
</Popover>
|
||||||
) : (
|
) : (
|
||||||
<Group aria-label="Git actions" className="shrink-0">
|
<Group aria-label="Git actions" className="shrink-0">
|
||||||
{quickActionDisabledReason ? (
|
{quickActionDisabledReason ? (
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ import { Toggle } from "../ui/toggle";
|
|||||||
import { SidebarTrigger } from "../ui/sidebar";
|
import { SidebarTrigger } from "../ui/sidebar";
|
||||||
import { OpenInPicker } from "./OpenInPicker";
|
import { OpenInPicker } from "./OpenInPicker";
|
||||||
import { usePrimaryEnvironmentId } from "../../environments/primary";
|
import { usePrimaryEnvironmentId } from "../../environments/primary";
|
||||||
|
import { resolveVcsTerms } from "../../vcsPresentation";
|
||||||
|
import type { VcsDriverKind } from "@t3tools/contracts";
|
||||||
|
|
||||||
interface ChatHeaderProps {
|
interface ChatHeaderProps {
|
||||||
activeThreadEnvironmentId: EnvironmentId;
|
activeThreadEnvironmentId: EnvironmentId;
|
||||||
@@ -24,7 +26,8 @@ interface ChatHeaderProps {
|
|||||||
draftId?: DraftId;
|
draftId?: DraftId;
|
||||||
activeThreadTitle: string;
|
activeThreadTitle: string;
|
||||||
activeProjectName: string | undefined;
|
activeProjectName: string | undefined;
|
||||||
isGitRepo: boolean;
|
isVcsRepo: boolean;
|
||||||
|
vcsKind: VcsDriverKind | null;
|
||||||
openInCwd: string | null;
|
openInCwd: string | null;
|
||||||
activeProjectScripts: ProjectScript[] | undefined;
|
activeProjectScripts: ProjectScript[] | undefined;
|
||||||
preferredScriptId: string | null;
|
preferredScriptId: string | null;
|
||||||
@@ -50,7 +53,8 @@ export const ChatHeader = memo(function ChatHeader({
|
|||||||
draftId,
|
draftId,
|
||||||
activeThreadTitle,
|
activeThreadTitle,
|
||||||
activeProjectName,
|
activeProjectName,
|
||||||
isGitRepo,
|
isVcsRepo,
|
||||||
|
vcsKind,
|
||||||
openInCwd,
|
openInCwd,
|
||||||
activeProjectScripts,
|
activeProjectScripts,
|
||||||
preferredScriptId,
|
preferredScriptId,
|
||||||
@@ -72,6 +76,7 @@ export const ChatHeader = memo(function ChatHeader({
|
|||||||
const primaryEnvironmentId = usePrimaryEnvironmentId();
|
const primaryEnvironmentId = usePrimaryEnvironmentId();
|
||||||
const isRemoteEnvironment =
|
const isRemoteEnvironment =
|
||||||
primaryEnvironmentId !== null && activeThreadEnvironmentId !== primaryEnvironmentId;
|
primaryEnvironmentId !== null && activeThreadEnvironmentId !== primaryEnvironmentId;
|
||||||
|
const vcsTerms = resolveVcsTerms(vcsKind);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="@container/header-actions flex min-w-0 flex-1 items-center gap-2">
|
<div className="@container/header-actions flex min-w-0 flex-1 items-center gap-2">
|
||||||
@@ -88,9 +93,9 @@ export const ChatHeader = memo(function ChatHeader({
|
|||||||
<span className="min-w-0 truncate">{activeProjectName}</span>
|
<span className="min-w-0 truncate">{activeProjectName}</span>
|
||||||
</Badge>
|
</Badge>
|
||||||
)}
|
)}
|
||||||
{activeProjectName && !isGitRepo && (
|
{activeProjectName && !isVcsRepo && (
|
||||||
<Badge variant="outline" className="shrink-0 text-[10px] text-amber-700">
|
<Badge variant="outline" className="shrink-0 text-[10px] text-amber-700">
|
||||||
No Git
|
No repository
|
||||||
</Badge>
|
</Badge>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
@@ -154,15 +159,15 @@ export const ChatHeader = memo(function ChatHeader({
|
|||||||
aria-label="Toggle diff panel"
|
aria-label="Toggle diff panel"
|
||||||
variant="outline"
|
variant="outline"
|
||||||
size="xs"
|
size="xs"
|
||||||
disabled={!isGitRepo && !diffOpen}
|
disabled={!isVcsRepo && !diffOpen}
|
||||||
>
|
>
|
||||||
<DiffIcon className="size-3" />
|
<DiffIcon className="size-3" />
|
||||||
</Toggle>
|
</Toggle>
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
<TooltipPopup side="bottom">
|
<TooltipPopup side="bottom">
|
||||||
{!isGitRepo && !diffOpen
|
{!isVcsRepo && !diffOpen
|
||||||
? "Diff panel is unavailable because this project is not a git repository."
|
? `Diff panel is unavailable because this project is not a supported ${vcsTerms.repositoryNoun}.`
|
||||||
: diffToggleShortcutLabel
|
: diffToggleShortcutLabel
|
||||||
? `Toggle diff panel (${diffToggleShortcutLabel})`
|
? `Toggle diff panel (${diffToggleShortcutLabel})`
|
||||||
: "Toggle diff panel"}
|
: "Toggle diff panel"}
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ const TARGET = { environmentId: ENVIRONMENT_ID, cwd: "/repo" } as const;
|
|||||||
const FRESH_TARGET = { environmentId: ENVIRONMENT_ID, cwd: "/fresh" } as const;
|
const FRESH_TARGET = { environmentId: ENVIRONMENT_ID, cwd: "/fresh" } as const;
|
||||||
|
|
||||||
const BASE_STATUS: VcsStatusResult = {
|
const BASE_STATUS: VcsStatusResult = {
|
||||||
|
kind: "git",
|
||||||
isRepo: true,
|
isRepo: true,
|
||||||
hasPrimaryRemote: true,
|
hasPrimaryRemote: true,
|
||||||
isDefaultRef: false,
|
isDefaultRef: false,
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ function normalizeCheckpointErrorMessage(error: unknown): string {
|
|||||||
|
|
||||||
const lower = message.toLowerCase();
|
const lower = message.toLowerCase();
|
||||||
if (lower.includes("not a git repository")) {
|
if (lower.includes("not a git repository")) {
|
||||||
return "Turn diffs are unavailable because this project is not a git repository.";
|
return "Turn diffs are unavailable because this project is not a repository.";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
|
|||||||
@@ -262,6 +262,7 @@ const baseServerConfig: ServerConfig = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const baseGitStatus: VcsStatusResult = {
|
const baseGitStatus: VcsStatusResult = {
|
||||||
|
kind: "git",
|
||||||
isRepo: true,
|
isRepo: true,
|
||||||
hasPrimaryRemote: true,
|
hasPrimaryRemote: true,
|
||||||
isDefaultRef: false,
|
isDefaultRef: false,
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import { createWsRpcClient } from "./wsRpcClient";
|
|||||||
import { type WsTransport } from "./wsTransport";
|
import { type WsTransport } from "./wsTransport";
|
||||||
|
|
||||||
const baseLocalStatus: VcsStatusLocalResult = {
|
const baseLocalStatus: VcsStatusLocalResult = {
|
||||||
|
kind: "git",
|
||||||
isRepo: true,
|
isRepo: true,
|
||||||
hasPrimaryRemote: true,
|
hasPrimaryRemote: true,
|
||||||
isDefaultRef: false,
|
isDefaultRef: false,
|
||||||
|
|||||||
@@ -0,0 +1,60 @@
|
|||||||
|
import type { VcsDriverKind } from "@t3tools/contracts";
|
||||||
|
|
||||||
|
export interface VcsTerms {
|
||||||
|
readonly systemName: string;
|
||||||
|
readonly repositoryNoun: string;
|
||||||
|
readonly refNoun: string;
|
||||||
|
readonly refNounPlural: string;
|
||||||
|
readonly currentRefFallback: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface VcsActionPresentation {
|
||||||
|
readonly supportsGitWorkflowActions: boolean;
|
||||||
|
readonly unsupportedGitWorkflowDescription: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const gitLikeTerms: VcsTerms = {
|
||||||
|
systemName: "Git",
|
||||||
|
repositoryNoun: "repository",
|
||||||
|
refNoun: "branch",
|
||||||
|
refNounPlural: "branches",
|
||||||
|
currentRefFallback: "checkout",
|
||||||
|
};
|
||||||
|
|
||||||
|
const unknownTerms: VcsTerms = {
|
||||||
|
systemName: "VCS",
|
||||||
|
repositoryNoun: "repository",
|
||||||
|
refNoun: "ref",
|
||||||
|
refNounPlural: "refs",
|
||||||
|
currentRefFallback: "checkout",
|
||||||
|
};
|
||||||
|
|
||||||
|
export function resolveVcsTerms(kind: VcsDriverKind | null | undefined): VcsTerms {
|
||||||
|
if (kind === "jj") {
|
||||||
|
return {
|
||||||
|
systemName: "JJ",
|
||||||
|
repositoryNoun: "workspace",
|
||||||
|
refNoun: "bookmark",
|
||||||
|
refNounPlural: "bookmarks",
|
||||||
|
currentRefFallback: "working copy",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (kind === "git") {
|
||||||
|
return gitLikeTerms;
|
||||||
|
}
|
||||||
|
|
||||||
|
return unknownTerms;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function resolveVcsActionPresentation(
|
||||||
|
kind: VcsDriverKind | null | undefined,
|
||||||
|
): VcsActionPresentation {
|
||||||
|
const terms = resolveVcsTerms(kind);
|
||||||
|
const supportsGitWorkflowActions = kind === undefined || kind === null || kind === "git";
|
||||||
|
|
||||||
|
return {
|
||||||
|
supportsGitWorkflowActions,
|
||||||
|
unsupportedGitWorkflowDescription: `Git commit, push, and PR actions are not available for this ${terms.systemName} ${terms.repositoryNoun}.`,
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -196,6 +196,7 @@ const VcsStatusChangeRequest = Schema.Struct({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const VcsStatusLocalShape = {
|
const VcsStatusLocalShape = {
|
||||||
|
kind: VcsDriverKind,
|
||||||
isRepo: Schema.Boolean,
|
isRepo: Schema.Boolean,
|
||||||
sourceControlProvider: Schema.optional(SourceControlProviderInfo),
|
sourceControlProvider: Schema.optional(SourceControlProviderInfo),
|
||||||
hasPrimaryRemote: Schema.Boolean,
|
hasPrimaryRemote: Schema.Boolean,
|
||||||
|
|||||||
@@ -81,6 +81,7 @@ describe("applyGitStatusStreamEvent", () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
expect(applyGitStatusStreamEvent(null, { _tag: "remoteUpdated", remote })).toEqual({
|
expect(applyGitStatusStreamEvent(null, { _tag: "remoteUpdated", remote })).toEqual({
|
||||||
|
kind: "unknown",
|
||||||
isRepo: true,
|
isRepo: true,
|
||||||
hasPrimaryRemote: false,
|
hasPrimaryRemote: false,
|
||||||
isDefaultRef: false,
|
isDefaultRef: false,
|
||||||
@@ -96,6 +97,7 @@ describe("applyGitStatusStreamEvent", () => {
|
|||||||
|
|
||||||
it("preserves local-only fields when applying a remote update", () => {
|
it("preserves local-only fields when applying a remote update", () => {
|
||||||
const current: VcsStatusResult = {
|
const current: VcsStatusResult = {
|
||||||
|
kind: "git",
|
||||||
isRepo: true,
|
isRepo: true,
|
||||||
sourceControlProvider: {
|
sourceControlProvider: {
|
||||||
kind: "github",
|
kind: "github",
|
||||||
|
|||||||
@@ -226,6 +226,7 @@ function toRemoteStatusPart(status: VcsStatusResult): VcsStatusRemoteResult {
|
|||||||
|
|
||||||
function toLocalStatusPart(status: VcsStatusResult): VcsStatusLocalResult {
|
function toLocalStatusPart(status: VcsStatusResult): VcsStatusLocalResult {
|
||||||
return {
|
return {
|
||||||
|
kind: status.kind,
|
||||||
isRepo: status.isRepo,
|
isRepo: status.isRepo,
|
||||||
...(status.sourceControlProvider
|
...(status.sourceControlProvider
|
||||||
? { sourceControlProvider: status.sourceControlProvider }
|
? { sourceControlProvider: status.sourceControlProvider }
|
||||||
@@ -251,6 +252,7 @@ export function applyGitStatusStreamEvent(
|
|||||||
if (current === null) {
|
if (current === null) {
|
||||||
return mergeGitStatusParts(
|
return mergeGitStatusParts(
|
||||||
{
|
{
|
||||||
|
kind: "unknown",
|
||||||
isRepo: true,
|
isRepo: true,
|
||||||
hasPrimaryRemote: false,
|
hasPrimaryRemote: false,
|
||||||
isDefaultRef: false,
|
isDefaultRef: false,
|
||||||
|
|||||||
Reference in new issue
Block a user