@@ -3,7 +3,7 @@ import { invoke } from '@tauri-apps/api/core';
33import { createFastMutation } from '@yaakapp/app/hooks/useFastMutation' ;
44import { queryClient } from '@yaakapp/app/lib/queryClient' ;
55import { useMemo } from 'react' ;
6- import { GitCommit , GitRemote , GitStatusSummary , PullResult , PushResult } from './bindings/gen_git' ;
6+ import { BranchDeleteResult , CloneResult , GitCommit , GitRemote , GitStatusSummary , PullResult , PushResult } from './bindings/gen_git' ;
77
88export * from './bindings/gen_git' ;
99
@@ -59,7 +59,6 @@ export const gitMutations = (dir: string, callbacks: GitCallbacks) => {
5959 if ( creds == null ) throw new Error ( 'Canceled' ) ;
6060
6161 await invoke ( 'cmd_git_add_credential' , {
62- dir,
6362 remoteUrl : result . url ,
6463 username : creds . username ,
6564 password : creds . password ,
@@ -90,21 +89,31 @@ export const gitMutations = (dir: string, callbacks: GitCallbacks) => {
9089 mutationFn : ( args ) => invoke ( 'cmd_git_rm_remote' , { dir, ...args } ) ,
9190 onSuccess,
9291 } ) ,
93- branch : createFastMutation < void , string , { branch : string } > ( {
92+ createBranch : createFastMutation < void , string , { branch : string ; base ? : string } > ( {
9493 mutationKey : [ 'git' , 'branch' , dir ] ,
9594 mutationFn : ( args ) => invoke ( 'cmd_git_branch' , { dir, ...args } ) ,
9695 onSuccess,
9796 } ) ,
98- mergeBranch : createFastMutation < void , string , { branch : string ; force : boolean } > ( {
97+ mergeBranch : createFastMutation < void , string , { branch : string } > ( {
9998 mutationKey : [ 'git' , 'merge' , dir ] ,
10099 mutationFn : ( args ) => invoke ( 'cmd_git_merge_branch' , { dir, ...args } ) ,
101100 onSuccess,
102101 } ) ,
103- deleteBranch : createFastMutation < void , string , { branch : string } > ( {
102+ deleteBranch : createFastMutation < BranchDeleteResult , string , { branch : string , force ?: boolean } > ( {
104103 mutationKey : [ 'git' , 'delete-branch' , dir ] ,
105104 mutationFn : ( args ) => invoke ( 'cmd_git_delete_branch' , { dir, ...args } ) ,
106105 onSuccess,
107106 } ) ,
107+ deleteRemoteBranch : createFastMutation < void , string , { branch : string } > ( {
108+ mutationKey : [ 'git' , 'delete-remote-branch' , dir ] ,
109+ mutationFn : ( args ) => invoke ( 'cmd_git_delete_remote_branch' , { dir, ...args } ) ,
110+ onSuccess,
111+ } ) ,
112+ renameBranch : createFastMutation < void , string , { oldName : string , newName : string } > ( {
113+ mutationKey : [ 'git' , 'rename-branch' , dir ] ,
114+ mutationFn : ( args ) => invoke ( 'cmd_git_rename_branch' , { dir, ...args } ) ,
115+ onSuccess,
116+ } ) ,
108117 checkout : createFastMutation < string , string , { branch : string ; force : boolean } > ( {
109118 mutationKey : [ 'git' , 'checkout' , dir ] ,
110119 mutationFn : ( args ) => invoke ( 'cmd_git_checkout' , { dir, ...args } ) ,
@@ -144,7 +153,6 @@ export const gitMutations = (dir: string, callbacks: GitCallbacks) => {
144153 if ( creds == null ) throw new Error ( 'Canceled' ) ;
145154
146155 await invoke ( 'cmd_git_add_credential' , {
147- dir,
148156 remoteUrl : result . url ,
149157 username : creds . username ,
150158 password : creds . password ,
@@ -166,3 +174,28 @@ export const gitMutations = (dir: string, callbacks: GitCallbacks) => {
166174async function getRemotes ( dir : string ) {
167175 return invoke < GitRemote [ ] > ( 'cmd_git_remotes' , { dir } ) ;
168176}
177+
178+ /**
179+ * Clone a git repository, prompting for credentials if needed.
180+ */
181+ export async function gitClone (
182+ url : string ,
183+ dir : string ,
184+ promptCredentials : ( args : { url : string ; error : string | null } ) => Promise < GitCredentials | null > ,
185+ ) : Promise < CloneResult > {
186+ const result = await invoke < CloneResult > ( 'cmd_git_clone' , { url, dir } ) ;
187+ if ( result . type !== 'needs_credentials' ) return result ;
188+
189+ // Prompt for credentials
190+ const creds = await promptCredentials ( { url : result . url , error : result . error } ) ;
191+ if ( creds == null ) return { type : 'cancelled' } ;
192+
193+ // Store credentials and retry
194+ await invoke ( 'cmd_git_add_credential' , {
195+ remoteUrl : result . url ,
196+ username : creds . username ,
197+ password : creds . password ,
198+ } ) ;
199+
200+ return invoke < CloneResult > ( 'cmd_git_clone' , { url, dir } ) ;
201+ }
0 commit comments