@@ -6129,6 +6129,86 @@ it.layer(layerGitManagerTest)("GitManager", (it) => {
61296129 } ) ,
61306130 ) ;
61316131
6132+ it . effect . each ( [
6133+ { isCrossRepository : false , padding : 0 } ,
6134+ { isCrossRepository : false , padding : 110 } ,
6135+ { isCrossRepository : true , padding : 0 } ,
6136+ { isCrossRepository : true , padding : 110 } ,
6137+ ] ) (
6138+ "reuses an existing PR worktree with $padding preceding matching branches (fork: $isCrossRepository)" ,
6139+ ( { isCrossRepository, padding } ) =>
6140+ Effect . gen ( function * ( ) {
6141+ const repoDir = yield * makeTempDir ( "t3code-git-manager-" ) ;
6142+ yield * initRepo ( repoDir ) ;
6143+ const remoteDir = yield * createBareRemote ( ) ;
6144+ yield * runGit ( repoDir , [ "remote" , "add" , "origin" , remoteDir ] ) ;
6145+ yield * runGit ( repoDir , [ "push" , "-u" , "origin" , "main" ] ) ;
6146+ const forkDir = isCrossRepository ? yield * createBareRemote ( ) : null ;
6147+ if ( forkDir ) {
6148+ yield * runGit ( repoDir , [ "remote" , "add" , "fork-seed" , forkDir ] ) ;
6149+ yield * runGit ( repoDir , [ "push" , "fork-seed" , "main:pr-pagination" ] ) ;
6150+ }
6151+ const headBranch = "pr-pagination" ;
6152+ const localBranch = isCrossRepository ? "t3code/pr-78/pr-pagination" : headBranch ;
6153+ yield * runGit ( repoDir , [ "branch" , localBranch ] ) ;
6154+ yield * runGit ( repoDir , [ "push" , "origin" , `${ localBranch } :refs/pull/78/head` ] ) ;
6155+ const worktreePath = NodePath . join ( repoDir , "existing-pr" ) ;
6156+ yield * runGit ( repoDir , [ "worktree" , "add" , worktreePath , localBranch ] ) ;
6157+ for ( let index = 0 ; index < padding ; index ++ ) {
6158+ yield * runGit ( repoDir , [
6159+ "branch" ,
6160+ `a-padding-${ String ( index ) . padStart ( 3 , "0" ) } /${ localBranch } ` ,
6161+ ] ) ;
6162+ }
6163+ const git = yield * GitVcsDriver . GitVcsDriver ;
6164+ const page = yield * git . listRefs ( {
6165+ cwd : repoDir ,
6166+ refKind : "local" ,
6167+ query : localBranch ,
6168+ refresh : true ,
6169+ } ) ;
6170+ expect ( page . nextCursor !== null ) . toBe ( padding > 0 ) ;
6171+ expect ( page . refs . some ( ( ref ) => ref . name === localBranch ) ) . toBe ( padding === 0 ) ;
6172+ const { manager } = yield * makeManager ( {
6173+ ghScenario : {
6174+ repositoryCloneUrls : forkDir
6175+ ? { "contributor/codething-mvp" : { url : forkDir , sshUrl : forkDir } }
6176+ : { } ,
6177+ pullRequest : {
6178+ number : 78 ,
6179+ title : "Paginated PR worktree" ,
6180+ url : "https://github.com/pingdotgg/codething-mvp/pull/78" ,
6181+ baseRefName : "main" ,
6182+ headRefName : headBranch ,
6183+ state : "open" ,
6184+ isCrossRepository,
6185+ ...( isCrossRepository
6186+ ? {
6187+ headRepositoryNameWithOwner : "contributor/codething-mvp" ,
6188+ headRepositoryOwnerLogin : "contributor" ,
6189+ }
6190+ : { } ) ,
6191+ } ,
6192+ } ,
6193+ } ) ;
6194+
6195+ // Fetching directly into this checked-out branch would fail with git exit 128.
6196+ const result = yield * preparePullRequestThread ( manager , {
6197+ cwd : repoDir ,
6198+ reference : "78" ,
6199+ mode : "worktree" ,
6200+ } ) ;
6201+ expect ( result . worktreePath && NodeFS . realpathSync . native ( result . worktreePath ) ) . toBe (
6202+ NodeFS . realpathSync . native ( worktreePath ) ,
6203+ ) ;
6204+ expect ( result . branch ) . toBe ( localBranch ) ;
6205+ expect ( result . isOnPullRequestHead ) . toBe ( true ) ;
6206+ expect ( ( yield * runGit ( worktreePath , [ "branch" , "--show-current" ] ) ) . stdout . trim ( ) ) . toBe (
6207+ localBranch ,
6208+ ) ;
6209+ } ) ,
6210+ ) ;
6211+
61326212 it . effect ( "refreshes a reused PR worktree that has no upstream from the pull request ref" , ( ) =>
61336213 Effect . gen ( function * ( ) {
61346214 const repoDir = yield * makeTempDir ( "t3code-git-manager-" ) ;
0 commit comments