-
Notifications
You must be signed in to change notification settings - Fork 964
fix(desktop): fix creating workspace and worktree from existing branch #2982
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
vivishko
wants to merge
6
commits into
superset-sh:main
Choose a base branch
from
vivishko:open-workspace-with-existing-branch
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8f2e1d6
fix(desktop): enforce create-from-existing-branch semantics and stabi…
vivishko a39e9e4
fix(desktop): make branch row click select base branch only and keep …
vivishko e81ab47
fix(desktop): restore branch picker keyboard open actions and apply p…
vivishko 7e89300
refactor(desktop): use shared WorkspaceCreateDomainErrorCode in Promp…
vivishko ae0597c
fix(desktop): add Cmd/Ctrl+Enter create-from-branch hotkey and unify …
vivishko 48e905d
fix(desktop): always revoke attachment blob URLs in existing-branch c…
vivishko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
apps/desktop/src/lib/trpc/routers/workspaces/procedures/utils/create-domain-errors.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| import { describe, expect, test } from "bun:test"; | ||
| import { TRPCError } from "@trpc/server"; | ||
| import { | ||
| throwWorkspaceCreateDomainError, | ||
| validateExistingBranchCreate, | ||
| } from "./create-domain-errors"; | ||
|
|
||
| describe("create-domain-errors", () => { | ||
| test("throws BRANCH_NOT_FOUND when branch is missing", () => { | ||
| expect(() => | ||
| validateExistingBranchCreate({ | ||
| branchName: "feature/missing", | ||
| existingBranches: ["main", "develop"], | ||
| existingWorktreePath: null, | ||
| }), | ||
| ).toThrow('BRANCH_NOT_FOUND: Branch "feature/missing" no longer exists.'); | ||
| }); | ||
|
|
||
| test("throws WORKTREE_ALREADY_EXISTS_FOR_BRANCH when worktree exists", () => { | ||
| expect(() => | ||
| validateExistingBranchCreate({ | ||
| branchName: "feature/existing", | ||
| existingBranches: ["main", "feature/existing"], | ||
| existingWorktreePath: "/tmp/worktrees/feature-existing", | ||
| }), | ||
| ).toThrow( | ||
| 'WORKTREE_ALREADY_EXISTS_FOR_BRANCH: Branch "feature/existing" is already checked out in another worktree.', | ||
| ); | ||
| }); | ||
|
|
||
| test("passes when branch exists and no worktree exists", () => { | ||
| expect(() => | ||
| validateExistingBranchCreate({ | ||
| branchName: "feature/new", | ||
| existingBranches: ["main", "feature/new"], | ||
| existingWorktreePath: null, | ||
| }), | ||
| ).not.toThrow(); | ||
| }); | ||
|
|
||
| test("throws with provided tRPC code", () => { | ||
| try { | ||
| throwWorkspaceCreateDomainError( | ||
| "GIT_OPERATION_FAILED", | ||
| "Unable to list branches.", | ||
| "INTERNAL_SERVER_ERROR", | ||
| ); | ||
| throw new Error("Expected TRPCError"); | ||
| } catch (error) { | ||
| expect(error).toBeInstanceOf(TRPCError); | ||
| expect((error as TRPCError).code).toBe("INTERNAL_SERVER_ERROR"); | ||
| expect((error as TRPCError).message).toBe( | ||
| "GIT_OPERATION_FAILED: Unable to list branches.", | ||
| ); | ||
| } | ||
| }); | ||
| }); |
42 changes: 42 additions & 0 deletions
42
apps/desktop/src/lib/trpc/routers/workspaces/procedures/utils/create-domain-errors.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| import { TRPCError } from "@trpc/server"; | ||
|
|
||
| export type WorkspaceCreateDomainErrorCode = | ||
| | "WORKTREE_ALREADY_EXISTS_FOR_BRANCH" | ||
| | "BRANCH_NOT_FOUND" | ||
| | "GIT_OPERATION_FAILED"; | ||
|
|
||
| export function throwWorkspaceCreateDomainError( | ||
| code: WorkspaceCreateDomainErrorCode, | ||
| message: string, | ||
| trpcCode: TRPCError["code"] = "BAD_REQUEST", | ||
| ): never { | ||
| console.warn("[workspaces/create] Domain error", { code, message }); | ||
| throw new TRPCError({ | ||
| code: trpcCode, | ||
| message: `${code}: ${message}`, | ||
| }); | ||
| } | ||
|
|
||
| export function validateExistingBranchCreate({ | ||
| branchName, | ||
| existingBranches, | ||
| existingWorktreePath, | ||
| }: { | ||
| branchName: string; | ||
| existingBranches: string[]; | ||
| existingWorktreePath: string | null; | ||
| }): void { | ||
| if (!existingBranches.includes(branchName)) { | ||
| throwWorkspaceCreateDomainError( | ||
| "BRANCH_NOT_FOUND", | ||
| `Branch "${branchName}" no longer exists.`, | ||
| ); | ||
| } | ||
|
|
||
| if (existingWorktreePath) { | ||
| throwWorkspaceCreateDomainError( | ||
| "WORKTREE_ALREADY_EXISTS_FOR_BRANCH", | ||
| `Branch "${branchName}" is already checked out in another worktree.`, | ||
| ); | ||
| } | ||
| } |
16 changes: 16 additions & 0 deletions
16
apps/desktop/src/lib/trpc/routers/workspaces/utils/default-worktree-base-dir.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| import { describe, expect, test } from "bun:test"; | ||
| import path from "node:path"; | ||
| import { getDefaultWorktreeBaseDir } from "./default-worktree-base-dir"; | ||
|
|
||
| describe("getDefaultWorktreeBaseDir", () => { | ||
| test("uses stable ~/.superset/worktrees default base dir", () => { | ||
| expect(getDefaultWorktreeBaseDir("/Users/tester")).toBe( | ||
| path.join("/Users/tester", ".superset", "worktrees"), | ||
| ); | ||
| }); | ||
|
|
||
| test("does not include workspace-name-scoped suffix", () => { | ||
| const baseDir = getDefaultWorktreeBaseDir("/Users/tester"); | ||
| expect(baseDir.includes(".superset-open-workspace")).toBe(false); | ||
| }); | ||
| }); | ||
10 changes: 10 additions & 0 deletions
10
apps/desktop/src/lib/trpc/routers/workspaces/utils/default-worktree-base-dir.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| import { homedir } from "node:os"; | ||
| import { join } from "node:path"; | ||
| import { | ||
| PROJECT_SUPERSET_DIR_NAME, | ||
| WORKTREES_DIR_NAME, | ||
| } from "shared/constants"; | ||
|
|
||
| export function getDefaultWorktreeBaseDir(homeDirectory = homedir()): string { | ||
| return join(homeDirectory, PROJECT_SUPERSET_DIR_NAME, WORKTREES_DIR_NAME); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.