Browse Source

Adds Remotes view

main
Eric Amodio 4 years ago
parent
commit
3d865de84b
8 changed files with 516 additions and 15 deletions
  1. +184
    -0
      package.json
  2. +1
    -0
      src/config.ts
  3. +11
    -0
      src/container.ts
  4. +4
    -2
      src/views/nodes/branchNode.ts
  5. +8
    -7
      src/views/nodes/remoteNode.ts
  6. +6
    -5
      src/views/nodes/remotesNode.ts
  7. +292
    -0
      src/views/remotesView.ts
  8. +10
    -1
      src/views/viewBase.ts

+ 184
- 0
package.json View File

@ -1720,6 +1720,60 @@
"markdownDescription": "Specifies where to show the _Line History_ view",
"scope": "window"
},
"gitlens.views.remotes.avatars": {
"type": "boolean",
"default": true,
"markdownDescription": "Specifies whether to show avatar images instead of commit (or status) icons in the _Remotes_ view",
"scope": "window"
},
"gitlens.views.remotes.branches.layout": {
"type": "string",
"default": "tree",
"enum": [
"list",
"tree"
],
"enumDescriptions": [
"Displays branches as a list",
"Displays branches as a tree when branch names contain slashes `/`"
],
"markdownDescription": "Specifies how the _Remotes_ view will display branches",
"scope": "window"
},
"gitlens.views.remotes.files.compact": {
"type": "boolean",
"default": true,
"markdownDescription": "Specifies whether to compact (flatten) unnecessary file nesting in the _Remotes_ view. Only applies when `#gitlens.views.remotes.files.layout#` is set to `tree` or `auto`",
"scope": "window"
},
"gitlens.views.remotes.files.layout": {
"type": "string",
"default": "auto",
"enum": [
"auto",
"list",
"tree"
],
"enumDescriptions": [
"Automatically switches between displaying files as a `tree` or `list` based on the `#gitlens.views.remotes.files.threshold#` value and the number of files at each nesting level",
"Displays files as a list",
"Displays files as a tree"
],
"markdownDescription": "Specifies how the _Remotes_ view will display files",
"scope": "window"
},
"gitlens.views.remotes.files.threshold": {
"type": "number",
"default": 5,
"markdownDescription": "Specifies when to switch between displaying files as a `tree` or `list` based on the number of files in a nesting level in the _Remotes_ view. Only applies when `#gitlens.views.remotes.files.layout#` is set to `auto`",
"scope": "window"
},
"gitlens.views.remotes.showTrackingBranch": {
"type": "boolean",
"default": true,
"markdownDescription": "Specifies whether to show the tracking branch when displaying local branches in the _Remotes_ view",
"scope": "window"
},
"gitlens.views.repositories.autoRefresh": {
"type": "boolean",
"default": true,
@ -3587,6 +3641,60 @@
}
},
{
"command": "gitlens.views.remotes.copy",
"title": "Copy",
"category": "GitLens"
},
{
"command": "gitlens.views.remotes.refresh",
"title": "Refresh",
"category": "GitLens",
"icon": "$(refresh)"
},
{
"command": "gitlens.views.remotes.setLayoutToList",
"title": "Toggle Layout (Tree)",
"category": "GitLens",
"icon": "$(list-tree)"
},
{
"command": "gitlens.views.remotes.setLayoutToTree",
"title": "Toggle Layout (List)",
"category": "GitLens",
"icon": "$(list-flat)"
},
{
"command": "gitlens.views.remotes.setFilesLayoutToAuto",
"title": "Toggle File Layout (Tree)",
"category": "GitLens",
"icon": "$(list-tree)"
},
{
"command": "gitlens.views.remotes.setFilesLayoutToList",
"title": "Toggle File Layout (Auto)",
"category": "GitLens",
"icon": {
"dark": "images/dark/icon-view-auto.svg",
"light": "images/light/icon-view-auto.svg"
}
},
{
"command": "gitlens.views.remotes.setFilesLayoutToTree",
"title": "Toggle File Layout (List)",
"category": "GitLens",
"icon": "$(list-flat)"
},
{
"command": "gitlens.views.remotes.setShowAvatarsOn",
"title": "Show Avatars",
"category": "GitLens"
},
{
"command": "gitlens.views.remotes.setShowAvatarsOff",
"title": "Hide Avatars",
"category": "GitLens"
},
{
"command": "gitlens.views.search.copy",
"title": "Copy",
"category": "GitLens"
@ -4577,6 +4685,42 @@
"when": "false"
},
{
"command": "gitlens.views.remotes.copy",
"when": "false"
},
{
"command": "gitlens.views.remotes.refresh",
"when": "false"
},
{
"command": "gitlens.views.remotes.setLayoutToList",
"when": "false"
},
{
"command": "gitlens.views.remotes.setLayoutToTree",
"when": "false"
},
{
"command": "gitlens.views.remotes.setFilesLayoutToAuto",
"when": "false"
},
{
"command": "gitlens.views.remotes.setFilesLayoutToList",
"when": "false"
},
{
"command": "gitlens.views.remotes.setFilesLayoutToTree",
"when": "false"
},
{
"command": "gitlens.views.remotes.setShowAvatarsOn",
"when": "false"
},
{
"command": "gitlens.views.remotes.setShowAvatarsOff",
"when": "false"
},
{
"command": "gitlens.views.search.copy",
"when": "false"
},
@ -5359,6 +5503,46 @@
"group": "1_gitlens@0"
},
{
"command": "gitlens.views.remotes.setLayoutToList",
"when": "view =~ /gitlens\\.views\\.remotes/ && config.gitlens.views.remotes.branches.layout == tree",
"group": "navigation@1"
},
{
"command": "gitlens.views.remotes.setLayoutToTree",
"when": "view =~ /gitlens\\.views\\.remotes/ && config.gitlens.views.remotes.branches.layout == list",
"group": "navigation@1"
},
{
"command": "gitlens.views.remotes.setFilesLayoutToList",
"when": "view =~ /^gitlens\\.views\\.remotes/ && config.gitlens.views.remotes.files.layout == auto",
"group": "navigation@13"
},
{
"command": "gitlens.views.remotes.setFilesLayoutToTree",
"when": "view =~ /^gitlens\\.views\\.remotes/ && config.gitlens.views.remotes.files.layout == list",
"group": "navigation@13"
},
{
"command": "gitlens.views.remotes.setFilesLayoutToAuto",
"when": "view =~ /^gitlens\\.views\\.remotes/ && config.gitlens.views.remotes.files.layout == tree",
"group": "navigation@13"
},
{
"command": "gitlens.views.remotes.refresh",
"when": "view =~ /^gitlens\\.views\\.remotes/",
"group": "navigation@99"
},
{
"command": "gitlens.views.remotes.setShowAvatarsOn",
"when": "view =~ /^gitlens\\.views\\.remotes/ && !config.gitlens.views.remotes.avatars",
"group": "1_gitlens@0"
},
{
"command": "gitlens.views.remotes.setShowAvatarsOff",
"when": "view =~ /^gitlens\\.views\\.remotes/ && config.gitlens.views.remotes.avatars",
"group": "1_gitlens@0"
},
{
"command": "gitlens.views.tags.setLayoutToList",
"when": "view =~ /gitlens\\.views\\.tags/ && config.gitlens.views.tags.branches.layout == tree",
"group": "navigation@1"

+ 1
- 0
src/config.ts View File

@ -519,6 +519,7 @@ export interface RemotesViewConfig {
layout: ViewBranchesLayout;
};
files: ViewsFilesConfig;
showTrackingBranch: boolean;
}
export interface RepositoriesViewConfig {

+ 11
- 0
src/container.ts View File

@ -28,6 +28,7 @@ import { CompareView } from './views/compareView';
import { FileHistoryView } from './views/fileHistoryView';
import { HistoryView } from './views/historyView';
import { LineHistoryView } from './views/lineHistoryView';
import { RemotesView } from './views/remotesView';
import { RepositoriesView } from './views/repositoriesView';
import { SearchView } from './views/searchView';
import { TagsView } from './views/tagsView';
@ -67,6 +68,7 @@ export class Container {
context.subscriptions.push((this._branchesView = new BranchesView()));
context.subscriptions.push((this._historyView = new HistoryView()));
context.subscriptions.push((this._remotesView = new RemotesView()));
context.subscriptions.push((this._tagsView = new TagsView()));
if (config.views.compare.enabled) {
@ -286,6 +288,15 @@ export class Container {
return this._lineTracker;
}
private static _remotesView: RemotesView | undefined;
static get remotesView() {
if (this._remotesView === undefined) {
this._context.subscriptions.push((this._remotesView = new RemotesView()));
}
return this._remotesView;
}
private static _repositoriesView: RepositoriesView | undefined;
static get repositoriesView(): RepositoriesView {
if (this._repositoriesView === undefined) {

+ 4
- 2
src/views/nodes/branchNode.ts View File

@ -11,12 +11,14 @@ import { Container } from '../../container';
import { BranchDateFormatting, GitBranch, GitBranchReference, GitLog, GitRemoteType } from '../../git/git';
import { GitUri } from '../../git/gitUri';
import { insertDateMarkers } from './helpers';
import { RemotesView } from '../remotesView';
import { RepositoriesView } from '../repositoriesView';
import { RepositoryNode } from './repositoryNode';
import { debug, gate, Iterables, log, Strings } from '../../system';
import { ContextValues, PageableViewNode, ViewNode, ViewRefNode } from './viewNode';
export class BranchNode extends ViewRefNode<RepositoriesView | BranchesView | HistoryView, GitBranchReference>
export class BranchNode
extends ViewRefNode<BranchesView | HistoryView | RemotesView | RepositoriesView, GitBranchReference>
implements PageableViewNode {
static key = ':branch';
static getId(repoPath: string, name: string, root: boolean): string {
@ -32,7 +34,7 @@ export class BranchNode extends ViewRefNode
constructor(
uri: GitUri,
view: RepositoriesView | BranchesView | HistoryView,
view: BranchesView | HistoryView | RemotesView | RepositoriesView,
parent: ViewNode,
public readonly branch: GitBranch,
// Specifies that the node is shown as a root under the repository node

+ 8
- 7
src/views/nodes/remoteNode.ts View File

@ -1,19 +1,20 @@
'use strict';
import { TreeItem, TreeItemCollapsibleState } from 'vscode';
import { BranchNode } from './branchNode';
import { BranchOrTagFolderNode } from './branchOrTagFolderNode';
import { MessageNode } from './common';
import { ViewBranchesLayout } from '../../configuration';
import { GlyphChars } from '../../constants';
import { Container } from '../../container';
import { GitRemote, GitRemoteType, Repository } from '../../git/git';
import { GitUri } from '../../git/gitUri';
import { Arrays, log } from '../../system';
import { RemotesView } from '../remotesView';
import { RepositoriesView } from '../repositoriesView';
import { BranchNode } from './branchNode';
import { BranchOrTagFolderNode } from './branchOrTagFolderNode';
import { ContextValues, ViewNode } from './viewNode';
import { RepositoryNode } from './repositoryNode';
import { MessageNode } from './common';
import { Arrays, log } from '../../system';
import { ContextValues, ViewNode } from './viewNode';
export class RemoteNode extends ViewNode<RepositoriesView> {
export class RemoteNode extends ViewNode<RemotesView | RepositoriesView> {
static key = ':remote';
static getId(repoPath: string, name: string, id: string): string {
return `${RepositoryNode.getId(repoPath)}${this.key}(${name}|${id})`;
@ -21,7 +22,7 @@ export class RemoteNode extends ViewNode {
constructor(
uri: GitUri,
view: RepositoriesView,
view: RemotesView | RepositoriesView,
parent: ViewNode,
public readonly remote: GitRemote,
public readonly repo: Repository,

+ 6
- 5
src/views/nodes/remotesNode.ts View File

@ -1,21 +1,22 @@
'use strict';
import { TreeItem, TreeItemCollapsibleState } from 'vscode';
import { MessageNode } from './common';
import { Container } from '../../container';
import { Repository } from '../../git/git';
import { GitUri } from '../../git/gitUri';
import { RepositoriesView } from '../repositoriesView';
import { MessageNode } from './common';
import { RemoteNode } from './remoteNode';
import { ContextValues, ViewNode } from './viewNode';
import { RemotesView } from '../remotesView';
import { RepositoriesView } from '../repositoriesView';
import { RepositoryNode } from './repositoryNode';
import { ContextValues, ViewNode } from './viewNode';
export class RemotesNode extends ViewNode<RepositoriesView> {
export class RemotesNode extends ViewNode<RemotesView | RepositoriesView> {
static key = ':remotes';
static getId(repoPath: string): string {
return `${RepositoryNode.getId(repoPath)}${this.key}`;
}
constructor(uri: GitUri, view: RepositoriesView, parent: ViewNode, public readonly repo: Repository) {
constructor(uri: GitUri, view: RemotesView | RepositoriesView, parent: ViewNode, public readonly repo: Repository) {
super(uri, view, parent);
}

+ 292
- 0
src/views/remotesView.ts View File

@ -0,0 +1,292 @@
'use strict';
import {
CancellationToken,
commands,
ConfigurationChangeEvent,
ProgressLocation,
TreeItem,
TreeItemCollapsibleState,
window,
} from 'vscode';
import { configuration, RemotesViewConfig, ViewBranchesLayout, ViewFilesLayout } from '../configuration';
import { Container } from '../container';
import {
GitBranch,
GitBranchReference,
GitReference,
Repository,
RepositoryChange,
RepositoryChangeEvent,
} from '../git/git';
import { GitUri } from '../git/gitUri';
import {
BranchesNode,
BranchOrTagFolderNode,
ContextValues,
MessageNode,
RemoteNode,
RemotesNode,
RepositoriesNode,
RepositoryNode,
SubscribeableViewNode,
unknownGitUri,
ViewNode,
} from './nodes';
import { debug, gate } from '../system';
import { ViewBase } from './viewBase';
export class RemotesRepositoryNode extends SubscribeableViewNode<RemotesView> {
private child: RemotesNode | undefined;
constructor(
uri: GitUri,
view: RemotesView,
parent: ViewNode,
public readonly repo: Repository,
private readonly root: boolean,
) {
super(uri, view, parent);
}
async getChildren(): Promise<ViewNode[]> {
if (this.child == null) {
this.child = new RemotesNode(this.uri, this.view, this, this.repo);
void this.ensureSubscription();
}
return this.child.getChildren();
}
getTreeItem(): TreeItem {
const item = new TreeItem(
this.repo.formattedName ?? this.uri.repoPath ?? '',
TreeItemCollapsibleState.Expanded,
);
item.contextValue = ContextValues.RepositoryFolder;
void this.ensureSubscription();
return item;
}
@gate()
@debug()
async refresh(reset: boolean = false) {
await this.child?.triggerChange(reset);
await this.ensureSubscription();
}
@debug()
protected subscribe() {
return this.repo.onDidChange(this.onRepositoryChanged, this);
}
@debug({
args: {
0: (e: RepositoryChangeEvent) =>
`{ repository: ${e.repository ? e.repository.name : ''}, changes: ${e.changes.join()} }`,
},
})
private onRepositoryChanged(e: RepositoryChangeEvent) {
if (e.changed(RepositoryChange.Closed)) {
this.dispose();
void this.parent?.triggerChange(true);
return;
}
if (e.changed(RepositoryChange.Remotes)) {
void this.triggerChange(true);
if (this.root) {
void this.parent?.triggerChange(true);
}
}
}
}
export class RemotesViewNode extends ViewNode<RemotesView> {
private children: RemotesRepositoryNode[] | undefined;
constructor(view: RemotesView) {
super(unknownGitUri, view);
}
async getChildren(): Promise<ViewNode[]> {
if (this.children != null) {
for (const child of this.children) {
child.dispose?.();
}
this.children = undefined;
}
const repositories = await Container.git.getOrderedRepositories();
if (repositories.length === 0) return [new MessageNode(this.view, this, 'No remotes could be found.')];
const root = repositories.length === 1;
this.children = repositories.map(
r => new RemotesRepositoryNode(GitUri.fromRepoPath(r.path), this.view, this, r, root),
);
if (root) {
const [child] = this.children;
const remotes = await child.repo.getRemotes();
this.view.description = remotes.length === 0 ? undefined : `(${remotes.length})`;
return child.getChildren();
}
return this.children;
}
getTreeItem(): TreeItem {
const item = new TreeItem('Remotes', TreeItemCollapsibleState.Expanded);
return item;
}
}
export class RemotesView extends ViewBase<RemotesViewNode, RemotesViewConfig> {
protected readonly configKey = 'remotes';
constructor() {
super('gitlens.views.remotes', 'Remotes');
}
getRoot() {
return new RemotesViewNode(this);
}
protected registerCommands() {
void Container.viewCommands;
commands.registerCommand(
this.getQualifiedCommand('copy'),
() => commands.executeCommand('gitlens.views.copy', this.selection),
this,
);
commands.registerCommand(this.getQualifiedCommand('refresh'), () => this.refresh(true), this);
commands.registerCommand(
this.getQualifiedCommand('setLayoutToList'),
() => this.setLayout(ViewBranchesLayout.List),
this,
);
commands.registerCommand(
this.getQualifiedCommand('setLayoutToTree'),
() => this.setLayout(ViewBranchesLayout.Tree),
this,
);
commands.registerCommand(
this.getQualifiedCommand('setFilesLayoutToAuto'),
() => this.setFilesLayout(ViewFilesLayout.Auto),
this,
);
commands.registerCommand(
this.getQualifiedCommand('setFilesLayoutToList'),
() => this.setFilesLayout(ViewFilesLayout.List),
this,
);
commands.registerCommand(
this.getQualifiedCommand('setFilesLayoutToTree'),
() => this.setFilesLayout(ViewFilesLayout.Tree),
this,
);
commands.registerCommand(this.getQualifiedCommand('setShowAvatarsOn'), () => this.setShowAvatars(true), this);
commands.registerCommand(this.getQualifiedCommand('setShowAvatarsOff'), () => this.setShowAvatars(false), this);
}
protected filterConfigurationChanged(e: ConfigurationChangeEvent) {
const changed = super.filterConfigurationChanged(e);
if (
!changed &&
!configuration.changed(e, 'defaultDateFormat') &&
!configuration.changed(e, 'defaultDateSource') &&
!configuration.changed(e, 'defaultDateStyle') &&
!configuration.changed(e, 'defaultGravatarsStyle') &&
!configuration.changed(e, 'sortBranchesBy')
) {
return false;
}
return true;
}
protected onConfigurationChanged(e: ConfigurationChangeEvent) {
if (configuration.initializing(e)) {
this.initialize(undefined, { showCollapseAll: true });
}
if (!configuration.initializing(e) && this._root != null) {
void this.refresh(true);
}
}
findBranch(branch: GitBranchReference, token?: CancellationToken) {
if (!branch.remote) return undefined;
const repoNodeId = RepositoryNode.getId(branch.repoPath);
return this.findNode((n: any) => n.branch !== undefined && n.branch.ref === branch.ref, {
allowPaging: true,
maxDepth: 6,
canTraverse: n => {
// Only search for branch nodes in the same repo within BranchesNode
if (n instanceof RepositoriesNode) return true;
if (n instanceof RemoteNode) {
if (!n.id.startsWith(repoNodeId)) return false;
return branch.remote && n.remote.name === GitBranch.getRemote(branch.name); //branch.getRemoteName();
}
if (
n instanceof RepositoryNode ||
n instanceof BranchesNode ||
n instanceof RemotesNode ||
n instanceof BranchOrTagFolderNode
) {
return n.id.startsWith(repoNodeId);
}
return false;
},
token: token,
});
}
@gate(() => '')
revealBranch(
branch: GitBranchReference,
options?: {
select?: boolean;
focus?: boolean;
expand?: boolean | number;
},
) {
return window.withProgress(
{
location: ProgressLocation.Notification,
title: `Revealing ${GitReference.toString(branch, { icon: false })} in the Repositories view...`,
cancellable: true,
},
async (progress, token) => {
const node = await this.findBranch(branch, token);
if (node === undefined) return node;
await this.ensureRevealNode(node, options);
return node;
},
);
}
private setLayout(layout: ViewBranchesLayout) {
return configuration.updateEffective('views', this.configKey, 'branches', 'layout', layout);
}
private setFilesLayout(layout: ViewFilesLayout) {
return configuration.updateEffective('views', this.configKey, 'files', 'layout', layout);
}
private setShowAvatars(enabled: boolean) {
return configuration.updateEffective('views', this.configKey, 'avatars', enabled);
}
}

+ 10
- 1
src/views/viewBase.ts View File

@ -43,6 +43,7 @@ import { FileHistoryView } from './fileHistoryView';
import { LineHistoryView } from './lineHistoryView';
import { Logger } from '../logger';
import { PageableViewNode, ViewNode } from './nodes';
import { RemotesView } from './remotesView';
import { RepositoriesView } from './repositoriesView';
import { SearchView } from './searchView';
import { debug, Functions, log, Promises, Strings } from '../system';
@ -54,10 +55,18 @@ export type View =
| FileHistoryView
| HistoryView
| LineHistoryView
| RemotesView
| RepositoriesView
| SearchView
| TagsView;
export type ViewsWithFiles =
| BranchesView
| CompareView
| HistoryView
| RemotesView
| RepositoriesView
| SearchView
| TagsView;
export type ViewsWithFiles = BranchesView | CompareView | HistoryView | RepositoriesView | SearchView | TagsView;
export interface TreeViewNodeStateChangeEvent<T> extends TreeViewExpansionEvent<T> {
state: TreeItemCollapsibleState;

Loading…
Cancel
Save