@@ -13,6 +13,7 @@ export type DiffType =
1313 | "unstaged"
1414 | "last-commit"
1515 | "branch"
16+ | "merge-base"
1617 | `worktree:${string } `
1718 | "p4-default"
1819 | `p4-changelist:${string } `;
@@ -150,6 +151,7 @@ export async function getGitContext(
150151
151152 if ( currentBranch !== defaultBranch ) {
152153 diffOptions . push ( { id : "branch" , label : `vs ${ defaultBranch } ` } ) ;
154+ diffOptions . push ( { id : "merge-base" , label : `Current PR Diff` } ) ;
153155 }
154156
155157 const [ worktrees , currentTreePathResult ] = await Promise . all ( [
@@ -385,6 +387,28 @@ export async function runGitDiff(
385387 break ;
386388 }
387389
390+ case "merge-base" : {
391+ const mergeBaseResult = assertGitSuccess (
392+ await runtime . runGit ( [ "merge-base" , defaultBranch , "HEAD" ] , { cwd } ) ,
393+ [ "merge-base" , defaultBranch , "HEAD" ] ,
394+ ) ;
395+ const mergeBase = mergeBaseResult . stdout . trim ( ) ;
396+ const mergeBaseDiffArgs = [
397+ "diff" ,
398+ "--no-ext-diff" ,
399+ `${ mergeBase } ..HEAD` ,
400+ "--src-prefix=a/" ,
401+ "--dst-prefix=b/" ,
402+ ] ;
403+ const mergeBaseDiff = assertGitSuccess (
404+ await runtime . runGit ( mergeBaseDiffArgs , { cwd } ) ,
405+ mergeBaseDiffArgs ,
406+ ) ;
407+ patch = mergeBaseDiff . stdout ;
408+ label = `PR diff vs ${ defaultBranch } ` ;
409+ break ;
410+ }
411+
388412 default :
389413 return { patch : "" , label : "Unknown diff type" } ;
390414 }
@@ -474,6 +498,14 @@ export async function getFileContentsForDiff(
474498 oldContent : await gitShow ( defaultBranch , oldFilePath ) ,
475499 newContent : await gitShow ( "HEAD" , filePath ) ,
476500 } ;
501+ case "merge-base" : {
502+ const mbResult = await runtime . runGit ( [ "merge-base" , defaultBranch , "HEAD" ] , { cwd } ) ;
503+ const mb = mbResult . exitCode === 0 ? mbResult . stdout . trim ( ) : defaultBranch ;
504+ return {
505+ oldContent : await gitShow ( mb , oldFilePath ) ,
506+ newContent : await gitShow ( "HEAD" , filePath ) ,
507+ } ;
508+ }
477509 default :
478510 return { oldContent : null , newContent : null } ;
479511 }
0 commit comments