@@ -6724,6 +6724,86 @@ it.layer(layerGitManagerTest)("GitManager", (it) => {
67246724 } ) ,
67256725 ) ;
67266726
6727+ it . effect . each ( [
6728+ { isCrossRepository : false , padding : 0 } ,
6729+ { isCrossRepository : false , padding : 110 } ,
6730+ { isCrossRepository : true , padding : 0 } ,
6731+ { isCrossRepository : true , padding : 110 } ,
6732+ ] ) (
6733+ "reuses an existing PR worktree with $padding preceding matching branches (fork: $isCrossRepository)" ,
6734+ ( { isCrossRepository, padding } ) =>
6735+ Effect . gen ( function * ( ) {
6736+ const repoDir = yield * makeTempDir ( "t3code-git-manager-" ) ;
6737+ yield * initRepo ( repoDir ) ;
6738+ const remoteDir = yield * createBareRemote ( ) ;
6739+ yield * runGit ( repoDir , [ "remote" , "add" , "origin" , remoteDir ] ) ;
6740+ yield * runGit ( repoDir , [ "push" , "-u" , "origin" , "main" ] ) ;
6741+ const forkDir = isCrossRepository ? yield * createBareRemote ( ) : null ;
6742+ if ( forkDir ) {
6743+ yield * runGit ( repoDir , [ "remote" , "add" , "fork-seed" , forkDir ] ) ;
6744+ yield * runGit ( repoDir , [ "push" , "fork-seed" , "main:pr-pagination" ] ) ;
6745+ }
6746+ const headBranch = "pr-pagination" ;
6747+ const localBranch = isCrossRepository ? "t3code/pr-78/pr-pagination" : headBranch ;
6748+ yield * runGit ( repoDir , [ "branch" , localBranch ] ) ;
6749+ yield * runGit ( repoDir , [ "push" , "origin" , `${ localBranch } :refs/pull/78/head` ] ) ;
6750+ const worktreePath = NodePath . join ( repoDir , "existing-pr" ) ;
6751+ yield * runGit ( repoDir , [ "worktree" , "add" , worktreePath , localBranch ] ) ;
6752+ for ( let index = 0 ; index < padding ; index ++ ) {
6753+ yield * runGit ( repoDir , [
6754+ "branch" ,
6755+ `a-padding-${ String ( index ) . padStart ( 3 , "0" ) } /${ localBranch } ` ,
6756+ ] ) ;
6757+ }
6758+ const git = yield * GitVcsDriver . GitVcsDriver ;
6759+ const page = yield * git . listRefs ( {
6760+ cwd : repoDir ,
6761+ refKind : "local" ,
6762+ query : localBranch ,
6763+ refresh : true ,
6764+ } ) ;
6765+ expect ( page . nextCursor !== null ) . toBe ( padding > 0 ) ;
6766+ expect ( page . refs . some ( ( ref ) => ref . name === localBranch ) ) . toBe ( padding === 0 ) ;
6767+ const { manager } = yield * makeManager ( {
6768+ ghScenario : {
6769+ repositoryCloneUrls : forkDir
6770+ ? { "contributor/codething-mvp" : { url : forkDir , sshUrl : forkDir } }
6771+ : { } ,
6772+ pullRequest : {
6773+ number : 78 ,
6774+ title : "Paginated PR worktree" ,
6775+ url : "https://github.com/pingdotgg/codething-mvp/pull/78" ,
6776+ baseRefName : "main" ,
6777+ headRefName : headBranch ,
6778+ state : "open" ,
6779+ isCrossRepository,
6780+ ...( isCrossRepository
6781+ ? {
6782+ headRepositoryNameWithOwner : "contributor/codething-mvp" ,
6783+ headRepositoryOwnerLogin : "contributor" ,
6784+ }
6785+ : { } ) ,
6786+ } ,
6787+ } ,
6788+ } ) ;
6789+
6790+ // Fetching directly into this checked-out branch would fail with git exit 128.
6791+ const result = yield * preparePullRequestThread ( manager , {
6792+ cwd : repoDir ,
6793+ reference : "78" ,
6794+ mode : "worktree" ,
6795+ } ) ;
6796+ expect ( result . worktreePath && NodeFS . realpathSync . native ( result . worktreePath ) ) . toBe (
6797+ NodeFS . realpathSync . native ( worktreePath ) ,
6798+ ) ;
6799+ expect ( result . branch ) . toBe ( localBranch ) ;
6800+ expect ( result . isOnPullRequestHead ) . toBe ( true ) ;
6801+ expect ( ( yield * runGit ( worktreePath , [ "branch" , "--show-current" ] ) ) . stdout . trim ( ) ) . toBe (
6802+ localBranch ,
6803+ ) ;
6804+ } ) ,
6805+ ) ;
6806+
67276807 it . effect ( "refreshes a reused PR worktree that has no upstream from the pull request ref" , ( ) =>
67286808 Effect . gen ( function * ( ) {
67296809 const repoDir = yield * makeTempDir ( "t3code-git-manager-" ) ;
0 commit comments