@@ -271,13 +271,142 @@ export class DashboardWebviewProvider extends WebviewBase {
271271 }
272272
273273 private async switchToLocalTask ( branchName : string ) : Promise < void > {
274+ // Switch to the branch first
274275 await this . _taskManager . switchToLocalTask ( branchName ) ;
276+
277+ // Open the combined diff view for all changes in the branch
278+ await this . openBranchDiffView ( branchName ) ;
279+
275280 // Update dashboard to reflect current branch change
276281 setTimeout ( ( ) => {
277282 this . updateDashboard ( ) ;
278283 } , 500 ) ;
279284 }
280285
286+ private async openBranchDiffView ( branchName : string ) : Promise < void > {
287+ try {
288+ // Find the folder manager that has this branch
289+ const folderManager = this . _repositoriesManager . folderManagers . find ( fm =>
290+ fm . gitHubRepositories . length > 0
291+ ) ;
292+
293+ if ( ! folderManager ) {
294+ vscode . window . showErrorMessage ( 'No GitHub repository found in the current workspace.' ) ;
295+ return ;
296+ }
297+
298+ // Get the base branch (usually main or master)
299+ const baseBranch = await this . getDefaultBranch ( folderManager ) || 'main' ;
300+
301+ // Use git to get the list of changed files
302+ const changedFiles = await this . getChangedFilesInBranch ( folderManager , branchName , baseBranch ) ;
303+
304+ if ( changedFiles . length === 0 ) {
305+ vscode . window . showInformationMessage ( `No changes found in branch ${ branchName } ` ) ;
306+ return ;
307+ }
308+
309+ // Open the first changed file using the existing openDiff pattern
310+ // if (changedFiles.length > 0) {
311+ // const firstFile = changedFiles[0];
312+ // await this.openFileInDiffView(folderManager, firstFile, branchName, baseBranch);
313+ // }
314+
315+ // Position chat to the right
316+ await vscode . commands . executeCommand ( 'workbench.action.chat.open' , {
317+ location : vscode . ViewColumn . Two
318+ } ) ;
319+
320+ // Show info about other changed files
321+ if ( changedFiles . length > 1 ) {
322+ const otherFiles = changedFiles . slice ( 1 ) ;
323+ const action = await vscode . window . showInformationMessage (
324+ `Showing 1 of ${ changedFiles . length } changed files. ${ otherFiles . length } more files changed.` ,
325+ 'Show All Changes'
326+ ) ;
327+
328+ if ( action === 'Show All Changes' ) {
329+ // Open file explorer focused on the changed files
330+ await vscode . commands . executeCommand ( 'workbench.view.explorer' ) ;
331+ }
332+ }
333+
334+ } catch ( error ) {
335+ Logger . error ( `Failed to open branch diff view: ${ error } ` , DashboardWebviewProvider . ID ) ;
336+ vscode . window . showErrorMessage ( `Failed to open diff view for branch ${ branchName } : ${ error } ` ) ;
337+ }
338+ }
339+
340+ private async getDefaultBranch ( folderManager : FolderRepositoryManager ) : Promise < string | undefined > {
341+ try {
342+ // Try to get the default branch from the repository
343+ if ( folderManager . repository . getRefs ) {
344+ const refs = await folderManager . repository . getRefs ( { pattern : 'refs/remotes/origin' } ) ;
345+ const defaultRef = refs . find ( ref => ref . name === 'refs/remotes/origin/main' ) ||
346+ refs . find ( ref => ref . name === 'refs/remotes/origin/master' ) ;
347+ return defaultRef ?. name ?. split ( '/' ) . pop ( ) ;
348+ }
349+ return undefined ;
350+ } catch ( error ) {
351+ Logger . debug ( `Failed to get default branch: ${ error } ` , DashboardWebviewProvider . ID ) ;
352+ return undefined ;
353+ }
354+ }
355+
356+ private async getChangedFilesInBranch ( folderManager : FolderRepositoryManager , branchName : string , baseBranch : string ) : Promise < string [ ] > {
357+ try {
358+ // Use the repository's git interface to get changed files
359+ const repository = folderManager . repository ;
360+
361+ // Get the diff between base and target branch
362+ const diff = await repository . diffBetween ( 'refs/heads/' + baseBranch , 'refs/heads/' + branchName ) ;
363+ // Extract file paths from the diff
364+ return diff . map ( change => change . uri . fsPath ) ;
365+
366+
367+ } catch ( error ) {
368+ Logger . debug ( `Failed to get changed files via API: ${ error } ` , DashboardWebviewProvider . ID ) ;
369+ }
370+
371+ // Fallback: try to get changes using git status if on the branch
372+ try {
373+ const repository = folderManager . repository ;
374+ const changes = repository . state . workingTreeChanges . concat ( repository . state . indexChanges ) ;
375+ return changes . map ( change => change . uri . fsPath ) ;
376+ } catch ( fallbackError ) {
377+ Logger . debug ( `Fallback failed: ${ fallbackError } ` , DashboardWebviewProvider . ID ) ;
378+ return [ ] ;
379+ }
380+ }
381+
382+ private async openFileInDiffView ( folderManager : FolderRepositoryManager , filePath : string , branchName : string , baseBranch : string ) : Promise < void > {
383+ try {
384+ // Create URIs for the base and head versions of the file
385+ const baseUri = vscode . Uri . file ( filePath ) . with ( {
386+ scheme : 'git' ,
387+ query : `${ baseBranch } `
388+ } ) ;
389+ const headUri = vscode . Uri . file ( filePath ) . with ( {
390+ scheme : 'git' ,
391+ query : branchName
392+ } ) ;
393+
394+ // Use the same openDiff pattern as FileChangeNode
395+ const fileName = filePath . split ( '/' ) . pop ( ) || filePath ;
396+ await vscode . commands . executeCommand (
397+ 'vscode.diff' ,
398+ baseUri ,
399+ headUri ,
400+ `${ fileName } (${ baseBranch } ↔ ${ branchName } )` ,
401+ { viewColumn : vscode . ViewColumn . One }
402+ ) ;
403+
404+ } catch ( error ) {
405+ Logger . error ( `Failed to open file in diff view: ${ error } ` , DashboardWebviewProvider . ID ) ;
406+ throw error ;
407+ }
408+ }
409+
281410 private async getMilestoneIssues ( ) : Promise < IssueData [ ] > {
282411 try {
283412 const issuesMap = new Map < string , IssueData > ( ) ;
0 commit comments