@@ -2193,6 +2193,70 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
21932193 } ) ,
21942194 ) ;
21952195
2196+ it . effect ( "keeps local branch bases consistent when tags share their names" , ( ) =>
2197+ Effect . gen ( function * ( ) {
2198+ const cwd = yield * makeTmpDir ( ) ;
2199+ yield * initRepoWithCommit ( cwd ) ;
2200+ const driver = yield * GitVcsDriver . GitVcsDriver ;
2201+ yield * git ( cwd , [ "branch" , "-M" , "main" ] ) ;
2202+ const initialCommit = yield * git ( cwd , [ "rev-parse" , "HEAD" ] ) ;
2203+ yield * git ( cwd , [ "update-ref" , "refs/tags/main" , initialCommit ] ) ;
2204+ yield * git ( cwd , [ "update-ref" , "refs/tags/release/v2" , initialCommit ] ) ;
2205+ yield * writeTextFile ( cwd , "README.md" , "# test\nbase work\n" ) ;
2206+ yield * git ( cwd , [ "commit" , "-am" , "base work" ] ) ;
2207+ yield * git ( cwd , [ "branch" , "release/v2" , "HEAD" ] ) ;
2208+ yield * git ( cwd , [ "checkout" , "-b" , "feature/local-base" , "HEAD" ] ) ;
2209+ yield * writeTextFile ( cwd , "README.md" , "# test\nbase work\nfeature work\n" ) ;
2210+ yield * git ( cwd , [ "commit" , "-am" , "feature work" ] ) ;
2211+
2212+ for ( const configuredBase of [ undefined , "main" , "release/v2" ] ) {
2213+ if ( configuredBase !== undefined ) {
2214+ yield * git ( cwd , [ "config" , "branch.feature/local-base.gh-merge-base" , configuredBase ] ) ;
2215+ }
2216+ const baseRef = configuredBase ?? "main" ;
2217+ const status = yield * driver . statusDetailsLocal ( cwd , { includeBranchChanges : true } ) ;
2218+ assert . deepStrictEqual ( status . branchChanges , { baseRef, insertions : 1 , deletions : 0 } ) ;
2219+ assert . strictEqual ( status . aheadCount , 1 ) ;
2220+ const preview = yield * driver . getReviewDiffPreview ( { cwd } ) ;
2221+ const changes = preview . sources . find ( ( source ) => source . kind === "branch-range" ) ! ;
2222+ assert . strictEqual ( changes . baseRef , baseRef ) ;
2223+ assert . deepStrictEqual ( changes . files , [
2224+ { path : "README.md" , previousPath : null , additions : 1 , deletions : 0 } ,
2225+ ] ) ;
2226+ const scoped = yield * driver . getReviewDiffPreview ( {
2227+ cwd,
2228+ baseRef,
2229+ file : { path : "README.md" , previousPath : null , sourceKind : "branch-range" } ,
2230+ } ) ;
2231+ const scopedChanges = scoped . sources . find ( ( source ) => source . kind === "branch-range" ) ! ;
2232+ assert . deepStrictEqual ( scopedChanges . files , changes . files ) ;
2233+ assert . strictEqual ( scopedChanges . diff , changes . diff ) ;
2234+ const contents = yield * driver . getReviewDiffFileContents (
2235+ makeReviewDiffFileContentsInput ( cwd , {
2236+ sourceKind : "branch-range" ,
2237+ baseRef : changes . baseRef ,
2238+ headRef : "feature/local-base" ,
2239+ } ) ,
2240+ ) ;
2241+ assert . deepStrictEqual ( contents , {
2242+ oldContents : "# test\nbase work\n" ,
2243+ newContents : "# test\nbase work\nfeature work\n" ,
2244+ } ) ;
2245+ }
2246+
2247+ for ( const baseRef of [ "refs/tags/main" , initialCommit , "HEAD~2" ] ) {
2248+ const contents = yield * driver . getReviewDiffFileContents (
2249+ makeReviewDiffFileContentsInput ( cwd , {
2250+ sourceKind : "branch-range" ,
2251+ baseRef,
2252+ headRef : "feature/local-base" ,
2253+ } ) ,
2254+ ) ;
2255+ assert . strictEqual ( contents . oldContents , "# test\n" ) ;
2256+ }
2257+ } ) ,
2258+ ) ;
2259+
21962260 it . effect ( "Changes accepts an explicit base on a detached HEAD and rejects a bad one" , ( ) =>
21972261 Effect . gen ( function * ( ) {
21982262 const cwd = yield * makeTmpDir ( ) ;
0 commit comments