fix(ui): default worktrees to current branch (#105304)

This commit is contained in:
Peter Steinberger
2026-07-12 11:54:15 +01:00
committed by GitHub
parent 66d9ec535e
commit 04e8aeb784
2 changed files with 31 additions and 3 deletions
@@ -12,8 +12,11 @@ type WorktreesPageTestElement = HTMLElement & {
busyId: string | null;
creating: boolean;
createRepoRoot: string;
createBaseRef: string;
createBranches: string[];
updateComplete: Promise<boolean>;
requestUpdate: () => void;
loadCreateBranches: () => void;
createWorktree: () => Promise<void>;
removeWorktree: (record: WorktreeRecord) => Promise<void>;
restore: (record: WorktreeRecord) => Promise<void>;
@@ -286,4 +289,25 @@ describe("WorktreesPage lifecycle", () => {
expect(page.creating).toBe(false);
expect(page.error).toBeNull();
});
it("uses the current branch when a repository has no remote default", async () => {
const request = vi.fn((method: string) => {
if (method === "worktrees.branches") {
return Promise.resolve({ branches: [{ name: "main" }], headBranch: "main" });
}
return Promise.resolve({ worktrees: [] });
});
const page = document.createElement("openclaw-worktrees-page") as WorktreesPageTestElement;
page.context = contextWithGateway(
gatewayWithClient({ request } as unknown as GatewayBrowserClient),
);
page.createRepoRoot = "/tmp/repo";
document.body.append(page);
await vi.waitFor(() => expect(request).toHaveBeenCalledWith("worktrees.list", {}));
page.loadCreateBranches();
await vi.waitFor(() => expect(page.createBranches).toEqual(["main"]));
expect(page.createBaseRef).toBe("main");
});
});
+7 -3
View File
@@ -15,7 +15,11 @@ import { SubscriptionsController } from "../../lit/subscriptions-controller.ts";
type WorktreesListResult = { worktrees: WorktreeRecord[] };
type WorktreesRemoveResult = { removed: boolean; snapshotError?: string };
type WorktreeBranchesResult = { branches: Array<{ name: string }>; defaultBranch?: string };
type WorktreeBranchesResult = {
branches: Array<{ name: string }>;
defaultBranch?: string;
headBranch?: string;
};
type WorktreeOperationScope = {
gateway: ApplicationContext["gateway"];
@@ -266,8 +270,8 @@ class WorktreesPage extends OpenClawLightDomElement {
.then((result) => {
if (this.isOperationScopeCurrent(scope) && repoRoot === this.createRepoRoot.trim()) {
this.createBranches = result.branches.map((branch) => branch.name);
if (!this.createBaseRef && result.defaultBranch) {
this.createBaseRef = result.defaultBranch;
if (!this.createBaseRef) {
this.createBaseRef = result.defaultBranch ?? result.headBranch ?? "";
}
}
})