@@ -5033,20 +5033,27 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
50335033 ) ;
50345034
50355035 it . effect (
5036- "hands back a clean PR head after provider refusal when fetching its head succeeds " ,
5036+ "passes up provider refusal on the PR branch when its head is already checked out " ,
50375037 ( ) =>
50385038 Effect . gen ( function * ( ) {
5039+ const providerFailure = new Error ( "provider refused checkout" ) ;
50395040 const { repoDir, headBranch, c1, checkout } = yield * makeLocalPullRequestFixture ( {
50405041 prCheckout : ( ) => {
5041- throw new Error ( "provider refused checkout" ) ;
5042+ throw providerFailure ;
50425043 } ,
50435044 } ) ;
50445045 yield * runGit ( repoDir , [ "branch" , "--unset-upstream" ] ) ;
50455046
5046- const result = yield * checkout ( ) ;
5047+ const error = yield * checkout ( ) . pipe ( Effect . flip ) ;
50475048
5048- expect ( result . branch ) . toBe ( headBranch ) ;
5049- expect ( result . isOnPullRequestHead ) . toBe ( true ) ;
5049+ expect ( error ) . toMatchObject ( {
5050+ _tag : "SourceControlProviderError" ,
5051+ operation : "checkoutChangeRequest" ,
5052+ cause : { _tag : "GitHubCliCommandError" , cause : providerFailure } ,
5053+ } ) ;
5054+ expect ( ( yield * runGit ( repoDir , [ "branch" , "--show-current" ] ) ) . stdout . trim ( ) ) . toBe (
5055+ headBranch ,
5056+ ) ;
50505057 expect ( ( yield * runGit ( repoDir , [ "rev-parse" , "HEAD" ] ) ) . stdout . trim ( ) ) . toBe ( c1 ) ;
50515058 expect (
50525059 ( yield * runGit ( repoDir , [ "rev-parse" , "--abbrev-ref" , "@{upstream}" ] ) ) . stdout . trim ( ) ,
@@ -5055,6 +5062,33 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
50555062 } ) ,
50565063 ) ;
50575064
5065+ it . effect (
5066+ "hands back a clean PR branch behind its head after provider refusal without moving it" ,
5067+ ( ) =>
5068+ Effect . gen ( function * ( ) {
5069+ const { repoDir, headBranch, c1, checkout } = yield * makeLocalPullRequestFixture ( {
5070+ prCheckout : ( cwd ) => {
5071+ runGitSyncForFakeGh ( cwd , [ "checkout" , "feature/pr-local-keeps-work" ] ) ;
5072+ throw new Error ( "provider refused checkout" ) ;
5073+ } ,
5074+ } ) ;
5075+ const c2 = yield * advanceLocalPullRequestRemote ( repoDir ) ;
5076+ yield * runGit ( repoDir , [ "checkout" , "main" ] ) ;
5077+
5078+ const result = yield * checkout ( ) ;
5079+
5080+ expect ( result . branch ) . toBe ( headBranch ) ;
5081+ expect ( result . worktreePath ) . toBeNull ( ) ;
5082+ expect ( result . isOnPullRequestHead ) . toBe ( false ) ;
5083+ expect ( ( yield * runGit ( repoDir , [ "branch" , "--show-current" ] ) ) . stdout . trim ( ) ) . toBe (
5084+ headBranch ,
5085+ ) ;
5086+ expect ( ( yield * runGit ( repoDir , [ "rev-parse" , "HEAD" ] ) ) . stdout . trim ( ) ) . toBe ( c1 ) ;
5087+ expect ( ( yield * runGit ( repoDir , [ "rev-parse" , "@{upstream}" ] ) ) . stdout . trim ( ) ) . toBe ( c2 ) ;
5088+ expect ( ( yield * runGit ( repoDir , [ "status" , "--porcelain" ] ) ) . stdout ) . toBe ( "" ) ;
5089+ } ) ,
5090+ ) ;
5091+
50585092 it . effect ( "preserves an ignored file that a local PR fast-forward would overwrite" , ( ) =>
50595093 Effect . gen ( function * ( ) {
50605094 const repoDir = yield * makeTempDir ( "t3code-git-manager-" ) ;
0 commit comments