Add JJ VCS driver support
- Detect and route jj repositories alongside git - Thread VCS kind through status and UI labels - Add jj driver contract coverage and shared freshness helper
This commit is contained in:
1 parent
0ce7e56e43
commit
1a5be6cc2b
30 files changed
+836
-86
No files matched your search
@@ -724,6 +724,7 @@ export const makeGitManager = Effect.fn("makeGitManager")(function* () {
|
||||
: null;
|
||||
|
||||
return {
|
||||
kind: details.isRepo ? ("git" as const) : ("unknown" as const),
|
||||
isRepo: details.isRepo,
|
||||
...(hostingProvider ? { sourceControlProvider: hostingProvider } : {}),
|
||||
hasPrimaryRemote: details.hasOriginRemote,
|
||||
|
||||
@@ -3,6 +3,7 @@ import { Context, Effect, Layer } from "effect";
|
||||
import {
|
||||
GitManagerError,
|
||||
GitCommandError,
|
||||
type VcsDriverKind,
|
||||
type VcsSwitchRefInput,
|
||||
type VcsSwitchRefResult,
|
||||
type VcsCreateRefInput,
|
||||
@@ -29,6 +30,7 @@ import {
|
||||
import { GitManager, type GitRunStackedActionOptions } from "./GitManager.ts";
|
||||
import { GitVcsDriver } from "../vcs/GitVcsDriver.ts";
|
||||
import { VcsDriverRegistry } from "../vcs/VcsDriverRegistry.ts";
|
||||
import { mergeGitStatusParts } from "@t3tools/shared/git";
|
||||
|
||||
export interface GitWorkflowServiceShape {
|
||||
readonly status: (
|
||||
@@ -91,31 +93,7 @@ const unsupportedGitCommand = (operation: string, cwd: string, detail: string) =
|
||||
detail,
|
||||
});
|
||||
|
||||
function nonRepositoryLocalStatus(): VcsStatusLocalResult {
|
||||
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,
|
||||
aheadOfDefaultCount: 0,
|
||||
pr: null,
|
||||
};
|
||||
}
|
||||
const emptyWorkingTree = { files: [], insertions: 0, deletions: 0 } as const;
|
||||
|
||||
function nonRepositoryListRefs(): VcsListRefsResult {
|
||||
return {
|
||||
@@ -127,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* () {
|
||||
const registry = yield* VcsDriverRegistry;
|
||||
const git = yield* GitVcsDriver;
|
||||
@@ -242,27 +230,60 @@ export const make = Effect.fn("makeGitWorkflowService")(function* () {
|
||||
(input: 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({
|
||||
status: (input) =>
|
||||
detectGitRepositoryForStatus("GitWorkflowService.status", input.cwd).pipe(
|
||||
Effect.flatMap((isGitRepository) =>
|
||||
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),
|
||||
),
|
||||
),
|
||||
status,
|
||||
localStatus,
|
||||
remoteStatus,
|
||||
invalidateLocalStatus: gitManager.invalidateLocalStatus,
|
||||
invalidateRemoteStatus: gitManager.invalidateRemoteStatus,
|
||||
invalidateStatus: gitManager.invalidateStatus,
|
||||
|
||||
Reference in new issue
Block a user