@@ -1967,24 +1967,47 @@ export const make = Effect.gen(function* () {
19671967 } ;
19681968 } ) ;
19691969
1970- const resolveBaseBranch = Effect . fn ( "resolveBaseBranch " ) ( function * (
1970+ const resolvePrBase = Effect . fn ( "resolvePrBase " ) ( function * (
19711971 cwd : string ,
19721972 branch : string ,
19731973 upstreamRef : string | null ,
19741974 headContext : Pick < BranchHeadContext , "isCrossRepository" | "remoteName" > ,
19751975 ) {
1976+ const configuredRef = yield * gitCore . readConfigValue ( cwd , `branch.${ branch } .t3-merge-base-ref` ) ;
1977+ if ( configuredRef ?. startsWith ( "refs/heads/" ) || configuredRef ?. startsWith ( "refs/remotes/" ) ) {
1978+ const configuredBranch = yield * gitCore . resolveBranchName ( cwd , configuredRef ) ;
1979+ if ( configuredBranch ) return { baseBranch : configuredBranch , baseRef : configuredRef } ;
1980+ }
1981+
19761982 const configured = yield * gitCore . readConfigValue ( cwd , `branch.${ branch } .gh-merge-base` ) ;
19771983 if ( configured ) {
1984+ const localRef = configured . startsWith ( "refs/" ) ? configured : `refs/heads/${ configured } ` ;
1985+ const localBranch = yield * gitCore . resolveBranchName ( cwd , localRef ) ;
1986+ if ( localBranch ) {
1987+ const shadowsRemote =
1988+ configured . includes ( "/" ) &&
1989+ ! configured . startsWith ( "refs/" ) &&
1990+ ( yield * gitCore . resolveBranchName ( cwd , `refs/remotes/${ configured } ` ) ) !== null ;
1991+ return {
1992+ baseBranch : localBranch ,
1993+ baseRef : configured . startsWith ( "refs/" ) || shadowsRemote ? localRef : localBranch ,
1994+ } ;
1995+ }
1996+ if ( configured . includes ( "/" ) && ! configured . startsWith ( "refs/" ) ) {
1997+ const remoteRef = `refs/remotes/${ configured } ` ;
1998+ const remoteBranch = yield * gitCore . resolveBranchName ( cwd , remoteRef ) ;
1999+ if ( remoteBranch ) return { baseBranch : remoteBranch , baseRef : remoteRef } ;
2000+ }
19782001 const configuredBranch = yield * gitCore . resolveBranchName ( cwd , configured ) ;
1979- if ( configuredBranch ) return configuredBranch ;
2002+ if ( configuredBranch ) return { baseBranch : configuredBranch , baseRef : configuredBranch } ;
19802003 }
19812004
19822005 if ( upstreamRef && ! headContext . isCrossRepository ) {
19832006 const upstreamBranch = extractBranchNameFromRemoteRef ( upstreamRef , {
19842007 remoteName : headContext . remoteName ,
19852008 } ) ;
19862009 if ( upstreamBranch . length > 0 && upstreamBranch !== branch ) {
1987- return upstreamBranch ;
2010+ return { baseBranch : upstreamBranch , baseRef : upstreamBranch } ;
19882011 }
19892012 }
19902013
@@ -1993,24 +2016,25 @@ export const make = Effect.gen(function* () {
19932016 Effect . orElseSucceed ( ( ) => null ) ,
19942017 ) ;
19952018 if ( defaultFromProvider ) {
1996- return defaultFromProvider ;
2019+ return { baseBranch : defaultFromProvider , baseRef : defaultFromProvider } ;
19972020 }
19982021
19992022 const defaultFromRemote = yield * gitCore . resolvePrimaryRemoteName ( cwd ) . pipe (
20002023 Effect . flatMap ( ( remoteName ) => gitCore . resolveDefaultBranchName ( cwd , remoteName ) ) ,
20012024 Effect . orElseSucceed ( ( ) => null ) ,
20022025 ) ;
20032026 if ( defaultFromRemote ) {
2004- return defaultFromRemote ;
2027+ return { baseBranch : defaultFromRemote , baseRef : defaultFromRemote } ;
20052028 }
20062029
2007- return "main" ;
2030+ return { baseBranch : "main" , baseRef : "main" } ;
20082031 } ) ;
20092032
20102033 const resolveBaseRangeRef = Effect . fn ( "resolveBaseRangeRef" ) ( function * (
20112034 cwd : string ,
20122035 baseBranch : string ,
20132036 ) {
2037+ if ( baseBranch . startsWith ( "refs/" ) ) return baseBranch ;
20142038 const remoteName = yield * gitCore
20152039 . resolvePrimaryRemoteName ( cwd )
20162040 . pipe ( Effect . orElseSucceed ( ( ) => null ) ) ;
@@ -2235,13 +2259,18 @@ export const make = Effect.gen(function* () {
22352259 } ;
22362260 }
22372261
2238- const baseBranch = yield * resolveBaseBranch ( cwd , branch , details . upstreamRef , headContext ) ;
2262+ const { baseBranch, baseRef } = yield * resolvePrBase (
2263+ cwd ,
2264+ branch ,
2265+ details . upstreamRef ,
2266+ headContext ,
2267+ ) ;
22392268 yield * emit ( {
22402269 kind : "phase_started" ,
22412270 phase : "pr" ,
22422271 label : `Generating ${ terms . shortLabel } content...` ,
22432272 } ) ;
2244- const baseRangeRef = yield * resolveBaseRangeRef ( cwd , baseBranch ) ;
2273+ const baseRangeRef = yield * resolveBaseRangeRef ( cwd , baseRef ) ;
22452274 const rangeContext = yield * gitCore . readRangeContext ( cwd , baseRangeRef ) ;
22462275 const policy = yield * resolveStylePolicy ( cwd , settings ) ;
22472276 const changeRequestTemplate =
0 commit comments