-
Notifications
You must be signed in to change notification settings - Fork 47
Fix: show deleted worktree, related to issue 945 #980
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
base: main
Are you sure you want to change the base?
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,11 @@ | ||
| import { parseGitOriginUrl } from "@getpochi/common/git-utils"; | ||
| import { Schema, queryDb, sql } from "@livestore/livestore"; | ||
| import { tables } from "./default-schema"; | ||
|
|
||
| export const makeTasksQuery = (cwd: string) => | ||
| queryDb( | ||
| { | ||
| query: sql`select * from tasks where parentId is null and (cwd = '${cwd}' or git->>'$.worktree.gitdir' like '${cwd}/.git/worktrees%') order by updatedAt desc`, | ||
| query: sql`select * from tasks where parentId is null and (cwd = '${cwd}' or git->>'$.worktree.gitdir' = '${cwd}') order by updatedAt desc`, | ||
| schema: Schema.Array(tables.tasks.rowSchema), | ||
| }, | ||
| { | ||
|
|
@@ -21,7 +22,7 @@ export const makeTasksQuery = (cwd: string) => | |
| export const makeTasksWithLimitQuery = (cwd: string, limit: number) => { | ||
| return queryDb( | ||
| { | ||
| query: sql`select * from tasks where parentId is null and cwd = '${cwd}' order by updatedAt desc limit ${limit}`, | ||
| query: sql`select * from tasks where parentId is null and (cwd = '${cwd}' or git->>'$.worktree.gitdir' = '${cwd}') order by updatedAt desc limit ${limit}`, | ||
| schema: Schema.Array(tables.tasks.rowSchema), | ||
| }, | ||
| { | ||
|
|
@@ -38,7 +39,7 @@ export const makeTasksWithLimitQuery = (cwd: string, limit: number) => { | |
| export const makeTasksCountQuery = (cwd: string) => { | ||
| return queryDb( | ||
| { | ||
| query: sql`select COUNT(*) as count from tasks where parentId is null and cwd = '${cwd}'`, | ||
| query: sql`select COUNT(*) as count from tasks where parentId is null and (cwd = '${cwd}' or git->>'$.worktree.gitdir' = '${cwd}')`, | ||
| schema: Schema.Array(Schema.Struct({ count: Schema.Number })), | ||
| }, | ||
| { | ||
|
|
@@ -47,3 +48,26 @@ export const makeTasksCountQuery = (cwd: string) => { | |
| }, | ||
| ); | ||
| }; | ||
|
|
||
| export const makeNonCwdWorktreesQuery = (cwd: string, origin?: string) => { | ||
| const originFilter = origin | ||
| ? `and git->>'$.origin' = '${parseGitOriginUrl(origin)?.webUrl}'` | ||
| : ""; | ||
|
|
||
| return queryDb( | ||
| { | ||
| query: sql`select distinct git->>'$.worktree.gitdir' as path, git->>'$.branch' as branch, cwd from tasks where parentId is null and cwd != '${cwd}' ${originFilter} and git->>'$.worktree.gitdir' is not null`, | ||
|
||
| schema: Schema.Array( | ||
| Schema.Struct({ | ||
| path: Schema.String, | ||
| branch: Schema.String, | ||
| cwd: Schema.String, | ||
| }), | ||
| ), | ||
| }, | ||
| { | ||
| label: "tasks.cwd.worktrees", | ||
| deps: [cwd, origin], | ||
| }, | ||
| ); | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import { taskCatalog } from "@getpochi/livekit"; | ||
| import { useStore } from "@livestore/react"; | ||
| import { useMemo } from "react"; | ||
|
|
||
| interface DeletedWorktreesOptions { | ||
| cwd: string; | ||
| origin?: string | null; | ||
| activeWorktrees?: { path: string }[]; | ||
| } | ||
| export function useDeletedWorktrees({ | ||
| cwd, | ||
| origin, | ||
| activeWorktrees, | ||
| }: DeletedWorktreesOptions) { | ||
| const { store } = useStore(); | ||
|
|
||
| const worktreeQuery = useMemo(() => { | ||
| return taskCatalog.queries.makeNonCwdWorktreesQuery(cwd, origin ?? ""); | ||
| }, [cwd, origin]); | ||
| const worktrees = store.useQuery(worktreeQuery); | ||
| const deletedWorktrees = useMemo( | ||
| () => | ||
| worktrees.filter( | ||
| (wt) => !activeWorktrees?.some((active) => active.path === wt.path), | ||
|
||
| ), | ||
| [worktrees, activeWorktrees], | ||
| ); | ||
| return { deletedWorktrees }; | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Revert, querying only with the cwd is sufficient
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@liangfung briefly, to reproduce this bug, you can : let's say your current workspace=xx/main, then create worktree(eg: br-1) with vscode, and DO NOT switch to this worktree; then, hover on the worktree label on Pochi's panel, click the revealed menu btn "create task" on the worktree, hence, the new task was created with : cwd = current workspace(xx/main), and git.worktree.gitdir = xx/br-1, later you can delete the worktree br-1.
so that when you fetch deleted tasks, query by cwd= xx/br-1 won't get the task.