cli/workspace: Expose Jujutsu checkout actions
Route `paseo workspace jj` through the daemon for describe, new, fetch, bookmark publication and pull request creation. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
1b4905f32c
commit
cac41e8889
2 files changed
+82
No files matched your search
@@ -5,6 +5,7 @@ import { runArchiveCommand } from "./archive.js";
|
||||
import { runCreateCommand } from "./create.js";
|
||||
import { runLsCommand } from "./ls.js";
|
||||
import { runRenameCommand } from "./rename.js";
|
||||
import { createJujutsuCommand } from "./jujutsu.js";
|
||||
import { runSetupCommand } from "./setup.js";
|
||||
|
||||
export function createWorkspaceCommand(): Command {
|
||||
@@ -65,5 +66,6 @@ export function createWorkspaceCommand(): Command {
|
||||
.argument("<workspace-id>", "Workspace id"),
|
||||
).action(withOutput(runArchiveCommand));
|
||||
|
||||
workspace.addCommand(createJujutsuCommand());
|
||||
return workspace;
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
import { Argument, Command } from "commander";
|
||||
import { JujutsuCheckoutActionSchema } from "@getpaseo/protocol/messages";
|
||||
import {
|
||||
withOutput,
|
||||
type CommandOptions,
|
||||
type OutputSchema,
|
||||
type SingleResult,
|
||||
} from "../../output/index.js";
|
||||
import { connectToDaemon } from "../../utils/client.js";
|
||||
import { addJsonAndDaemonHostOptions } from "../../utils/command-options.js";
|
||||
import { resolveRepositoryDirectory } from "../worktree/repository-directory.js";
|
||||
|
||||
interface JujutsuCommandOptions extends CommandOptions {
|
||||
path?: string;
|
||||
description?: string;
|
||||
bookmark?: string;
|
||||
remote?: string;
|
||||
base?: string;
|
||||
title?: string;
|
||||
body?: string;
|
||||
create?: boolean;
|
||||
parent?: string;
|
||||
}
|
||||
|
||||
const outputSchema: OutputSchema<{ action: string; url: string | null }> = {
|
||||
idField: "action",
|
||||
columns: [
|
||||
{ header: "ACTION", field: "action" },
|
||||
{ header: "URL", field: "url" },
|
||||
],
|
||||
};
|
||||
|
||||
export function createJujutsuCommand(): Command {
|
||||
return addJsonAndDaemonHostOptions(
|
||||
new Command("jj")
|
||||
.description("Run a Jujutsu checkout action")
|
||||
.addArgument(
|
||||
new Argument("<action>").choices([
|
||||
"describe",
|
||||
"new",
|
||||
"fetch",
|
||||
"publish",
|
||||
"create-pull-request",
|
||||
]),
|
||||
)
|
||||
.option("--path <path>", "Checkout directory (default: current directory)")
|
||||
.option("--description <text>", "Change description for describe or new")
|
||||
.option("--parent <bookmark-or-change>", "Start new on this instead of the current change")
|
||||
.option("--bookmark <name>", "Head bookmark for publish or create-pull-request")
|
||||
.option("--create", "Create the bookmark at the current change before publishing")
|
||||
.option("--remote <name>", "Remote for fetch or publish")
|
||||
.option("--base <name>", "Base bookmark for create-pull-request")
|
||||
.option("--title <text>", "Pull request title")
|
||||
.option("--body <text>", "Pull request body"),
|
||||
).action(withOutput(runJujutsuCommand));
|
||||
}
|
||||
|
||||
async function runJujutsuCommand(
|
||||
name: string,
|
||||
options: JujutsuCommandOptions,
|
||||
_command: Command,
|
||||
): Promise<SingleResult<{ action: string; url: string | null }>> {
|
||||
const action = JujutsuCheckoutActionSchema.parse({
|
||||
...options,
|
||||
kind: name === "create-pull-request" ? "create_pull_request" : name,
|
||||
});
|
||||
const target = options.daemonTarget;
|
||||
const cwd = resolveRepositoryDirectory({ cwd: options.path, daemonTarget: target });
|
||||
const client = await connectToDaemon({ target });
|
||||
try {
|
||||
const status = await client.getCheckoutStatus(cwd);
|
||||
if (status.error) throw new Error(status.error.message);
|
||||
if (!status.jujutsu) throw new Error("The selected checkout does not use Jujutsu.");
|
||||
const response = await client.checkoutJujutsuAction(cwd, status.jujutsu.changeId, action);
|
||||
if (response.error) throw new Error(response.error.message);
|
||||
return { type: "single", data: { action: name, url: response.url }, schema: outputSchema };
|
||||
} finally {
|
||||
await client.close().catch(() => undefined);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user