From fa3cb4c5366760e2dbc8a8101115eb32eaceed8e Mon Sep 17 00:00:00 2001 From: hugocasa Date: Thu, 11 Jun 2026 12:18:46 +0200 Subject: [PATCH] fix(cli): refuse fork --from-branch rename of a base branch Co-Authored-By: Claude Opus 4.8 (1M context) --- cli/src/commands/workspace/fork.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/cli/src/commands/workspace/fork.ts b/cli/src/commands/workspace/fork.ts index d058192022..e08177db6c 100644 --- a/cli/src/commands/workspace/fork.ts +++ b/cli/src/commands/workspace/fork.ts @@ -51,6 +51,23 @@ async function createWorkspaceFork( ); } const config = await readConfigFile({ warnIfMissing: false }); + // Protect base branches. This workflow renames the *current* branch onto + // the fork branch, so refuse when the current branch is itself a base + // branch — either mapped to a workspace in wmill.yaml, or a conventional + // default (main/master). Renaming one of those would clobber it; the user + // must check out a disposable working branch first. Fail fast, before any + // fork workspace or git branch is created. + const currentBranchIsBase = + currentBranch === "main" || + currentBranch === "master" || + findWorkspaceByGitBranch(config.workspaces, currentBranch) !== undefined; + if (currentBranchIsBase) { + throw new Error( + `Refusing to rename your current branch \`${currentBranch}\` — it looks like a base branch (mapped to a workspace in wmill.yaml, or main/master). ` + + `The --from-branch workflow turns a *disposable working branch* into the fork branch. ` + + `Check out the working branch you want to convert first, or omit --from-branch to create a fresh fork branch with \`git checkout -b\`.`, + ); + } const match = findWorkspaceByGitBranch(config.workspaces, fromBranch); if (!match) { throw new Error(