@@ -42,30 +42,37 @@ export function activate(context: vscode.ExtensionContext) {
42
42
43
43
// For modified files, show diff between current commit and its parent
44
44
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 } ` )
50
56
return
51
57
}
52
58
}
53
59
54
60
// For added files, show the entire file content
55
61
if ( fileInfo . status === 'A' ) {
56
- const gitUri = toGitUri ( uri , commit , fileInfo )
62
+ const gitUri = toGitUri ( uri , commit )
57
63
await vscode . commands . executeCommand ( 'vscode.open' , gitUri )
58
64
}
59
65
} ) ,
60
66
)
61
67
}
62
68
63
69
// 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 {
65
71
return uri . with ( {
66
72
scheme : 'git' ,
73
+ path : uri . path ,
67
74
query : JSON . stringify ( {
68
- path : fileInfo . path ,
75
+ path : uri . path ,
69
76
ref,
70
77
} ) ,
71
78
} )
0 commit comments