mirror of
https://github.com/ckaczor/vscode-gitlens.git
synced 2026-02-15 10:58:36 -05:00
Spits branch and status nodes into separate files
Removes status node for now
This commit is contained in:
29
src/views/branchHistoryNode.ts
Normal file
29
src/views/branchHistoryNode.ts
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
'use strict';
|
||||||
|
import { Iterables } from '../system';
|
||||||
|
import { ExtensionContext, TreeItem, TreeItemCollapsibleState } from 'vscode';
|
||||||
|
import { CommitNode } from './commitNode';
|
||||||
|
import { GlyphChars } from '../constants';
|
||||||
|
import { ExplorerNode, ResourceType } from './explorerNode';
|
||||||
|
import { GitBranch, GitService, GitUri } from '../gitService';
|
||||||
|
|
||||||
|
export class BranchHistoryNode extends ExplorerNode {
|
||||||
|
|
||||||
|
readonly resourceType: ResourceType = 'branch-history';
|
||||||
|
|
||||||
|
constructor(public branch: GitBranch, uri: GitUri, context: ExtensionContext, git: GitService) {
|
||||||
|
super(uri, context, git);
|
||||||
|
}
|
||||||
|
|
||||||
|
async getChildren(): Promise<CommitNode[]> {
|
||||||
|
const log = await this.git.getLogForRepo(this.uri.repoPath!, this.branch.name);
|
||||||
|
if (log === undefined) return [];
|
||||||
|
|
||||||
|
return [...Iterables.map(log.commits.values(), c => new CommitNode(c, this.uri, this.context, this.git))];
|
||||||
|
}
|
||||||
|
|
||||||
|
getTreeItem(): TreeItem {
|
||||||
|
const item = new TreeItem(`${this.branch.name}${this.branch.current ? ` ${GlyphChars.Dash} current` : ''}`, TreeItemCollapsibleState.Collapsed);
|
||||||
|
item.contextValue = this.resourceType;
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
}
|
||||||
28
src/views/branchesNode.ts
Normal file
28
src/views/branchesNode.ts
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
'use strict';
|
||||||
|
import { Iterables } from '../system';
|
||||||
|
import { ExtensionContext, TreeItem, TreeItemCollapsibleState } from 'vscode';
|
||||||
|
import { BranchHistoryNode } from './branchHistoryNode';
|
||||||
|
import { ExplorerNode, ResourceType } from './explorerNode';
|
||||||
|
import { GitService, GitUri } from '../gitService';
|
||||||
|
|
||||||
|
export class BranchesNode extends ExplorerNode {
|
||||||
|
|
||||||
|
readonly resourceType: ResourceType = 'branches';
|
||||||
|
|
||||||
|
constructor(uri: GitUri, context: ExtensionContext, git: GitService) {
|
||||||
|
super(uri, context, git);
|
||||||
|
}
|
||||||
|
|
||||||
|
async getChildren(): Promise<BranchHistoryNode[]> {
|
||||||
|
const branches = await this.git.getBranches(this.uri.repoPath!);
|
||||||
|
if (branches === undefined) return [];
|
||||||
|
|
||||||
|
return [...Iterables.filterMap(branches.sort(_ => _.current ? 0 : 1), b => b.remote ? undefined : new BranchHistoryNode(b, this.uri, this.context, this.git))];
|
||||||
|
}
|
||||||
|
|
||||||
|
getTreeItem(): TreeItem {
|
||||||
|
const item = new TreeItem(`Branches`, TreeItemCollapsibleState.Collapsed);
|
||||||
|
item.contextValue = this.resourceType;
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,9 +1,12 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
export * from './explorerNode';
|
export * from './explorerNode';
|
||||||
|
export * from './branchesNode';
|
||||||
|
export * from './branchHistoryNode';
|
||||||
export * from './commitFileNode';
|
export * from './commitFileNode';
|
||||||
export * from './commitNode';
|
export * from './commitNode';
|
||||||
export * from './fileHistoryNode';
|
export * from './fileHistoryNode';
|
||||||
export * from './repositoryNode';
|
export * from './repositoryNode';
|
||||||
export * from './stashCommitNode';
|
export * from './stashCommitNode';
|
||||||
export * from './stashNode';
|
export * from './stashNode';
|
||||||
|
export * from './statusNode';
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
import { Iterables, Strings } from '../system';
|
|
||||||
import { ExtensionContext, TreeItem, TreeItemCollapsibleState } from 'vscode';
|
import { ExtensionContext, TreeItem, TreeItemCollapsibleState } from 'vscode';
|
||||||
import { CommitNode } from './commitNode';
|
import { BranchesNode } from './branchesNode';
|
||||||
import { GlyphChars } from '../constants';
|
import { GlyphChars } from '../constants';
|
||||||
import { ExplorerNode, ResourceType } from './explorerNode';
|
import { ExplorerNode, ResourceType } from './explorerNode';
|
||||||
import { GitBranch, GitService, GitUri } from '../gitService';
|
import { GitService, GitUri } from '../gitService';
|
||||||
|
// import { StatusNode } from './statusNode';
|
||||||
|
|
||||||
export class RepositoryNode extends ExplorerNode {
|
export class RepositoryNode extends ExplorerNode {
|
||||||
|
|
||||||
@@ -17,7 +17,7 @@ export class RepositoryNode extends ExplorerNode {
|
|||||||
|
|
||||||
async getChildren(): Promise<ExplorerNode[]> {
|
async getChildren(): Promise<ExplorerNode[]> {
|
||||||
return [
|
return [
|
||||||
new StatusNode(this.uri, this.context, this.git),
|
// new StatusNode(this.uri, this.context, this.git),
|
||||||
new BranchesNode(this.uri, this.context, this.git)
|
new BranchesNode(this.uri, this.context, this.git)
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
@@ -28,76 +28,3 @@ export class RepositoryNode extends ExplorerNode {
|
|||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class BranchesNode extends ExplorerNode {
|
|
||||||
|
|
||||||
readonly resourceType: ResourceType = 'branches';
|
|
||||||
|
|
||||||
constructor(uri: GitUri, context: ExtensionContext, git: GitService) {
|
|
||||||
super(uri, context, git);
|
|
||||||
}
|
|
||||||
|
|
||||||
async getChildren(): Promise<BranchHistoryNode[]> {
|
|
||||||
const branches = await this.git.getBranches(this.uri.repoPath!);
|
|
||||||
if (branches === undefined) return [];
|
|
||||||
|
|
||||||
return [...Iterables.filterMap(branches.sort(_ => _.current ? 0 : 1), b => b.remote ? undefined : new BranchHistoryNode(b, this.uri, this.context, this.git))];
|
|
||||||
}
|
|
||||||
|
|
||||||
getTreeItem(): TreeItem {
|
|
||||||
const item = new TreeItem(`Branches`, TreeItemCollapsibleState.Collapsed);
|
|
||||||
item.contextValue = this.resourceType;
|
|
||||||
return item;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export class BranchHistoryNode extends ExplorerNode {
|
|
||||||
|
|
||||||
readonly resourceType: ResourceType = 'branch-history';
|
|
||||||
|
|
||||||
constructor(public branch: GitBranch, uri: GitUri, context: ExtensionContext, git: GitService) {
|
|
||||||
super(uri, context, git);
|
|
||||||
}
|
|
||||||
|
|
||||||
async getChildren(): Promise<CommitNode[]> {
|
|
||||||
const log = await this.git.getLogForRepo(this.uri.repoPath!, this.branch.name);
|
|
||||||
if (log === undefined) return [];
|
|
||||||
|
|
||||||
return [...Iterables.map(log.commits.values(), c => new CommitNode(c, this.uri, this.context, this.git))];
|
|
||||||
}
|
|
||||||
|
|
||||||
getTreeItem(): TreeItem {
|
|
||||||
const item = new TreeItem(`${this.branch.name}${this.branch.current ? ` ${GlyphChars.Dash} current` : ''}`, TreeItemCollapsibleState.Collapsed);
|
|
||||||
item.contextValue = this.resourceType;
|
|
||||||
return item;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export class StatusNode extends ExplorerNode {
|
|
||||||
|
|
||||||
readonly resourceType: ResourceType = 'status';
|
|
||||||
|
|
||||||
constructor(uri: GitUri, context: ExtensionContext, git: GitService) {
|
|
||||||
super(uri, context, git);
|
|
||||||
}
|
|
||||||
|
|
||||||
async getChildren(): Promise<ExplorerNode[]> {
|
|
||||||
return [];
|
|
||||||
// const status = await this.git.getStatusForRepo(this.uri.repoPath!);
|
|
||||||
// if (status === undefined) return [];
|
|
||||||
|
|
||||||
// return [...Iterables.map(status.files, b => new CommitFile(b, this.uri, this.context, this.git))];
|
|
||||||
}
|
|
||||||
|
|
||||||
async getTreeItem(): Promise<TreeItem> {
|
|
||||||
const status = await this.git.getStatusForRepo(this.uri.repoPath!);
|
|
||||||
let suffix = '';
|
|
||||||
if (status !== undefined) {
|
|
||||||
suffix = ` ${GlyphChars.Dash} ${GlyphChars.ArrowUp} ${status.state.ahead} ${GlyphChars.ArrowDown} ${status.state.behind} ${Strings.pad(GlyphChars.Dot, 1, 1)} ${status.branch} ${GlyphChars.ArrowLeftRight} ${status.upstream}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
const item = new TreeItem(`Status${suffix}`, TreeItemCollapsibleState.Collapsed);
|
|
||||||
item.contextValue = this.resourceType;
|
|
||||||
return item;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
34
src/views/statusNode.ts
Normal file
34
src/views/statusNode.ts
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
import { Strings } from '../system';
|
||||||
|
import { ExtensionContext, TreeItem, TreeItemCollapsibleState } from 'vscode';
|
||||||
|
import { GlyphChars } from '../constants';
|
||||||
|
import { ExplorerNode, ResourceType } from './explorerNode';
|
||||||
|
import { GitService, GitUri } from '../gitService';
|
||||||
|
|
||||||
|
export class StatusNode extends ExplorerNode {
|
||||||
|
|
||||||
|
readonly resourceType: ResourceType = 'status';
|
||||||
|
|
||||||
|
constructor(uri: GitUri, context: ExtensionContext, git: GitService) {
|
||||||
|
super(uri, context, git);
|
||||||
|
}
|
||||||
|
|
||||||
|
async getChildren(): Promise<ExplorerNode[]> {
|
||||||
|
return [];
|
||||||
|
// const status = await this.git.getStatusForRepo(this.uri.repoPath!);
|
||||||
|
// if (status === undefined) return [];
|
||||||
|
|
||||||
|
// return [...Iterables.map(status.files, b => new CommitFile(b, this.uri, this.context, this.git))];
|
||||||
|
}
|
||||||
|
|
||||||
|
async getTreeItem(): Promise<TreeItem> {
|
||||||
|
const status = await this.git.getStatusForRepo(this.uri.repoPath!);
|
||||||
|
let suffix = '';
|
||||||
|
if (status !== undefined) {
|
||||||
|
suffix = ` ${GlyphChars.Dash} ${GlyphChars.ArrowUp} ${status.state.ahead} ${GlyphChars.ArrowDown} ${status.state.behind} ${Strings.pad(GlyphChars.Dot, 1, 1)} ${status.branch} ${GlyphChars.ArrowLeftRight} ${status.upstream}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
const item = new TreeItem(`Status${suffix}`, TreeItemCollapsibleState.Collapsed);
|
||||||
|
item.contextValue = this.resourceType;
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user