-
Notifications
You must be signed in to change notification settings - Fork 963
refactor(desktop): derive v2 base branch from git config #3492
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
Changes from all commits
53f0d97
b33a914
64d342f
92db6aa
bfbe83d
269dc9d
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 |
|---|---|---|
|
|
@@ -24,12 +24,17 @@ export function useChangesTab({ | |
| onSelectFile, | ||
| }: UseChangesTabParams): SidebarTabDefinition { | ||
| const collections = useCollections(); | ||
| const utils = workspaceTrpc.useUtils(); | ||
| const localState = collections.v2WorkspaceLocalState.get(workspaceId); | ||
| const filter: ChangesFilter = localState?.sidebarState?.changesFilter ?? { | ||
| kind: "all", | ||
| }; | ||
| const baseBranch: string | null = | ||
| localState?.sidebarState?.baseBranch ?? null; | ||
|
|
||
| const baseBranchQuery = workspaceTrpc.git.getBaseBranch.useQuery( | ||
| { workspaceId }, | ||
| { staleTime: Number.POSITIVE_INFINITY }, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: Prompt for AI agents |
||
| ); | ||
| const baseBranch = baseBranchQuery.data?.baseBranch ?? null; | ||
|
|
||
| const { viewedSet, setViewed } = useViewedFiles(workspaceId); | ||
|
|
||
|
|
@@ -46,14 +51,20 @@ export function useChangesTab({ | |
| [collections, workspaceId], | ||
| ); | ||
|
|
||
| const setBaseBranchMutation = workspaceTrpc.git.setBaseBranch.useMutation({ | ||
| onSuccess: () => { | ||
| void utils.git.getBaseBranch.invalidate({ workspaceId }); | ||
| void utils.git.getStatus.invalidate({ workspaceId }); | ||
| void utils.git.listCommits.invalidate({ workspaceId }); | ||
| void utils.git.getDiff.invalidate({ workspaceId }); | ||
| }, | ||
| }); | ||
|
|
||
| const setBaseBranch = useCallback( | ||
| (branchName: string) => { | ||
| if (!collections.v2WorkspaceLocalState.get(workspaceId)) return; | ||
| collections.v2WorkspaceLocalState.update(workspaceId, (draft) => { | ||
| draft.sidebarState.baseBranch = branchName; | ||
| }); | ||
| setBaseBranchMutation.mutate({ workspaceId, baseBranch: branchName }); | ||
| }, | ||
| [collections, workspaceId], | ||
| [setBaseBranchMutation, workspaceId], | ||
| ); | ||
|
|
||
| const commits = workspaceTrpc.git.listCommits.useQuery( | ||
|
|
@@ -101,6 +112,7 @@ export function useChangesTab({ | |
| commits={commits} | ||
| branches={branches} | ||
| filter={filter} | ||
| baseBranch={baseBranch} | ||
| files={files} | ||
| isLoading={isLoading} | ||
| totalChanges={totalChanges} | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| import { workspaceTrpc } from "@superset/workspace-client"; | ||
| import { eq } from "@tanstack/db"; | ||
| import { useLiveQuery } from "@tanstack/react-db"; | ||
| import { useMemo } from "react"; | ||
|
|
@@ -15,7 +16,12 @@ export function useSidebarDiffRef(workspaceId: string): DiffRef { | |
| ); | ||
| const sidebarState = rows[0]?.sidebarState; | ||
| const filter = sidebarState?.changesFilter ?? { kind: "all" }; | ||
| const baseBranch = sidebarState?.baseBranch ?? null; | ||
|
|
||
| const baseBranchQuery = workspaceTrpc.git.getBaseBranch.useQuery( | ||
| { workspaceId }, | ||
| { staleTime: Number.POSITIVE_INFINITY }, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: Caching Prompt for AI agents |
||
| ); | ||
| const baseBranch = baseBranchQuery.data?.baseBranch ?? null; | ||
|
|
||
| const filterKind = filter.kind; | ||
| const commitHash = | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -231,6 +231,58 @@ export const gitRouter = router({ | |||||||||||
| return { files }; | ||||||||||||
| }), | ||||||||||||
|
|
||||||||||||
| getBaseBranch: protectedProcedure | ||||||||||||
| .input(z.object({ workspaceId: z.string() })) | ||||||||||||
| .query(async ({ ctx, input }) => { | ||||||||||||
| const worktreePath = resolveWorktreePath(ctx, input.workspaceId); | ||||||||||||
| const git = await ctx.git(worktreePath); | ||||||||||||
| const currentBranch = ( | ||||||||||||
| await git.revparse(["--abbrev-ref", "HEAD"]).catch(() => "") | ||||||||||||
| ).trim(); | ||||||||||||
| if (!currentBranch || currentBranch === "HEAD") { | ||||||||||||
| return { baseBranch: null as string | null }; | ||||||||||||
| } | ||||||||||||
| const configured = ( | ||||||||||||
| await git | ||||||||||||
| .raw(["config", `branch.${currentBranch}.base`]) | ||||||||||||
| .catch(() => "") | ||||||||||||
| ).trim(); | ||||||||||||
| return { baseBranch: (configured || null) as string | null }; | ||||||||||||
| }), | ||||||||||||
|
|
||||||||||||
| setBaseBranch: protectedProcedure | ||||||||||||
| .input( | ||||||||||||
| z.object({ | ||||||||||||
| workspaceId: z.string(), | ||||||||||||
| baseBranch: z.string().nullable(), | ||||||||||||
| }), | ||||||||||||
| ) | ||||||||||||
| .mutation(async ({ ctx, input }) => { | ||||||||||||
| const worktreePath = resolveWorktreePath(ctx, input.workspaceId); | ||||||||||||
| const git = await ctx.git(worktreePath); | ||||||||||||
| const currentBranch = ( | ||||||||||||
| await git.revparse(["--abbrev-ref", "HEAD"]).catch(() => "") | ||||||||||||
| ).trim(); | ||||||||||||
| if (!currentBranch || currentBranch === "HEAD") { | ||||||||||||
| throw new TRPCError({ | ||||||||||||
| code: "PRECONDITION_FAILED", | ||||||||||||
| message: "Cannot set base branch on detached HEAD", | ||||||||||||
| }); | ||||||||||||
| } | ||||||||||||
| if (input.baseBranch) { | ||||||||||||
| await git.raw([ | ||||||||||||
| "config", | ||||||||||||
| `branch.${currentBranch}.base`, | ||||||||||||
| input.baseBranch, | ||||||||||||
| ]); | ||||||||||||
| } else { | ||||||||||||
| await git | ||||||||||||
| .raw(["config", "--unset", `branch.${currentBranch}.base`]) | ||||||||||||
| .catch(() => {}); | ||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: Do not swallow errors when unsetting the base branch config; this can report success even when persistence fails. (Based on your team's feedback about handling async errors explicitly and avoiding silent empty catches.) Prompt for AI agents
Suggested change
|
||||||||||||
| } | ||||||||||||
| return { baseBranch: input.baseBranch }; | ||||||||||||
| }), | ||||||||||||
|
|
||||||||||||
| renameBranch: protectedProcedure | ||||||||||||
| .input( | ||||||||||||
| z.object({ | ||||||||||||
|
|
||||||||||||
Uh oh!
There was an error while loading. Please reload this page.