Add jujutsu (jj) VCS support #1796
Closedgergesh(GitHub profile, opens in a new tab)wants to merge 2 commits into
main fromrefs/pull/1796/headopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelssize:XXL
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
- @@ -0,0 +1233,21 @@1233+ (bookmark) =>1234+ ({1235+ name: `${bookmark.remoteName}/${bookmark.name}`,1236+ current: false,1237+ isRemote: true,1238+ remoteName: bookmark.remoteName ?? undefined,1239+ isDefault: bookmark.name === defaultBranch,1240+ worktreePath: null,1241+ }) satisfies GitBranch,1242+ )1243+ .toSorted((left, right) => left.name.localeCompare(right.name));1244+1245+ const registryCurrentPath = currentStatus.branch1246+ ? (registry.branches[currentStatus.branch] ?? null)1247+ : null;1248+ const adjustedLocalBranches: GitBranch[] = localBranches.map((branch) => {1249+ const worktreePath =1250+ branch.name === currentStatus.branch1251+ ? workspaceRoot1252+ : (branch.worktreePath ??1253+ (branch.name === currentStatus.branch ? registryCurrentPath : null));@@ -586,4 +586,4 @@586586 }).pipe(Effect.catch(() => Effect.void));587587 return;588588 }589- if (!isGitWorkspace(sessionRuntime.value.cwd)) {589+ if (!isVersionControlledWorkspace(sessionRuntime.value.cwd)) {
- @@ -0,0 +36,21 @@36+ GitCore37+> {38+ return Effect.gen(function* () {39+ const gitCore = yield* GitCore;40+ return yield* gitCore.execute({41+ operation: "JjTestUtils.runGit",42+ cwd,43+ args,44+ allowNonZeroExit,45+ timeoutMs: 30_000,46+ });47+ });48+}49+50+export function runJj(51+ cwd: string,52+ args: readonly string[],53+ allowNonZeroExit = false,54+): Effect.Effect<ProcessRunResult, Error> {55+ return Effect.promise(() =>56+ runProcess("jj", args, {@@ -0,0 +51,21 @@51+}52+53+function truncateOutput(54+ value: string,55+ maxOutputBytes: number,56+): { text: string; truncated: boolean } {57+ const byteLength = Buffer.byteLength(value);58+ if (byteLength <= maxOutputBytes) {59+ return { text: value, truncated: false };60+ }61+62+ let text = value;63+ while (Buffer.byteLength(text) > maxOutputBytes) {64+ text = text.slice(0, Math.max(0, Math.floor(text.length * 0.9)));65+ }66+67+ return {68+ text: `${text}${OUTPUT_TRUNCATED_MARKER}`,69+ truncated: true,70+ };71+}@@ -0,0 +874,21 @@874+ branchStep = featureBranchResult.branchStep;875+ commitMessageForStep = featureBranchResult.resolvedCommitMessage;876+ preResolvedCommitSuggestion = featureBranchResult.resolvedCommitSuggestion;877+ } else {878+ branchStep = { status: "skipped_not_requested" as const };879+ }880+881+ const currentBranch = branchStep.name ?? initialStatus.branch;882+883+ const commit = wantsCommit884+ ? yield* Effect.gen(function* () {885+ yield* Ref.set(currentPhase, "commit");886+ return yield* runCommitStep(887+ modelSelection,888+ input.cwd,889+ currentBranch,890+ commitMessageForStep,891+ preResolvedCommitSuggestion,892+ input.filePaths,893+ );894+ })@@ -0,0 +281,21 @@281+ args: ["root"],282+ detail: error.detail,283+ cause: error,284+ }),285+ ),286+ );287+288+export const resolveJjRepoDir = (cwd: string) =>289+ resolveJjRoot(cwd).pipe(290+ Effect.flatMap((workspaceRoot) =>291+ Effect.tryPromise({292+ try: async () => {293+ const repoPointerPath = path.join(workspaceRoot, ".jj", "repo");294+ try {295+ const repoPointerStats = await fsPromises.stat(repoPointerPath);296+ if (repoPointerStats.isFile()) {297+ const repoDir = (await fsPromises.readFile(repoPointerPath, "utf8")).trim();298+ if (repoDir.length > 0) {299+ return repoDir;300+ }301+ }
- @@ -25,0 +121,21 @@121+ * format (`commitId`).122+ */123+ const resolveJjCheckpointCommit = (124+ cwd: string,125+ checkpointRef: CheckpointRef,126+ ): Effect.Effect<string | null, GitCommandError> =>127+ resolveJjCheckpointPath(cwd, checkpointRef).pipe(128+ Effect.flatMap((checkpointPath) => fs.readFileString(checkpointPath)),129+ Effect.map((raw) => JSON.parse(raw) as JjCheckpointPayload),130+ Effect.flatMap((payload) => {131+ // New format: resolve commit from the operation ID.132+ if (typeof payload.operationId === "string" && payload.operationId.trim().length > 0) {133+ return readJjCommitIdAtOp(cwd, payload.operationId.trim());134+ }135+ // Legacy format: commit ID stored directly.136+ if (typeof payload.commitId === "string" && payload.commitId.trim().length > 0) {137+ return Effect.succeed(payload.commitId.trim());138+ }139+ return Effect.succeed(null);140+ }),141+ Effect.catch(() => Effect.succeed(null)),@@ -0,0 +1,14 @@1+import { Effect, Layer } from "effect";2+3+import { GitCore } from "../../git/Services/GitCore.ts";4+import { JjCore } from "../../jj/Services/JjCore.ts";5+import { VcsCore, type VcsCoreShape } from "../Services/VcsCore.ts";6+import { detectRepoKind } from "../Utils.ts";7+8+export const VcsCoreLive = Layer.effect(9+ VcsCore,10+ Effect.gen(function* () {11+ const gitCore = yield* GitCore;12+ const jjCore = yield* JjCore;13+14+ const selectCore = (cwd: string) => (detectRepoKind(cwd) === "jj" ? jjCore : gitCore);
- @@ -0,0 +1247,21 @@1247+ return left.name.localeCompare(right.name);1248+ });1249+1250+ const remoteBranches: GitBranch[] = bookmarkState.remoteBookmarks1251+ .map(1252+ (bookmark) =>1253+ ({1254+ name: `${bookmark.remoteName}/${bookmark.name}`,1255+ current: false,1256+ isRemote: true,1257+ remoteName: bookmark.remoteName ?? undefined,1258+ isDefault: bookmark.name === defaultBranch,1259+ worktreePath: null,1260+ }) satisfies GitBranch,1261+ )1262+ .toSorted((left, right) => left.name.localeCompare(right.name));1263+1264+ const registryCurrentPath = currentStatus.branch1265+ ? (registry.branches[currentStatus.branch] ?? null)1266+ : null;1267+ const adjustedLocalBranches: GitBranch[] = localBranches.map((branch) => {
juliusmarminge closed this
Sign in to join this conversation.


Important
Review skipped#
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID:
b51c049b-0708-438a-9f3b-63976ef978bcYou can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share