Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

new-task-context-presentation.ts

83 lines2.3 KB

1type WorkspaceMode = "local" | "worktree";
2​
3export function resolveNewTaskWorkspaceLabel(input: {
4 readonly workspaceMode: WorkspaceMode;
5 readonly worktreePath: string | null;
6}): "Current checkout" | "Current worktree" | "New worktree" {
7 if (input.workspaceMode === "worktree") {
8 return "New worktree";
9 }
10 return input.worktreePath ? "Current worktree" : "Current checkout";
12​
13export function resolveNewTaskBranchWorktreePath(input: {
14 readonly workspaceMode: WorkspaceMode;
15 readonly projectCwd: string;
16 readonly branchWorktreePath: string | null | undefined;
17}): string | null {
18 if (
19 input.workspaceMode === "worktree" ||
20 !input.branchWorktreePath ||
21 input.branchWorktreePath === input.projectCwd
22 ) {
23 return null;
24 }
25 return input.branchWorktreePath;
27​
28export function resolveNewTaskLocalWorkspaceSelection(input: {
29 readonly branches: ReadonlyArray<{
30 readonly name: string;
31 readonly current: boolean;
32 readonly worktreePath?: string | null;
33 }>;
34 readonly projectCwd: string;
35}): {
36 readonly branch: string | null;
37 readonly worktreePath: string | null;
38 readonly awaitsCurrentBranch: boolean;
39} {
40 const currentBranch = input.branches.find((branch) => branch.current) ?? null;
41 if (!currentBranch) {
42 return {
43 branch: null,
44 worktreePath: null,
45 awaitsCurrentBranch: true,
46 };
47 }
48​
49 return {
50 branch: currentBranch.name,
51 worktreePath: resolveNewTaskBranchWorktreePath({
52 workspaceMode: "local",
53 projectCwd: input.projectCwd,
54 branchWorktreePath: currentBranch.worktreePath,
55 }),
56 awaitsCurrentBranch: false,
57 };
59​
60export function resolveNewTaskBranchLabel(input: {
61 readonly branchName: string | null;
62 readonly startFromOrigin: boolean;
63 readonly workspaceMode: WorkspaceMode;
64}): string {
65 if (!input.branchName) {
66 return "Choose branch";
67 }
68​
69 if (input.workspaceMode === "local") {
70 return input.branchName;
71 }
72​
73 const baseRef = input.startFromOrigin ? `origin/${input.branchName}` : input.branchName;
74 return `From ${baseRef}`;
76​
77export function shouldCheckoutNewTaskBranch(input: {
78 readonly branchIsCurrent: boolean;
79 readonly branchWorktreePath: string | null | undefined;
80 readonly workspaceMode: WorkspaceMode;
81}): boolean {
82 return input.workspaceMode === "local" && !input.branchIsCurrent && !input.branchWorktreePath;