@@ -59,10 +59,13 @@ const DEFAULT_TIMEOUT_MS = 30_000;
5959/** T3's record of the branch, named as on the host, that a branch was cut from. */
6060const branchBaseConfigKey = ( branch : string ) => `branch.${ branch } .t3-merge-base` ;
6161/**
62- * Where T3 kept that record before it had a key of its own, for every host alike: the GitHub
63- * CLI's key, which branches cut before then still carry instead.
62+ * T3's keys plus the GitHub CLI's `gh-merge-base`, where T3 kept the record for every host alike
63+ * before it had a key of its own; branches cut before then still carry it instead.
6464 */
65- const legacyBranchBaseConfigKey = ( branch : string ) => `branch.${ branch } .gh-merge-base` ;
65+ const branchBaseConfigPattern = ( branch : string ) => {
66+ const escapedBranch = branch . replace ( / [ . * + ? ^ $ { } ( ) | [ \] \\ ] / g, "\\$&" ) ;
67+ return `^branch\\.${ escapedBranch } \\.(t3-merge-base-ref|t3-merge-base|gh-merge-base)$` ;
68+ } ;
6669const gitProcesses = Semaphore . makeUnsafe ( 8 ) ;
6770const WORKTREE_REMOVE_TIMEOUT_MS = Duration . toMillis ( Duration . minutes ( 5 ) ) ;
6871const DEFAULT_MAX_OUTPUT_BYTES = 1_000_000 ;
@@ -1848,7 +1851,10 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
18481851 readonly knownOriginDefaultBranch ?: string | null ;
18491852 } ,
18501853 ) {
1851- const configuredBaseRef = yield * readConfigValue ( cwd , `branch.${ refName } .t3-merge-base-ref` ) ;
1854+ const { baseRef : configuredBaseRef , base : recordedBase } = yield * readBranchBaseConfig (
1855+ cwd ,
1856+ refName ,
1857+ ) ;
18521858 if (
18531859 configuredBaseRef ?. startsWith ( "refs/heads/" ) ||
18541860 configuredBaseRef ?. startsWith ( "refs/remotes/" )
@@ -1863,7 +1869,7 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
18631869 }
18641870 }
18651871
1866- const configuredBaseBranch = ( yield * readBranchBase ( cwd , refName ) ) ?? "" ;
1872+ const configuredBaseBranch = recordedBase ?? "" ;
18671873 const configuredBase = yield * resolveComparisonBaseRef ( cwd , configuredBaseBranch ) ;
18681874 if (
18691875 configuredBase !== null &&
@@ -3747,11 +3753,35 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
37473753 yield * createBranchAt ( "GitVcsDriver.createBranch" , input , "git branch create failed" ) ;
37483754 } ) ;
37493755
3756+ // The last value of a repeated key wins, as with `git config --get`.
3757+ const readBranchBaseConfig = Effect . fn ( "GitVcsDriver.readBranchBaseConfig" ) ( function * (
3758+ cwd : string ,
3759+ branch : string ,
3760+ ) {
3761+ const stdout = yield * runGitStdout (
3762+ "GitVcsDriver.readBranchBaseConfig" ,
3763+ cwd ,
3764+ [ "config" , "-z" , "--get-regexp" , branchBaseConfigPattern ( branch ) ] ,
3765+ true ,
3766+ ) ;
3767+ const values = new Map < string , string | null > ( ) ;
3768+ for ( const entry of stdout . split ( "\0" ) ) {
3769+ if ( entry . length === 0 ) continue ;
3770+ const newline = entry . indexOf ( "\n" ) ;
3771+ const key = newline < 0 ? entry : entry . slice ( 0 , newline ) ;
3772+ const value = newline < 0 ? "" : entry . slice ( newline + 1 ) . trim ( ) ;
3773+ values . set ( key . slice ( key . lastIndexOf ( "." ) + 1 ) , value . length > 0 ? value : null ) ;
3774+ }
3775+ return {
3776+ baseRef : values . get ( "t3-merge-base-ref" ) ?? null ,
3777+ base : values . get ( "t3-merge-base" ) ?? values . get ( "gh-merge-base" ) ?? null ,
3778+ } ;
3779+ } ) ;
3780+
37503781 const readBranchBase : GitVcsDriver . GitVcsDriver [ "Service" ] [ "readBranchBase" ] = Effect . fn (
37513782 "GitVcsDriver.readBranchBase" ,
37523783 ) ( function * ( cwd , branch ) {
3753- const base = yield * readConfigValue ( cwd , branchBaseConfigKey ( branch ) ) ;
3754- return base ?? ( yield * readConfigValue ( cwd , legacyBranchBaseConfigKey ( branch ) ) ) ;
3784+ return ( yield * readBranchBaseConfig ( cwd , branch ) ) . base ;
37553785 } ) ;
37563786
37573787 const resolveBranchBase = Effect . fn ( "GitVcsDriver.resolveBranchBase" ) ( function * (
0 commit comments