|
2 | 2 | import { Iterables } from '../system'; |
3 | 3 | import { Command, ExtensionContext, TreeItem, TreeItemCollapsibleState } from 'vscode'; |
4 | 4 | import { Commands, DiffWithPreviousCommandArgs } from '../commands'; |
5 | | -import { CommitFileNode } from './commitFileNode'; |
| 5 | +import { CommitFileNode, CommitFileNodeDisplayAs } from './commitFileNode'; |
6 | 6 | import { ExplorerNode, ResourceType } from './explorerNode'; |
7 | | -import { CommitFormatter, getGitStatusIcon, GitBranch, GitLogCommit, GitService, GitUri, ICommitFormatOptions } from '../gitService'; |
8 | | -import * as path from 'path'; |
| 7 | +import { CommitFormatter, GitBranch, GitLogCommit, GitService, GitUri, ICommitFormatOptions } from '../gitService'; |
9 | 8 |
|
10 | 9 | export class CommitNode extends ExplorerNode { |
11 | 10 |
|
12 | 11 | readonly resourceType: ResourceType = 'gitlens:commit'; |
13 | 12 |
|
14 | | - constructor(public readonly commit: GitLogCommit, private readonly template: string, protected readonly context: ExtensionContext, protected readonly git: GitService, public readonly branch?: GitBranch) { |
| 13 | + constructor( |
| 14 | + public readonly commit: GitLogCommit, |
| 15 | + protected readonly context: ExtensionContext, |
| 16 | + protected readonly git: GitService, |
| 17 | + public readonly branch?: GitBranch |
| 18 | + ) { |
15 | 19 | super(new GitUri(commit.uri, commit)); |
16 | 20 | } |
17 | 21 |
|
18 | 22 | async getChildren(): Promise<ExplorerNode[]> { |
19 | | - if (this.commit.type === 'file') Promise.resolve([]); |
20 | | - |
21 | 23 | const log = await this.git.getLogForRepo(this.commit.repoPath, this.commit.sha, 1); |
22 | 24 | if (log === undefined) return []; |
23 | 25 |
|
24 | 26 | const commit = Iterables.first(log.commits.values()); |
25 | 27 | if (commit === undefined) return []; |
26 | 28 |
|
27 | | - return [...Iterables.map(commit.fileStatuses, s => new CommitFileNode(s, commit, this.context, this.git, this.branch))]; |
| 29 | + return [...Iterables.map(commit.fileStatuses, s => new CommitFileNode(s, commit, this.context, this.git, CommitFileNodeDisplayAs.File, this.branch))]; |
28 | 30 | } |
29 | 31 |
|
30 | 32 | getTreeItem(): TreeItem { |
31 | | - const item = new TreeItem(CommitFormatter.fromTemplate(this.template, this.commit, { |
| 33 | + const item = new TreeItem(CommitFormatter.fromTemplate(this.git.config.gitExplorer.commitFormat, this.commit, { |
32 | 34 | truncateMessageAtNewLine: true, |
33 | 35 | dataFormat: this.git.config.defaultDateFormat |
34 | | - } as ICommitFormatOptions)); |
35 | | - |
36 | | - if (this.commit.type === 'file') { |
37 | | - item.collapsibleState = TreeItemCollapsibleState.None; |
38 | | - item.command = this.getCommand(); |
39 | | - const resourceType: ResourceType = 'gitlens:commit-file'; |
40 | | - item.contextValue = resourceType; |
| 36 | + } as ICommitFormatOptions), TreeItemCollapsibleState.Collapsed); |
41 | 37 |
|
42 | | - const icon = getGitStatusIcon(this.commit.status!); |
43 | | - item.iconPath = { |
44 | | - dark: this.context.asAbsolutePath(path.join('images', 'dark', icon)), |
45 | | - light: this.context.asAbsolutePath(path.join('images', 'light', icon)) |
46 | | - }; |
47 | | - } |
48 | | - else { |
49 | | - item.collapsibleState = TreeItemCollapsibleState.Collapsed; |
50 | | - item.contextValue = this.resourceType; |
51 | | - |
52 | | - item.iconPath = { |
53 | | - dark: this.context.asAbsolutePath('images/dark/icon-commit.svg'), |
54 | | - light: this.context.asAbsolutePath('images/light/icon-commit.svg') |
55 | | - }; |
56 | | - } |
| 38 | + item.contextValue = this.resourceType; |
| 39 | + item.iconPath = { |
| 40 | + dark: this.context.asAbsolutePath('images/dark/icon-commit.svg'), |
| 41 | + light: this.context.asAbsolutePath('images/light/icon-commit.svg') |
| 42 | + }; |
57 | 43 |
|
58 | 44 | return item; |
59 | 45 | } |
|
0 commit comments