workspace forks: fix cli build errors (#6580)

This commit is contained in:
wendrul
2025-09-11 10:55:16 +02:00
committed by GitHub
parent 21602f125f
commit 6121fbb9ae
4 changed files with 24 additions and 53 deletions
+8 -47
View File
@@ -13,33 +13,10 @@ import { tryResolveBranchWorkspace } from "../../core/context.ts";
// Run ./gen_wm_client.sh to regenerate after backend changes
// import * as wmill from "../../../gen/services.gen.ts";
async function runGitCommand(
args: string[],
): Promise<{ success: boolean; output: string }> {
try {
const command = new Deno.Command("git", {
args,
stdout: "piped",
stderr: "piped",
});
const { code, stdout, stderr } = await command.output();
const output = new TextDecoder().decode(code === 0 ? stdout : stderr);
return {
success: code === 0,
output: output.trim(),
};
} catch (error) {
return {
success: false,
output: `Failed to execute git command: ${error.message}`,
};
}
}
async function createWorkspaceFork(
opts: GlobalOptions,
opts: GlobalOptions & {
createWorkspaceName: string | undefined;
},
workspaceName: string | undefined,
workspaceId: string | undefined = undefined,
) {
@@ -56,6 +33,9 @@ async function createWorkspaceFork(
log.info(`You are forking workspace (${workspace.workspaceId})`)
const currentBranch = getCurrentGitBranch()
if (!currentBranch) {
throw new Error("Could not get git branch name");
}
const originalBranchIfForked = getOriginalBranchForWorkspaceForks(currentBranch);
let clonedBranchName: string | null;
@@ -129,7 +109,7 @@ async function createWorkspaceFork(
const result = await wmill.createWorkspaceFork({
requestBody: {
id: trueWorkspaceId,
name: workspaceName,
name: opts.createWorkspaceName ?? trueWorkspaceId,
username: undefined, // Let the server handle username
color: undefined,
parent_workspace_id: workspace.workspaceId,
@@ -221,23 +201,4 @@ async function deleteWorkspaceFork(
await removeWorkspace(name, silent, opts);
}
const forkCommand = new Command()
.description("Create a forked workspace and git branch")
.arguments("[workspace_id:string]")
.option(
"--create-workspace-name <workspace_name:string>",
"Specify the workspace name. Ignored if --create is not specified or the workspace already exists. Will default to the workspace id."
)
.action(async (opts: GlobalOptions, workspace_id: string) => {
await requireLogin(opts);
await createWorkspaceFork(opts, workspace_id, undefined);
});
const deleteForkCommand = new Command()
.description("Delete a forked workspace and git branch")
.arguments("<fork_name:string>")
.action(async (opts: GlobalOptions, name: string, silent: boolean) => {
await deleteWorkspaceFork(opts, silent, name);
});
export { forkCommand, deleteForkCommand };
export { createWorkspaceFork, deleteWorkspaceFork };
+13 -3
View File
@@ -4,7 +4,7 @@ import { getActiveWorkspaceConfigFilePath, getWorkspaceConfigFilePath } from "..
import { loginInteractive, tryGetLoginInfo } from "../../core/login.ts";
import { colors, Command, Confirm, Input, log, setClient, Table } from "../../../deps.ts";
import { requireLogin } from "../../core/auth.ts";
import { forkCommand, deleteForkCommand } from "./fork.ts";
import { createWorkspaceFork, deleteWorkspaceFork } from "./fork.ts";
import * as wmill from "../../../gen/services.gen.ts";
@@ -466,7 +466,17 @@ const command = new Command()
.description("Remove workspace binding from the current Git branch")
.option("--branch <branch:string>", "Specify branch (defaults to current)")
.action((opts) => bind(opts as any, false))
.command("fork", forkCommand)
.command("delete-fork", deleteForkCommand);
.command("fork")
.description("Create a forked workspace")
.arguments("[workspace_name:string] [workspace_id:string]")
.option(
"--create-workspace-name <workspace_name:string>",
"Specify the workspace name. Ignored if --create is not specified or the workspace already exists. Will default to the workspace id."
)
.action(createWorkspaceFork as any)
.command("delete-fork")
.description("Delete a forked workspace and git branch")
.arguments("<fork_name:string>")
.action(deleteWorkspaceFork as any);
export default command;
+1 -1
View File
@@ -397,7 +397,7 @@ export async function validateBranchConfiguration(skipValidation?: boolean, auto
export async function getEffectiveSettings(config: SyncOptions, promotion?: string, skipBranchValidation?: boolean, suppressLogs?: boolean): Promise<SyncOptions> {
// Start with top-level settings from config
const { gitBranches, ...topLevelSettings } = config;
let effective = { ...topLevelSettings };
const effective = { ...topLevelSettings };
if (isGitRepository()) {
const branch = getCurrentGitBranch();
+2 -2
View File
@@ -16,8 +16,8 @@ export function getCurrentGitBranch(): string | null {
}
}
export function getOriginalBranchForWorkspaceForks(branchName: string): string | null {
if (!branchName.startsWith(WM_FORK_PREFIX)) {
export function getOriginalBranchForWorkspaceForks(branchName: string | null): string | null {
if (!branchName || !branchName.startsWith(WM_FORK_PREFIX)) {
return null
}