@@ -2669,12 +2669,20 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
26692669 }
26702670
26712671 // A deleted upstream keeps its config; republish to its remote when it was this branch's own.
2672- let goneUpstreamRemoteName : string | null = null ;
2672+ let goneUpstream : { remoteName : string ; branchName : string } | null = null ;
26732673 if ( ! details . hasUpstream ) {
2674- const publishBranch = yield * resolvePublishBranchName ( cwd , branch ) ;
26752674 const mergeRef = yield * readConfigValue ( cwd , `branch.${ branch } .merge` ) ;
2676- if ( mergeRef === `refs/heads/${ publishBranch } ` ) {
2677- goneUpstreamRemoteName = yield * readConfigValue ( cwd , `branch.${ branch } .remote` ) ;
2675+ const mergeBranch = mergeRef ?. startsWith ( "refs/heads/" )
2676+ ? mergeRef . slice ( "refs/heads/" . length )
2677+ : null ;
2678+ const remoteName = yield * readConfigValue ( cwd , `branch.${ branch } .remote` ) ;
2679+ if (
2680+ mergeBranch &&
2681+ remoteName &&
2682+ remoteName !== "." &&
2683+ ( mergeBranch === branch || mergeBranch === ( yield * resolvePublishBranchName ( cwd , branch ) ) )
2684+ ) {
2685+ goneUpstream = { remoteName, branchName : mergeBranch } ;
26782686 }
26792687 }
26802688
@@ -2695,7 +2703,7 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
26952703 const publishRemoteName = yield * resolvePushRemoteName (
26962704 cwd ,
26972705 branch ,
2698- goneUpstreamRemoteName ,
2706+ goneUpstream ?. remoteName ,
26992707 ) . pipe ( Effect . orElseSucceed ( ( ) => null ) ) ;
27002708 if ( ! publishRemoteName ) {
27012709 return {
@@ -2704,7 +2712,8 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
27042712 } ;
27052713 }
27062714
2707- const publishBranch = yield * resolvePublishBranchName ( cwd , branch ) ;
2715+ const publishBranch =
2716+ goneUpstream ?. branchName ?? ( yield * resolvePublishBranchName ( cwd , branch ) ) ;
27082717 // The configured diff base can contain HEAD while the publish branch is still behind.
27092718 const publishContainsHead = yield * executeGit (
27102719 "GitVcsDriver.pushCurrentBranch.publishContainsHead" ,
@@ -2730,7 +2739,7 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
27302739 }
27312740
27322741 if ( ! details . hasUpstream ) {
2733- const publishRemoteName = yield * resolvePushRemoteName ( cwd , branch , goneUpstreamRemoteName ) ;
2742+ const publishRemoteName = yield * resolvePushRemoteName ( cwd , branch , goneUpstream ?. remoteName ) ;
27342743 if ( ! publishRemoteName ) {
27352744 return yield * new GitCommandError ( {
27362745 ...gitCommandContext ( {
@@ -2741,7 +2750,8 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
27412750 detail : "Cannot push because no git remote is configured for this repository." ,
27422751 } ) ;
27432752 }
2744- const publishBranch = yield * resolvePublishBranchName ( cwd , branch ) ;
2753+ const publishBranch =
2754+ goneUpstream ?. branchName ?? ( yield * resolvePublishBranchName ( cwd , branch ) ) ;
27452755 yield * runGit (
27462756 "GitVcsDriver.pushCurrentBranch.pushWithUpstream" ,
27472757 cwd ,
0 commit comments