@@ -185,6 +185,7 @@ interface ExecuteGitOptions {
185185 maxOutputBytes ?: number | undefined ;
186186 appendTruncationMarker ?: boolean | undefined ;
187187 progress ?: GitVcsDriver . ExecuteGitProgress | undefined ;
188+ writesSharedConfig ?: boolean | undefined ;
188189}
189190
190191function parseBranchAb ( value : string ) : { ahead : number ; behind : number } {
@@ -1072,6 +1073,21 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
10721073 } ,
10731074 ) ;
10741075
1076+ const sharedConfigLocks = new Map < string , Semaphore . Semaphore > ( ) ;
1077+ const withSharedConfigLock = < A , E > ( cwd : string , effect : Effect . Effect < A , E > ) =>
1078+ resolveRepositoryPaths ( cwd ) . pipe (
1079+ Effect . orElseSucceed ( ( ) => null ) ,
1080+ Effect . flatMap ( ( repositoryPaths ) => {
1081+ if ( repositoryPaths === null ) return effect ;
1082+ let lock = sharedConfigLocks . get ( repositoryPaths . gitCommonDir ) ;
1083+ if ( lock === undefined ) {
1084+ lock = Semaphore . makeUnsafe ( 1 ) ;
1085+ sharedConfigLocks . set ( repositoryPaths . gitCommonDir , lock ) ;
1086+ }
1087+ return lock . withPermit ( effect ) ;
1088+ } ) ,
1089+ ) ;
1090+
10751091 const execute : GitVcsDriver . GitVcsDriver [ "Service" ] [ "execute" ] = ( input ) =>
10761092 executeRaw ( input ) . pipe (
10771093 withMetrics ( {
@@ -1093,6 +1109,9 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
10931109 "git.args_count" : input . args . length ,
10941110 } ,
10951111 } ) ,
1112+ // Outside the process permit: resolving the repository may itself need one.
1113+ ( execution ) =>
1114+ input . writesSharedConfig ? withSharedConfigLock ( input . cwd , execution ) : execution ,
10961115 ) ;
10971116
10981117 const executeGit = (
@@ -1117,6 +1136,7 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
11171136 ? { appendTruncationMarker : options . appendTruncationMarker }
11181137 : { } ) ,
11191138 ...( options . progress ? { progress : options . progress } : { } ) ,
1139+ ...( options . writesSharedConfig ? { writesSharedConfig : true } : { } ) ,
11201140 } ) . pipe (
11211141 Effect . flatMap ( ( result ) => {
11221142 if ( options . allowNonZeroExit || result . exitCode === 0 ) {
@@ -2602,17 +2622,23 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
26022622 const publishBranch = yield * resolvePublishBranchName ( cwd , branch ) ;
26032623 // Publishing retargets the upstream, so preserve its comparison base first.
26042624 if ( ( yield * readBranchBase ( cwd , branch ) ) === null ) {
2605- yield * runGit ( "GitVcsDriver.pushCurrentBranch.recordMergeBase" , cwd , [
2606- "config" ,
2607- branchBaseConfigKey ( branch ) ,
2608- currentUpstream . branchName ,
2609- ] ) ;
2625+ yield * runGit (
2626+ "GitVcsDriver.pushCurrentBranch.recordMergeBase" ,
2627+ cwd ,
2628+ [ "config" , branchBaseConfigKey ( branch ) , currentUpstream . branchName ] ,
2629+ { writesSharedConfig : true } ,
2630+ ) ;
26102631 if ( ! ( yield * readConfigValue ( cwd , `branch.${ branch } .t3-merge-base-ref` ) ) ) {
2611- yield * runGit ( "GitVcsDriver.pushCurrentBranch.recordComparisonRef" , cwd , [
2612- "config" ,
2613- `branch.${ branch } .t3-merge-base-ref` ,
2614- `refs/remotes/${ currentUpstream . upstreamRef } ` ,
2615- ] ) ;
2632+ yield * runGit (
2633+ "GitVcsDriver.pushCurrentBranch.recordComparisonRef" ,
2634+ cwd ,
2635+ [
2636+ "config" ,
2637+ `branch.${ branch } .t3-merge-base-ref` ,
2638+ `refs/remotes/${ currentUpstream . upstreamRef } ` ,
2639+ ] ,
2640+ { writesSharedConfig : true } ,
2641+ ) ;
26162642 }
26172643 }
26182644 yield * runGit (
@@ -3714,6 +3740,8 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
37143740 {
37153741 fallbackErrorDetail : "git worktree add failed" ,
37163742 timeoutMs : WORKTREE_ADD_TIMEOUT_MS ,
3743+ // Tracking a remote start point writes the new branch's upstream.
3744+ writesSharedConfig : true ,
37173745 ...( onCheckoutProgress
37183746 ? {
37193747 // Git only prints checkout progress when stderr is a tty or the
@@ -3805,18 +3833,20 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
38053833 const base = yield * resolveBranchBase ( input . cwd , input . baseRefName ) ;
38063834 if ( base ) {
38073835 yield * Effect . gen ( function * ( ) {
3808- yield * runGit ( "GitVcsDriver.createWorktree.configureBaseRef" , input . cwd , [
3809- "config" ,
3810- branchBaseConfigKey ( newRefName ) ,
3811- base . branchName ,
3812- ] ) ;
3836+ yield * runGit (
3837+ "GitVcsDriver.createWorktree.configureBaseRef" ,
3838+ input . cwd ,
3839+ [ "config" , branchBaseConfigKey ( newRefName ) , base . branchName ] ,
3840+ { writesSharedConfig : true } ,
3841+ ) ;
38133842 if ( base . baseRef . startsWith ( "refs/remotes/" ) ) {
38143843 // The base key names a branch on the host; this one keeps the remote it came from.
3815- yield * runGit ( "GitVcsDriver.createWorktree.configureComparisonRef" , input . cwd , [
3816- "config" ,
3817- `branch.${ input . newRefName } .t3-merge-base-ref` ,
3818- base . baseRef ,
3819- ] ) ;
3844+ yield * runGit (
3845+ "GitVcsDriver.createWorktree.configureComparisonRef" ,
3846+ input . cwd ,
3847+ [ "config" , `branch.${ input . newRefName } .t3-merge-base-ref` , base . baseRef ] ,
3848+ { writesSharedConfig : true } ,
3849+ ) ;
38203850 }
38213851 } ) . pipe (
38223852 Effect . catchTags ( {
@@ -4125,13 +4155,18 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
41254155 } ) ;
41264156
41274157 const setBranchUpstream : GitVcsDriver . GitVcsDriver [ "Service" ] [ "setBranchUpstream" ] = ( input ) =>
4128- runGit ( "GitVcsDriver.setBranchUpstream" , input . cwd , [
4129- "branch" ,
4130- "--set-upstream-to" ,
4131- `${ input . remoteName } /${ input . remoteBranch } ` ,
4132- "--" ,
4133- input . branch ,
4134- ] ) ;
4158+ runGit (
4159+ "GitVcsDriver.setBranchUpstream" ,
4160+ input . cwd ,
4161+ [
4162+ "branch" ,
4163+ "--set-upstream-to" ,
4164+ `${ input . remoteName } /${ input . remoteBranch } ` ,
4165+ "--" ,
4166+ input . branch ,
4167+ ] ,
4168+ { writesSharedConfig : true } ,
4169+ ) ;
41354170
41364171 /**
41374172 * Unlinks links under `target` without following them and removes the
0 commit comments