@@ -1732,6 +1732,7 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
17321732 const resolvePushRemoteName = Effect . fn ( "resolvePushRemoteName" ) ( function * (
17331733 cwd : string ,
17341734 refName : string ,
1735+ fallbackRemoteName : string | null = null ,
17351736 ) {
17361737 const branchPushRemote = yield * runGitStdout (
17371738 "GitVcsDriver.resolvePushRemoteName.branchPushRemote" ,
@@ -1753,6 +1754,10 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
17531754 return pushDefaultRemote ;
17541755 }
17551756
1757+ if ( fallbackRemoteName ) {
1758+ return fallbackRemoteName ;
1759+ }
1760+
17561761 return yield * resolvePrimaryRemoteName ( cwd ) . pipe ( Effect . orElseSucceed ( ( ) => null ) ) ;
17571762 } ) ;
17581763
@@ -2663,6 +2668,16 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
26632668 } ;
26642669 }
26652670
2671+ // A deleted upstream keeps its config; republish to its remote when it was this branch's own.
2672+ let goneUpstreamRemoteName : string | null = null ;
2673+ if ( ! details . hasUpstream ) {
2674+ const publishBranch = yield * resolvePublishBranchName ( cwd , branch ) ;
2675+ const mergeRef = yield * readConfigValue ( cwd , `branch.${ branch } .merge` ) ;
2676+ if ( mergeRef === `refs/heads/${ publishBranch } ` ) {
2677+ goneUpstreamRemoteName = yield * readConfigValue ( cwd , `branch.${ branch } .remote` ) ;
2678+ }
2679+ }
2680+
26662681 const hasNoLocalDelta = details . aheadCount === 0 && details . behindCount === 0 ;
26672682 if ( hasNoLocalDelta ) {
26682683 if ( details . hasUpstream ) {
@@ -2677,9 +2692,11 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
26772692 Effect . orElseSucceed ( ( ) => null ) ,
26782693 ) ;
26792694 if ( comparableBaseBranch ) {
2680- const publishRemoteName = yield * resolvePushRemoteName ( cwd , branch ) . pipe (
2681- Effect . orElseSucceed ( ( ) => null ) ,
2682- ) ;
2695+ const publishRemoteName = yield * resolvePushRemoteName (
2696+ cwd ,
2697+ branch ,
2698+ goneUpstreamRemoteName ,
2699+ ) . pipe ( Effect . orElseSucceed ( ( ) => null ) ) ;
26832700 if ( ! publishRemoteName ) {
26842701 return {
26852702 status : "skipped_up_to_date" as const ,
@@ -2713,7 +2730,7 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
27132730 }
27142731
27152732 if ( ! details . hasUpstream ) {
2716- const publishRemoteName = yield * resolvePushRemoteName ( cwd , branch ) ;
2733+ const publishRemoteName = yield * resolvePushRemoteName ( cwd , branch , goneUpstreamRemoteName ) ;
27172734 if ( ! publishRemoteName ) {
27182735 return yield * new GitCommandError ( {
27192736 ...gitCommandContext ( {
0 commit comments