@@ -42,30 +42,37 @@ export function activate(context: vscode.ExtensionContext) {
4242
4343 // For modified files, show diff between current commit and its parent
4444 if ( fileInfo . status === 'M' ) {
45- const parentCommit = await gitService . getParentCommit ( commit )
46- if ( parentCommit ) {
47- const leftUri = toGitUri ( uri , parentCommit , fileInfo )
48- const rightUri = toGitUri ( uri , commit , fileInfo )
49- await vscode . commands . executeCommand ( 'vscode.diff' , leftUri , rightUri , title )
45+ try {
46+ const parentCommit = await gitService . getParentCommit ( commit )
47+ if ( parentCommit ) {
48+ const leftUri = toGitUri ( uri , parentCommit )
49+ const rightUri = toGitUri ( uri , commit )
50+ await vscode . commands . executeCommand ( 'vscode.diff' , leftUri , rightUri , title )
51+ return
52+ }
53+ }
54+ catch ( error ) {
55+ vscode . window . showErrorMessage ( `无法获取父提交: ${ error } ` )
5056 return
5157 }
5258 }
5359
5460 // For added files, show the entire file content
5561 if ( fileInfo . status === 'A' ) {
56- const gitUri = toGitUri ( uri , commit , fileInfo )
62+ const gitUri = toGitUri ( uri , commit )
5763 await vscode . commands . executeCommand ( 'vscode.open' , gitUri )
5864 }
5965 } ) ,
6066 )
6167}
6268
6369// Helper function to create Git URIs
64- function toGitUri ( uri : vscode . Uri , ref : string , fileInfo : { path : string } ) : vscode . Uri {
70+ function toGitUri ( uri : vscode . Uri , ref : string ) : vscode . Uri {
6571 return uri . with ( {
6672 scheme : 'git' ,
73+ path : uri . path ,
6774 query : JSON . stringify ( {
68- path : fileInfo . path ,
75+ path : uri . path ,
6976 ref,
7077 } ) ,
7178 } )
0 commit comments