@@ -4319,13 +4319,13 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
43194319 } ) ,
43204320 ) ;
43214321
4322- it . effect ( " flattens a generated name when a branch at its parent path blocks it", ( ) =>
4322+ it . effect . each ( [ "t3" , "T3" ] ) ( " flattens a generated name when parent %s blocks it", ( parent ) =>
43234323 Effect . gen ( function * ( ) {
43244324 const cwd = yield * makeTmpDir ( ) ;
43254325 yield * initRepoWithCommit ( cwd ) ;
43264326 const driver = yield * GitVcsDriver . GitVcsDriver ;
43274327 // A local `t3` branch is why launches start on the flat `t3-<hex>` temporary branch.
4328- yield * git ( cwd , [ "branch" , "t3" ] ) ;
4328+ yield * git ( cwd , [ "branch" , parent ] ) ;
43294329 yield * git ( cwd , [ "checkout" , "-b" , "t3-abcd1234" ] ) ;
43304330 yield * git ( cwd , [ "branch" , "t3-fix-login" ] ) ;
43314331
@@ -4340,26 +4340,112 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
43404340 } ) ,
43414341 ) ;
43424342
4343- it . effect ( "skips a flattened name that a nested branch blocks" , ( ) =>
4343+ it . effect . each ( [ "t3-fix-login/child" , "T3-Fix-Login/child" , "T3-FIX-LOGIN" ] ) (
4344+ "skips a flattened name blocked by %s" ,
4345+ ( occupied ) =>
4346+ Effect . gen ( function * ( ) {
4347+ const cwd = yield * makeTmpDir ( ) ;
4348+ yield * initRepoWithCommit ( cwd ) ;
4349+ const driver = yield * GitVcsDriver . GitVcsDriver ;
4350+ yield * git ( cwd , [ "branch" , "t3" ] ) ;
4351+ yield * git ( cwd , [ "checkout" , "-b" , "t3-abcd1234" ] ) ;
4352+ yield * git ( cwd , [ "branch" , occupied ] ) ;
4353+
4354+ const renamed = yield * driver . renameBranch ( {
4355+ cwd,
4356+ oldBranch : "t3-abcd1234" ,
4357+ newBranch : "t3/fix-login" ,
4358+ } ) ;
4359+
4360+ assert . equal ( renamed . branch , "t3-fix-login-1" ) ;
4361+ assert . equal ( yield * git ( cwd , [ "branch" , "--show-current" ] ) , "t3-fix-login-1" ) ;
4362+ } ) ,
4363+ ) ;
4364+
4365+ it . effect ( "refuses exhausted automatic suffixes without changing existing branches" , ( ) =>
43444366 Effect . gen ( function * ( ) {
43454367 const cwd = yield * makeTmpDir ( ) ;
4346- yield * initRepoWithCommit ( cwd ) ;
4368+ const { initialBranch } = yield * initRepoWithCommit ( cwd ) ;
43474369 const driver = yield * GitVcsDriver . GitVcsDriver ;
4348- yield * git ( cwd , [ "branch" , "t3" ] ) ;
4349- yield * git ( cwd , [ "checkout" , "-b" , "t3-abcd1234" ] ) ;
4350- yield * git ( cwd , [ "branch" , "t3-fix-login/child" ] ) ;
4351-
4352- const renamed = yield * driver . renameBranch ( {
4353- cwd,
4354- oldBranch : "t3-abcd1234" ,
4355- newBranch : "t3/fix-login" ,
4356- } ) ;
4357-
4358- assert . equal ( renamed . branch , "t3-fix-login-1" ) ;
4359- assert . equal ( yield * git ( cwd , [ "branch" , "--show-current" ] ) , "t3-fix-login-1" ) ;
4370+ const oid = yield * git ( cwd , [ "rev-parse" , "HEAD" ] ) ;
4371+ for ( let index = 0 ; index <= 100 ; index += 1 ) {
4372+ yield * git ( cwd , [
4373+ "update-ref" ,
4374+ `refs/heads/${ index === 0 ? "topic" : `topic-${ index } ` } ` ,
4375+ oid ,
4376+ ] ) ;
4377+ }
4378+ const result = yield * driver
4379+ . renameBranch ( { cwd, oldBranch : initialBranch , newBranch : "topic" } )
4380+ . pipe ( Effect . result ) ;
4381+ assert . isTrue ( Result . isFailure ( result ) ) ;
4382+ if ( Result . isFailure ( result ) )
4383+ assert . include ( result . failure . detail , "Could not find an available branch name" ) ;
4384+ assert . equal ( yield * git ( cwd , [ "branch" , "--show-current" ] ) , initialBranch ) ;
4385+ assert . equal ( ( yield * driver . listLocalBranchNames ( cwd ) ) . length , 102 ) ;
43604386 } ) ,
43614387 ) ;
43624388
4389+ it . effect . each ( [ "rename" , "createWorktree" ] as const ) (
4390+ "preserves a concurrent creator's branch when %s loses the atomic ref operation" ,
4391+ ( operation ) =>
4392+ Effect . gen ( function * ( ) {
4393+ const cwd = yield * makeTmpDir ( ) ;
4394+ const { initialBranch } = yield * initRepoWithCommit ( cwd ) ;
4395+ const expected = yield * git ( cwd , [
4396+ "commit-tree" ,
4397+ "HEAD^{tree}" ,
4398+ "-m" ,
4399+ "concurrent winner" ,
4400+ ] ) ;
4401+ const original = yield * GitVcsDriver . GitVcsDriver ;
4402+ const delegate = yield * ChildProcessSpawner . ChildProcessSpawner ;
4403+ let claimed = false ;
4404+ const spawner = ChildProcessSpawner . make ( ( command ) =>
4405+ Effect . gen ( function * ( ) {
4406+ if (
4407+ ! claimed &&
4408+ ChildProcess . isStandardCommand ( command ) &&
4409+ command . args [ 0 ] === "branch" &&
4410+ command . args . includes ( operation === "rename" ? "-m" : "--no-track" )
4411+ ) {
4412+ claimed = true ;
4413+ yield * original
4414+ . execute ( {
4415+ cwd,
4416+ operation : "test.concurrentCreator" ,
4417+ args : [ "update-ref" , "refs/heads/topic" , expected , "" ] ,
4418+ } )
4419+ . pipe ( Effect . orDie ) ;
4420+ }
4421+ return yield * delegate . spawn ( command ) ;
4422+ } ) ,
4423+ ) ;
4424+ const driver = yield * makeGitVcsDriverCore ( ) . pipe (
4425+ Effect . provideService ( ChildProcessSpawner . ChildProcessSpawner , spawner ) ,
4426+ Effect . provide ( layerServerConfig ) ,
4427+ ) ;
4428+ const result = yield * (
4429+ operation === "rename"
4430+ ? driver
4431+ . renameBranch ( { cwd, oldBranch : initialBranch , newBranch : "topic" } )
4432+ . pipe ( Effect . asVoid )
4433+ : driver
4434+ . createWorktree ( {
4435+ cwd,
4436+ refName : initialBranch ,
4437+ newRefName : "topic" ,
4438+ path : NodePath . join ( cwd , "checkout" ) ,
4439+ } )
4440+ . pipe ( Effect . asVoid )
4441+ ) . pipe ( Effect . result ) ;
4442+ assert . isTrue ( claimed ) ;
4443+ assert . isTrue ( Result . isFailure ( result ) ) ;
4444+ assert . equal ( yield * git ( cwd , [ "rev-parse" , "refs/heads/topic" ] ) , expected ) ;
4445+ assert . equal ( yield * git ( cwd , [ "branch" , "--show-current" ] ) , initialBranch ) ;
4446+ } ) ,
4447+ ) ;
4448+
43634449 it . effect ( "rejects a missing branch without restoring a matching dirty file" , ( ) =>
43644450 Effect . gen ( function * ( ) {
43654451 const cwd = yield * makeTmpDir ( ) ;
@@ -4956,13 +5042,15 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
49565042 { cwd, path : null , refName : initialBranch , newRefName : "feature/custom-dir" } ,
49575043 { worktreesDirectory } ,
49585044 ) ;
4959- const expected = pathService . join (
4960- worktreesDirectory ,
4961- pathService . basename ( cwd ) ,
4962- "feature-custom-dir" ,
5045+ assert . equal (
5046+ pathService . dirname ( created . worktree . path ) ,
5047+ pathService . join ( worktreesDirectory , pathService . basename ( cwd ) ) ,
5048+ ) ;
5049+ assert . match (
5050+ pathService . basename ( created . worktree . path ) ,
5051+ / ^ f e a t u r e - c u s t o m - d i r - [ 0 - 9 a - f ] { 16 } $ / ,
49635052 ) ;
4964- assert . equal ( created . worktree . path , expected ) ;
4965- assert . equal ( yield * fileSystem . exists ( expected ) , true ) ;
5053+ assert . equal ( yield * fileSystem . exists ( created . worktree . path ) , true ) ;
49665054
49675055 const error = yield * driver
49685056 . createWorktree (
@@ -4982,6 +5070,33 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
49825070 } ) ,
49835071 ) ;
49845072
5073+ it . effect (
5074+ "keeps generated paths distinct across branch spellings and equal repository basenames" ,
5075+ ( ) =>
5076+ Effect . gen ( function * ( ) {
5077+ const fs = yield * FileSystem . FileSystem ;
5078+ const path = yield * Path . Path ;
5079+ const root = yield * makeTmpDir ( ) ;
5080+ const worktreesDirectory = yield * makeTmpDir ( ) ;
5081+ const driver = yield * GitVcsDriver . GitVcsDriver ;
5082+ const paths = new Set < string > ( ) ;
5083+ for ( const owner of [ "one" , "two" ] ) {
5084+ const cwd = path . join ( root , owner , "repository" ) ;
5085+ yield * fs . makeDirectory ( cwd , { recursive : true } ) ;
5086+ const { initialBranch } = yield * initRepoWithCommit ( cwd ) ;
5087+ for ( const branch of [ "feat/a" , "feat-a" ] ) {
5088+ const created = yield * driver . createWorktree (
5089+ { cwd, path : null , refName : initialBranch , newRefName : branch } ,
5090+ { worktreesDirectory } ,
5091+ ) ;
5092+ paths . add ( created . worktree . path ) ;
5093+ assert . equal ( yield * git ( created . worktree . path , [ "branch" , "--show-current" ] ) , branch ) ;
5094+ }
5095+ }
5096+ assert . equal ( paths . size , 4 ) ;
5097+ } ) ,
5098+ ) ;
5099+
49855100 it . effect ( "keeps generated worktree folders short without changing long branch names" , ( ) =>
49865101 Effect . gen ( function * ( ) {
49875102 const pathService = yield * Path . Path ;
@@ -4996,6 +5111,8 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
49965111 `feature/${ "a" . repeat ( 40 ) } /5fac` ,
49975112 `feature/${ "a" . repeat ( 40 ) } /18828` ,
49985113 `${ "a" . repeat ( 22 ) } 😀/${ "b" . repeat ( 30 ) } ` ,
5114+ "😀" . repeat ( 60 ) ,
5115+ "界" . repeat ( 80 ) ,
49995116 "z" . repeat ( 40 ) ,
50005117 "z" . repeat ( 41 ) ,
50015118 ] ;
@@ -5005,8 +5122,7 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
50055122 { worktreesDirectory } ,
50065123 ) ;
50075124 const folder = pathService . basename ( created . worktree . path ) ;
5008- assert . isAtMost ( folder . length , 40 ) ;
5009- if ( branch . length <= 40 ) assert . equal ( folder , branch ) ;
5125+ assert . isAtMost ( Buffer . byteLength ( folder ) , 40 ) ;
50105126 assert . equal ( yield * git ( created . worktree . path , [ "branch" , "--show-current" ] ) , branch ) ;
50115127 assert . include (
50125128 yield * git ( cwd , [ "-c" , "core.quotePath=false" , "worktree" , "list" , "--porcelain" ] ) ,
0 commit comments