@@ -367,6 +367,22 @@ const layer = Layer.effect(
367367 } )
368368 } )
369369
370+ /**
371+ * On Windows, Git exits non-zero instead of reusing a loose object that another process is finalizing at the
372+ * same moment. Objects are content-addressed, so one of at most two retries finds that copy in place. Only a Git
373+ * exit is retried, never a failure to start Git, and other platforms fail on the first attempt.
374+ */
375+ const retryConcurrentObjectWrite = < A , R > ( effect : Effect . Effect < A , OperationError , R > ) =>
376+ process . platform === "win32"
377+ ? effect . pipe (
378+ Effect . retry ( {
379+ times : 2 ,
380+ schedule : Schedule . spaced ( "50 millis" ) ,
381+ while : ( error ) => error . cause === undefined ,
382+ } ) ,
383+ )
384+ : effect
385+
370386 /**
371387 * A new store is initialized in a temporary sibling directory and renamed into
372388 * place, so processes racing to create the same store never observe or write a
@@ -505,11 +521,13 @@ const layer = Layer.effect(
505521 { concurrency : 8 } ,
506522 ) ) . filter ( ( item ) : item is RelativePath => item !== undefined )
507523 if ( added . length )
508- yield * repositoryOperation (
509- "refresh" ,
510- input . repository ,
511- [ "update-index" , "--add" , "--remove" , "--replace" , "-z" , "--stdin" ] ,
512- { stdin : [ ...added , ...embedded ] . join ( "\0" ) + "\0" , index : input . index } ,
524+ yield * retryConcurrentObjectWrite (
525+ repositoryOperation (
526+ "refresh" ,
527+ input . repository ,
528+ [ "update-index" , "--add" , "--remove" , "--replace" , "-z" , "--stdin" ] ,
529+ { stdin : [ ...added , ...embedded ] . join ( "\0" ) + "\0" , index : input . index } ,
530+ ) ,
513531 )
514532 return { skipped }
515533 } )
@@ -561,7 +579,9 @@ const layer = Layer.effect(
561579 } )
562580
563581 const writeTree = Effect . fn ( "Git.tree.write" ) ( function * ( repository : Repository , index ?: string ) {
564- const tree = ( yield * repositoryOperation ( "write_tree" , repository , [ "write-tree" ] , { index } ) ) . text . trim ( )
582+ const tree = ( yield * retryConcurrentObjectWrite (
583+ repositoryOperation ( "write_tree" , repository , [ "write-tree" ] , { index } ) ,
584+ ) ) . text . trim ( )
565585 if ( / ^ [ 0 - 9 a - f ] { 40 , 64 } $ / . test ( tree ) ) return TreeID . make ( tree )
566586 return yield * new OperationError ( {
567587 operation : "write_tree" ,
0 commit comments