| ... | @@ -13,6 +13,16 @@ export const gitQueryKeys = { | ... | @@ -13,6 +13,16 @@ export const gitQueryKeys = { |
| 13 | branches: (cwd: string | null) => ["git", "branches", cwd] as const, | 13 | branches: (cwd: string | null) => ["git", "branches", cwd] as const, |
| 14 | }; | 14 | }; |
| 15 | | 15 | |
| | 16 | export const gitMutationKeys = { |
| | 17 | init: (cwd: string | null) => ["git", "mutation", "init", cwd] as const, |
| | 18 | checkout: (cwd: string | null) => ["git", "mutation", "checkout", cwd] as const, |
| | 19 | createBranchAndCheckout: (cwd: string | null) => |
| | 20 | ["git", "mutation", "create-branch-and-checkout", cwd] as const, |
| | 21 | runStackedAction: (cwd: string | null) => |
| | 22 | ["git", "mutation", "run-stacked-action", cwd] as const, |
| | 23 | pull: (cwd: string | null) => ["git", "mutation", "pull", cwd] as const, |
| | 24 | }; |
| | 25 | |
| 16 | export function invalidateGitQueries(queryClient: QueryClient) { | 26 | export function invalidateGitQueries(queryClient: QueryClient) { |
| 17 | return queryClient.invalidateQueries({ queryKey: gitQueryKeys.all }); | 27 | return queryClient.invalidateQueries({ queryKey: gitQueryKeys.all }); |
| 18 | } | 28 | } |
| ... | @@ -51,6 +61,7 @@ export function gitBranchesQueryOptions(cwd: string | null) { | ... | @@ -51,6 +61,7 @@ export function gitBranchesQueryOptions(cwd: string | null) { |
| 51 | | 61 | |
| 52 | export function gitInitMutationOptions(input: { cwd: string | null; queryClient: QueryClient }) { | 62 | export function gitInitMutationOptions(input: { cwd: string | null; queryClient: QueryClient }) { |
| 53 | return mutationOptions({ | 63 | return mutationOptions({ |
| | 64 | mutationKey: gitMutationKeys.init(input.cwd), |
| 54 | mutationFn: async () => { | 65 | mutationFn: async () => { |
| 55 | const api = ensureNativeApi(); | 66 | const api = ensureNativeApi(); |
| 56 | if (!input.cwd) throw new Error("Git init is unavailable."); | 67 | if (!input.cwd) throw new Error("Git init is unavailable."); |
| ... | @@ -67,6 +78,7 @@ export function gitCheckoutMutationOptions(input: { | ... | @@ -67,6 +78,7 @@ export function gitCheckoutMutationOptions(input: { |
| 67 | queryClient: QueryClient; | 78 | queryClient: QueryClient; |
| 68 | }) { | 79 | }) { |
| 69 | return mutationOptions({ | 80 | return mutationOptions({ |
| | 81 | mutationKey: gitMutationKeys.checkout(input.cwd), |
| 70 | mutationFn: async (branch: string) => { | 82 | mutationFn: async (branch: string) => { |
| 71 | const api = ensureNativeApi(); | 83 | const api = ensureNativeApi(); |
| 72 | if (!input.cwd) throw new Error("Git checkout is unavailable."); | 84 | if (!input.cwd) throw new Error("Git checkout is unavailable."); |
| ... | @@ -83,6 +95,7 @@ export function gitCreateBranchAndCheckoutMutationOptions(input: { | ... | @@ -83,6 +95,7 @@ export function gitCreateBranchAndCheckoutMutationOptions(input: { |
| 83 | queryClient: QueryClient; | 95 | queryClient: QueryClient; |
| 84 | }) { | 96 | }) { |
| 85 | return mutationOptions({ | 97 | return mutationOptions({ |
| | 98 | mutationKey: gitMutationKeys.createBranchAndCheckout(input.cwd), |
| 86 | mutationFn: async (branch: string) => { | 99 | mutationFn: async (branch: string) => { |
| 87 | const api = ensureNativeApi(); | 100 | const api = ensureNativeApi(); |
| 88 | if (!input.cwd) throw new Error("Git branch creation is unavailable."); | 101 | if (!input.cwd) throw new Error("Git branch creation is unavailable."); |
| ... | @@ -100,6 +113,7 @@ export function gitRunStackedActionMutationOptions(input: { | ... | @@ -100,6 +113,7 @@ export function gitRunStackedActionMutationOptions(input: { |
| 100 | queryClient: QueryClient; | 113 | queryClient: QueryClient; |
| 101 | }) { | 114 | }) { |
| 102 | return mutationOptions({ | 115 | return mutationOptions({ |
| | 116 | mutationKey: gitMutationKeys.runStackedAction(input.cwd), |
| 103 | mutationFn: async ({ | 117 | mutationFn: async ({ |
| 104 | action, | 118 | action, |
| 105 | commitMessage, | 119 | commitMessage, |
| ... | @@ -123,6 +137,7 @@ export function gitRunStackedActionMutationOptions(input: { | ... | @@ -123,6 +137,7 @@ export function gitRunStackedActionMutationOptions(input: { |
| 123 | | 137 | |
| 124 | export function gitPullMutationOptions(input: { cwd: string | null; queryClient: QueryClient }) { | 138 | export function gitPullMutationOptions(input: { cwd: string | null; queryClient: QueryClient }) { |
| 125 | return mutationOptions({ | 139 | return mutationOptions({ |
| | 140 | mutationKey: gitMutationKeys.pull(input.cwd), |
| 126 | mutationFn: async () => { | 141 | mutationFn: async () => { |
| 127 | const api = ensureNativeApi(); | 142 | const api = ensureNativeApi(); |
| 128 | if (!input.cwd) throw new Error("Git pull is unavailable."); | 143 | if (!input.cwd) throw new Error("Git pull is unavailable."); |
| ... | @@ -151,6 +166,7 @@ export function gitCreateWorktreeMutationOptions(input: { queryClient: QueryClie | ... | @@ -151,6 +166,7 @@ export function gitCreateWorktreeMutationOptions(input: { queryClient: QueryClie |
| 151 | if (!cwd) throw new Error("Git worktree creation is unavailable."); | 166 | if (!cwd) throw new Error("Git worktree creation is unavailable."); |
| 152 | return api.git.createWorktree({ cwd, branch, newBranch, path: path ?? null }); | 167 | return api.git.createWorktree({ cwd, branch, newBranch, path: path ?? null }); |
| 153 | }, | 168 | }, |
| | 169 | mutationKey: ["git", "mutation", "create-worktree"] as const, |
| 154 | onSettled: async () => { | 170 | onSettled: async () => { |
| 155 | await invalidateGitQueries(input.queryClient); | 171 | await invalidateGitQueries(input.queryClient); |
| 156 | }, | 172 | }, |
| ... | @@ -164,6 +180,7 @@ export function gitRemoveWorktreeMutationOptions(input: { queryClient: QueryClie | ... | @@ -164,6 +180,7 @@ export function gitRemoveWorktreeMutationOptions(input: { queryClient: QueryClie |
| 164 | if (!cwd) throw new Error("Git worktree removal is unavailable."); | 180 | if (!cwd) throw new Error("Git worktree removal is unavailable."); |
| 165 | return api.git.removeWorktree({ cwd, path, force }); | 181 | return api.git.removeWorktree({ cwd, path, force }); |
| 166 | }, | 182 | }, |
| | 183 | mutationKey: ["git", "mutation", "remove-worktree"] as const, |
| 167 | onSettled: async () => { | 184 | onSettled: async () => { |
| 168 | await invalidateGitQueries(input.queryClient); | 185 | await invalidateGitQueries(input.queryClient); |
| 169 | }, | 186 | }, |