@@ -91,6 +91,8 @@ interface FakeProviderScenario {
9191 prListOtherwise ?: ReadonlyArray < FakeChangeRequest > ;
9292 defaultBranch ?: string ;
9393 pullRequest ?: FakeChangeRequest ;
94+ /** The answer to a bare-number lookup in the checkout's own repository; null is not found. */
95+ pullRequestInCheckout ?: FakeChangeRequest | null ;
9496 repositoryCloneUrls ?: Record < string , { url : string ; sshUrl : string } > ;
9597 failWith ?: string ;
9698 failCause ?: unknown ;
@@ -492,7 +494,22 @@ function createFakeSourceControlProvider(scenario: FakeProviderScenario = {}): {
492494 ) ,
493495 getChangeRequest : ( input ) =>
494496 record ( input . cwd , { operation : "getChangeRequest" , reference : input . reference } ) . pipe (
495- Effect . map ( ( ) => toChangeRequest ( pullRequest ( ) ) ) ,
497+ Effect . flatMap ( ( ) => {
498+ const inCheckout =
499+ / ^ \d + $ / . test ( input . reference ) && scenario . pullRequestInCheckout !== undefined
500+ ? scenario . pullRequestInCheckout
501+ : pullRequest ( ) ;
502+ return inCheckout === null
503+ ? Effect . fail (
504+ new SourceControlProviderFailure ( {
505+ provider : kind ,
506+ operation : "getChangeRequest" ,
507+ cwd : input . cwd ,
508+ detail : "Not found." ,
509+ } ) ,
510+ )
511+ : Effect . succeed ( toChangeRequest ( inCheckout ) ) ;
512+ } ) ,
496513 ) ,
497514 getRepositoryCloneUrls : ( input ) =>
498515 record ( input . cwd , {
@@ -5304,6 +5321,7 @@ it.layer(layerGitManagerTest)("GitManager", (it) => {
53045321 state : "open" ,
53055322 isCrossRepository : false ,
53065323 } ,
5324+ pullRequestInCheckout : null ,
53075325 } ,
53085326 } ) ;
53095327
@@ -5344,6 +5362,7 @@ it.layer(layerGitManagerTest)("GitManager", (it) => {
53445362 state : "open" ,
53455363 isCrossRepository : false ,
53465364 } ,
5365+ pullRequestInCheckout : null ,
53475366 } ,
53485367 } ) ;
53495368
@@ -5360,6 +5379,57 @@ it.layer(layerGitManagerTest)("GitManager", (it) => {
53605379 } ) ,
53615380 ) ;
53625381
5382+ it . effect . each ( [
5383+ "https://github.com/acme/old-name/pull/7" ,
5384+ "https://github.com/acme/new-name/pull/7" ,
5385+ "feature/renamed" ,
5386+ ] ) ( "prepares a PR thread from %s in a checkout under a repository's old name" , ( reference ) =>
5387+ Effect . gen ( function * ( ) {
5388+ // The host redirects the old name, so only it knows the checkout is of the renamed repository.
5389+ const repoDir = yield * makeTempDir ( "t3code-git-manager-" ) ;
5390+ yield * initRepo ( repoDir ) ;
5391+ const remoteDir = yield * createBareRemote ( ) ;
5392+ yield * runGit ( repoDir , [ "remote" , "add" , "origin" , remoteDir ] ) ;
5393+ yield * configureVisibleRemoteUrlWithLocalRewrite (
5394+ repoDir ,
5395+ "origin" ,
5396+ "https://github.com/acme/old-name.git" ,
5397+ remoteDir ,
5398+ ) ;
5399+ yield * runGit ( repoDir , [ "push" , "-u" , "origin" , "main" ] ) ;
5400+ yield * runGit ( repoDir , [ "checkout" , "-b" , "feature/renamed" ] ) ;
5401+ NodeFS . writeFileSync ( NodePath . join ( repoDir , "renamed.txt" ) , "renamed\n" ) ;
5402+ yield * runGit ( repoDir , [ "add" , "renamed.txt" ] ) ;
5403+ yield * runGit ( repoDir , [ "commit" , "-m" , "Renamed repository PR branch" ] ) ;
5404+ yield * runGit ( repoDir , [ "push" , "origin" , "feature/renamed" ] ) ;
5405+ yield * runGit ( repoDir , [ "checkout" , "main" ] ) ;
5406+ yield * runGit ( repoDir , [ "branch" , "-D" , "feature/renamed" ] ) ;
5407+
5408+ const { manager } = yield * makeManager ( {
5409+ providerScenario : {
5410+ pullRequest : {
5411+ number : 7 ,
5412+ title : "Renamed repository PR" ,
5413+ url : "https://github.com/acme/new-name/pull/7" ,
5414+ baseRefName : "main" ,
5415+ headRefName : "feature/renamed" ,
5416+ state : "open" ,
5417+ isCrossRepository : false ,
5418+ headRepositoryNameWithOwner : "acme/new-name" ,
5419+ } ,
5420+ } ,
5421+ } ) ;
5422+
5423+ const result = yield * preparePullRequestThread ( manager , {
5424+ cwd : repoDir ,
5425+ reference,
5426+ mode : "local" ,
5427+ } ) ;
5428+
5429+ expect ( result . branch ) . toBe ( "feature/renamed" ) ;
5430+ } ) ,
5431+ ) ;
5432+
53635433 it . effect ( "prepares a worktree PR thread through an insteadOf shorthand remote" , ( ) =>
53645434 Effect . gen ( function * ( ) {
53655435 // `gh:` only names the repository once `insteadOf` rewrites it; the SSH command serves the
@@ -5734,6 +5804,7 @@ it.layer(layerGitManagerTest)("GitManager", (it) => {
57345804 headRepositoryNameWithOwner : "octocat/codething-mvp" ,
57355805 headRepositoryOwnerLogin : "octocat" ,
57365806 } ,
5807+ pullRequestInCheckout : null ,
57375808 } ;
57385809 const gitCommands : string [ ] = [ ] ;
57395810 const { manager } = yield * makeManager ( {
0 commit comments