@@ -9,45 +9,56 @@ export class GitChangesProvider implements vscode.TreeDataProvider<CommitNode> {
99 readonly onDidChangeTreeData : vscode . Event < CommitNode | undefined | null | void > = this . _onDidChangeTreeData . event
1010 private gitService : GitService
1111 private fileTreeProvider : FileTreeProvider
12+ private selectedCommitHash ?: string
13+ private static instance : GitChangesProvider
1214
13- constructor ( ) {
15+ private constructor ( ) {
1416 this . gitService = new GitService ( )
1517 this . fileTreeProvider = new FileTreeProvider ( this . gitService )
1618 }
1719
18- refresh ( ) : void {
20+ static getInstance ( ) : GitChangesProvider {
21+ if ( ! GitChangesProvider . instance ) {
22+ GitChangesProvider . instance = new GitChangesProvider ( )
23+ }
24+ return GitChangesProvider . instance
25+ }
26+
27+ refresh ( commitHash ?: string ) : void {
28+ this . selectedCommitHash = commitHash
1929 this . _onDidChangeTreeData . fire ( )
2030 }
2131
2232 getTreeItem ( element : CommitNode ) : vscode . TreeItem {
2333 return element
2434 }
2535
26- private async getFirstCommitDetails ( ) : Promise < CommitDetails | null > {
36+ private async getCommitByHash ( hash ?: string ) : Promise < CommitDetails | null > {
2737 try {
2838 const history = await this . gitService . getHistory ( )
2939 if ( history . all . length === 0 ) {
3040 return null
3141 }
3242
33- const firstCommit = history . all [ 0 ]
43+ const commit = history . all . find ( c => c . hash === hash ) || history . all [ 0 ]
3444 return {
35- hash : firstCommit . hash ,
36- authorName : firstCommit . author_name ,
37- authorEmail : firstCommit . author_email ,
38- date : firstCommit . date ,
39- stats : firstCommit . stats ,
45+ hash : commit . hash ,
46+ authorName : commit . author_name ,
47+ authorEmail : commit . author_email ,
48+ date : commit . date ,
49+ stats : commit . stats ,
4050 }
4151 }
4252 catch ( error ) {
43- console . error ( 'Error getting first commit details:' , error )
53+ console . error ( 'Error getting commit details:' , error )
4454 return null
4555 }
4656 }
4757
4858 async getChildren ( element ?: CommitNode ) : Promise < CommitNode [ ] > {
4959 if ( ! element ) {
50- const commitDetails = await this . getFirstCommitDetails ( )
60+ const commitDetails = await this . getCommitByHash ( this . selectedCommitHash )
61+
5162 if ( ! commitDetails ) {
5263 return [ ]
5364 }
@@ -79,14 +90,14 @@ export class GitChangesProvider implements vscode.TreeDataProvider<CommitNode> {
7990 ) ,
8091 new CommitNode (
8192 'Changed Files' ,
82- 'Changed Files' ,
93+ ` ${ changedFiles . length } Files Changed` ,
8394 changedFiles . length > 0 ? vscode . TreeItemCollapsibleState . Expanded : vscode . TreeItemCollapsibleState . None ,
8495 'files' ,
85- changedFiles
96+ changedFiles ,
8697 ) ,
8798 ]
8899 }
89- else if ( element . label === 'Changed Files' && element . children ) {
100+ else if ( element . children ) {
90101 return element . children as CommitNode [ ]
91102 }
92103
0 commit comments