@@ -13,6 +13,16 @@ export const gitQueryKeys = {
1313 branches : ( cwd : string | null ) => [ "git" , "branches" , cwd ] as const ,
1414} ;
1515
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+
1626export function invalidateGitQueries ( queryClient : QueryClient ) {
1727 return queryClient . invalidateQueries ( { queryKey : gitQueryKeys . all } ) ;
1828}
@@ -51,6 +61,7 @@ export function gitBranchesQueryOptions(cwd: string | null) {
5161
5262export function gitInitMutationOptions ( input : { cwd : string | null ; queryClient : QueryClient } ) {
5363 return mutationOptions ( {
64+ mutationKey : gitMutationKeys . init ( input . cwd ) ,
5465 mutationFn : async ( ) => {
5566 const api = ensureNativeApi ( ) ;
5667 if ( ! input . cwd ) throw new Error ( "Git init is unavailable." ) ;
@@ -67,6 +78,7 @@ export function gitCheckoutMutationOptions(input: {
6778 queryClient : QueryClient ;
6879} ) {
6980 return mutationOptions ( {
81+ mutationKey : gitMutationKeys . checkout ( input . cwd ) ,
7082 mutationFn : async ( branch : string ) => {
7183 const api = ensureNativeApi ( ) ;
7284 if ( ! input . cwd ) throw new Error ( "Git checkout is unavailable." ) ;
@@ -83,6 +95,7 @@ export function gitCreateBranchAndCheckoutMutationOptions(input: {
8395 queryClient : QueryClient ;
8496} ) {
8597 return mutationOptions ( {
98+ mutationKey : gitMutationKeys . createBranchAndCheckout ( input . cwd ) ,
8699 mutationFn : async ( branch : string ) => {
87100 const api = ensureNativeApi ( ) ;
88101 if ( ! input . cwd ) throw new Error ( "Git branch creation is unavailable." ) ;
@@ -100,6 +113,7 @@ export function gitRunStackedActionMutationOptions(input: {
100113 queryClient : QueryClient ;
101114} ) {
102115 return mutationOptions ( {
116+ mutationKey : gitMutationKeys . runStackedAction ( input . cwd ) ,
103117 mutationFn : async ( {
104118 action,
105119 commitMessage,
@@ -123,6 +137,7 @@ export function gitRunStackedActionMutationOptions(input: {
123137
124138export function gitPullMutationOptions ( input : { cwd : string | null ; queryClient : QueryClient } ) {
125139 return mutationOptions ( {
140+ mutationKey : gitMutationKeys . pull ( input . cwd ) ,
126141 mutationFn : async ( ) => {
127142 const api = ensureNativeApi ( ) ;
128143 if ( ! input . cwd ) throw new Error ( "Git pull is unavailable." ) ;
@@ -151,6 +166,7 @@ export function gitCreateWorktreeMutationOptions(input: { queryClient: QueryClie
151166 if ( ! cwd ) throw new Error ( "Git worktree creation is unavailable." ) ;
152167 return api . git . createWorktree ( { cwd, branch, newBranch, path : path ?? null } ) ;
153168 } ,
169+ mutationKey : [ "git" , "mutation" , "create-worktree" ] as const ,
154170 onSettled : async ( ) => {
155171 await invalidateGitQueries ( input . queryClient ) ;
156172 } ,
@@ -164,6 +180,7 @@ export function gitRemoveWorktreeMutationOptions(input: { queryClient: QueryClie
164180 if ( ! cwd ) throw new Error ( "Git worktree removal is unavailable." ) ;
165181 return api . git . removeWorktree ( { cwd, path, force } ) ;
166182 } ,
183+ mutationKey : [ "git" , "mutation" , "remove-worktree" ] as const ,
167184 onSettled : async ( ) => {
168185 await invalidateGitQueries ( input . queryClient ) ;
169186 } ,
0 commit comments