@@ -189,16 +189,16 @@ pub(crate) fn execute_git_with_environment(
189189) -> Result < GitCommandResponse , CoreError > {
190190 let arguments = execution_policy:: arguments ( arguments) ;
191191 let mut retry_scope = None ;
192- for attempt in 0 ..3 {
193- let output = capture_git_process (
192+ for round in 0 ..3 {
193+ let attempt = capture_git_attempt (
194194 root,
195195 & arguments,
196196 input. clone ( ) ,
197197 disable_optional_locks,
198198 environment,
199199 true ,
200200 ) ?;
201- let response = output. into_command_response ( & arguments) ;
201+ let response = attempt . output . into_command_response ( & arguments) ;
202202 record_git_invocation ( & response) ;
203203 let authentication_failed = [
204204 "Authentication failed" ,
@@ -214,11 +214,14 @@ pub(crate) fn execute_git_with_environment(
214214 "fetch" | "pull" | "push" | "clone"
215215 )
216216 } ) ;
217+ // A user who cancelled or let a prompt expire has already declined;
218+ // asking whether to retry would only repeat the question.
217219 if response. exit_code == 0
218220 || !authentication_failed
219221 || !transfer
220222 || !execution_policy:: current ( ) . interactive
221- || attempt == 2
223+ || attempt. prompt_unanswered
224+ || round == 2
222225 {
223226 return Ok ( response) ;
224227 }
@@ -233,7 +236,7 @@ pub(crate) fn execute_git_with_environment(
233236 execution_events:: emit (
234237 serde_json:: json!( { "type" : "authentication" , "requestId" : confirmation. request_id,
235238 "prompt" : "Git authentication failed. Retry with credentials entered in Lithe, bypassing the credential helper for this retry?" ,
236- "secret" : false , "retry" : true , "attempt" : attempt + 2 , "workingDirectory" : root } ) ,
239+ "secret" : false , "retry" : true , "attempt" : round + 2 , "workingDirectory" : root } ) ,
237240 ) ;
238241 let retry = confirmation
239242 . wait ( || lithe_protocol:: cancellation:: check ( ) . is_err ( ) )
@@ -284,6 +287,34 @@ pub(crate) fn capture_git_process(
284287 environment : & [ ( String , String ) ] ,
285288 visible : bool ,
286289) -> Result < GitProcessOutput , CoreError > {
290+ capture_git_attempt (
291+ root,
292+ arguments,
293+ input,
294+ disable_optional_locks,
295+ environment,
296+ visible,
297+ )
298+ . map ( |attempt| attempt. output )
299+ }
300+
301+ /// One Git process and what became of the credential prompts it asked.
302+ struct GitAttempt {
303+ output : GitProcessOutput ,
304+ /// A prompt ended without an answer from the user: they cancelled it, or
305+ /// it expired. The authentication failure that follows is their decision,
306+ /// so it is not offered for retry.
307+ prompt_unanswered : bool ,
308+ }
309+
310+ fn capture_git_attempt (
311+ root : & str ,
312+ arguments : & [ String ] ,
313+ input : Option < String > ,
314+ disable_optional_locks : bool ,
315+ environment : & [ ( String , String ) ] ,
316+ visible : bool ,
317+ ) -> Result < GitAttempt , CoreError > {
287318 validate_windows_git_path ( Path :: new ( root) ) . map_err ( git_path_error) ?;
288319 lithe_protocol:: cancellation:: check ( ) ?;
289320 // Refuse before the trace: in safe mode no Git starts, so there is nothing to record.
@@ -299,7 +330,11 @@ pub(crate) fn capture_git_process(
299330 visible,
300331 & mut trace,
301332 ) {
302- Some ( result) => result,
333+ // Remote Git never asks through this host's AskPass channel.
334+ Some ( result) => result. map ( |output| GitAttempt {
335+ output,
336+ prompt_unanswered : false ,
337+ } ) ,
303338 None => capture_local_git_process (
304339 root,
305340 arguments,
@@ -322,7 +357,7 @@ fn capture_local_git_process(
322357 environment : & [ ( String , String ) ] ,
323358 visible : bool ,
324359 trace : & mut command_trace:: Trace ,
325- ) -> Result < GitProcessOutput , CoreError > {
360+ ) -> Result < GitAttempt , CoreError > {
326361 let mut process = git_process ( ) ?;
327362 let version = lithe_git_host:: configuration:: version ( process. get_program ( ) , || {
328363 lithe_protocol:: cancellation:: check ( ) . is_err ( )
@@ -460,10 +495,15 @@ fn capture_local_git_process(
460495 if let Some ( error) = error {
461496 return Err ( error) ;
462497 }
463- Ok ( GitProcessOutput {
464- stdout : output. stdout ,
465- stderr : output. stderr ,
466- exit_code : exit_code. unwrap_or ( 1 ) ,
498+ Ok ( GitAttempt {
499+ output : GitProcessOutput {
500+ stdout : output. stdout ,
501+ stderr : output. stderr ,
502+ exit_code : exit_code. unwrap_or ( 1 ) ,
503+ } ,
504+ prompt_unanswered : authentication
505+ . as_ref ( )
506+ . is_some_and ( lithe_git_host:: authentication:: Session :: unanswered) ,
467507 } )
468508}
469509
0 commit comments