66
77import * as pathLib from 'path' ;
88import * as vscode from 'vscode' ;
9+ import { Repository } from './api/api' ;
910import { GitErrorCodes } from './api/api1' ;
1011import { CommentReply , findActiveHandler , resolveCommentHandler } from './commentHandlerResolver' ;
1112import { COPILOT_LOGINS } from './common/copilot' ;
@@ -55,7 +56,7 @@ const DISCARD_CHANGES = vscode.l10n.t('Discard changes');
5556 * @param repository The git repository with uncommitted changes
5657 * @returns Promise<boolean> true if user chose to proceed (after staging/discarding), false if cancelled
5758 */
58- async function handleUncommittedChanges ( repository : any ) : Promise < boolean > {
59+ async function handleUncommittedChanges ( repository : Repository ) : Promise < boolean > {
5960 const hasWorkingTreeChanges = repository . state . workingTreeChanges . length > 0 ;
6061 const hasIndexChanges = repository . state . indexChanges . length > 0 ;
6162
@@ -520,19 +521,19 @@ export function registerCommands(
520521 ) ;
521522 }
522523
523- function isSourceControl ( x : any ) : x is any {
524+ function isSourceControl ( x : any ) : x is Repository {
524525 return ! ! x ?. rootUri ;
525526 }
526527
527528 context . subscriptions . push (
528529 vscode . commands . registerCommand (
529530 'pr.create' ,
530- async ( args ?: { repoPath : string ; compareBranch : string } | any ) => {
531+ async ( args ?: { repoPath : string ; compareBranch : string } | Repository ) => {
531532 // The arguments this is called with are either from the SCM view, or manually passed.
532533 if ( isSourceControl ( args ) ) {
533534 ( await chooseReviewManager ( args . rootUri . fsPath ) ) ?. createPullRequest ( ) ;
534535 } else {
535- ( await chooseReviewManager ( ( args as any ) ?. repoPath ) ) ?. createPullRequest ( ( args as any ) ?. compareBranch ) ;
536+ ( await chooseReviewManager ( args ?. repoPath ) ) ?. createPullRequest ( args ?. compareBranch ) ;
536537 }
537538 } ,
538539 ) ,
@@ -541,7 +542,7 @@ export function registerCommands(
541542 context . subscriptions . push (
542543 vscode . commands . registerCommand (
543544 'pr.pushAndCreate' ,
544- async ( args ?: any ) => {
545+ async ( args ?: any | Repository ) => {
545546 if ( isSourceControl ( args ) ) {
546547 const reviewManager = await chooseReviewManager ( args . rootUri . fsPath ) ;
547548 const folderManager = reposManager . getManagerForFile ( args . rootUri ) ;
@@ -576,7 +577,7 @@ export function registerCommands(
576577 }
577578
578579 let pullRequestModel : PullRequestModel ;
579- let repository : any | undefined ;
580+ let repository : Repository | undefined ;
580581
581582 if ( pr instanceof PRNode || pr instanceof RepositoryChangesNode ) {
582583 pullRequestModel = pr . pullRequestModel ;
@@ -654,75 +655,15 @@ export function registerCommands(
654655 ) ;
655656
656657 context . subscriptions . push (
657- vscode . commands . registerCommand ( 'pr.openCommitChanges' , async ( commitShaOrUrl : string , folderManager ?: FolderRepositoryManager ) => {
658- try {
659- // Extract commit SHA from GitHub URL if needed
660- let commitSha : string ;
661- if ( commitShaOrUrl . includes ( 'github.com' ) && commitShaOrUrl . includes ( '/commit/' ) ) {
662- const match = commitShaOrUrl . match ( / \/ c o m m i t \/ ( [ a - f 0 - 9 ] { 7 , 40 } ) / ) ;
663- if ( ! match ) {
664- vscode . window . showErrorMessage ( vscode . l10n . t ( 'Invalid commit URL: {0}' , commitShaOrUrl ) ) ;
665- return ;
666- }
667- commitSha = match [ 1 ] ;
668- } else {
669- commitSha = commitShaOrUrl ;
670- }
671-
672- // Use provided folder manager or try to find one for the active workspace
673- if ( ! folderManager ) {
674- folderManager = reposManager . folderManagers . find ( fm => fm . repository . rootUri . fsPath === vscode . workspace . workspaceFolders ?. [ 0 ] ?. uri . fsPath ) ;
675- if ( ! folderManager ) {
676- vscode . window . showErrorMessage ( vscode . l10n . t ( 'No repository found to show commit changes.' ) ) ;
677- return ;
678- }
679- }
680-
681- const repository = folderManager . repository ;
682-
683- // Get the changes for this commit
684- const changes = await repository . diffBetween ( commitSha + '^' , commitSha ) ;
685-
686- if ( changes . length === 0 ) {
687- vscode . window . showInformationMessage ( vscode . l10n . t ( 'No file changes found in commit {0}' , commitSha . substring ( 0 , 7 ) ) ) ;
688- return ;
689- }
690-
691- // Build arguments for vscode.changes command
692- const args : [ vscode . Uri , vscode . Uri | undefined , vscode . Uri | undefined ] [ ] = [ ] ;
693- for ( const change of changes ) {
694- // For each changed file, create URIs for before and after
695- const parentCommit = commitSha + '^' ;
696- let beforeUri : vscode . Uri | undefined ;
697- let afterUri : vscode . Uri | undefined ;
698-
699- if ( change . status === 7 ) { // DELETED
700- // File was deleted, show old version vs empty
701- beforeUri = change . uri . with ( { scheme : 'git' , authority : parentCommit } ) ;
702- afterUri = undefined ;
703- } else if ( change . status === 1 || change . status === 11 ) { // INDEX_ADDED || ADDED_BY_US
704- // File was added, show empty vs new version
705- beforeUri = undefined ;
706- afterUri = change . uri . with ( { scheme : 'git' , authority : commitSha } ) ;
707- } else {
708- // File was modified, show old vs new
709- beforeUri = change . uri . with ( { scheme : 'git' , authority : parentCommit } ) ;
710- afterUri = change . uri . with ( { scheme : 'git' , authority : commitSha } ) ;
711- }
712-
713- args . push ( [ change . uri , beforeUri , afterUri ] ) ;
714- }
715-
716- // Send telemetry
717- folderManager . telemetry . sendTelemetryEvent ( 'pr.openCommitChanges' ) ;
718-
719- // Open multi diff editor
720- return vscode . commands . executeCommand ( 'vscode.changes' , vscode . l10n . t ( 'Changes in Commit {0}' , commitSha . substring ( 0 , 7 ) ) , args ) ;
721-
722- } catch ( error ) {
723- Logger . error ( `Failed to open commit changes: ${ formatError ( error ) } ` , 'Commands' ) ;
724- vscode . window . showErrorMessage ( vscode . l10n . t ( 'Failed to open commit changes: {0}' , formatError ( error ) ) ) ;
658+ vscode . commands . registerCommand ( 'pr.openCommitChanges' , async ( commitSha : string , folderManager ?: FolderRepositoryManager ) => {
659+ if ( ! folderManager ) {
660+ folderManager = reposManager . folderManagers [ 0 ] ;
661+ }
662+ if ( ! folderManager ) {
663+ vscode . window . showErrorMessage ( vscode . l10n . t ( 'No repository found' ) ) ;
664+ return ;
725665 }
666+ return PullRequestModel . openCommitChanges ( folderManager , commitSha ) ;
726667 } ) ,
727668 ) ;
728669
0 commit comments