Skip to content

Commit 8d41664

Browse files
committed
Aligns Repositories view with other views
Adds more customization options to Repositories view
1 parent 146cd56 commit 8d41664

20 files changed

+1109
-349
lines changed

README.md

Lines changed: 37 additions & 27 deletions
Large diffs are not rendered by default.

package.json

Lines changed: 351 additions & 18 deletions
Large diffs are not rendered by default.

src/config.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ export interface BranchesViewConfig {
485485
showForBranches: boolean;
486486
showForCommits: boolean;
487487
};
488-
showBranchComparison: false | ViewShowBranchComparison;
488+
showBranchComparison: false | ViewShowBranchComparison.Branch;
489489
}
490490

491491
export interface CommitsViewConfig {
@@ -537,6 +537,7 @@ export interface RepositoriesViewConfig {
537537
avatars: boolean;
538538
branches: {
539539
layout: ViewBranchesLayout;
540+
showBranchComparison: false | ViewShowBranchComparison.Branch;
540541
};
541542
compact: boolean;
542543
enabled: boolean;
@@ -548,6 +549,14 @@ export interface RepositoriesViewConfig {
548549
showForCommits: boolean;
549550
};
550551
showBranchComparison: false | ViewShowBranchComparison;
552+
showBranches: boolean;
553+
showCommits: boolean;
554+
showContributors: boolean;
555+
showIncomingActivity: boolean;
556+
showRemotes: boolean;
557+
showStashes: boolean;
558+
showTags: boolean;
559+
showUpstreamStatus: boolean;
551560
}
552561

553562
export interface SearchAndCompareViewConfig {

src/views/branchesView.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ export class BranchesView extends ViewBase<BranchesViewNode, BranchesViewConfig>
323323
'views',
324324
this.configKey,
325325
'showBranchComparison',
326-
enabled ? ViewShowBranchComparison.Working : false,
326+
enabled ? ViewShowBranchComparison.Branch : false,
327327
);
328328
}
329329

src/views/commitsView.ts

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
commands,
55
ConfigurationChangeEvent,
66
Disposable,
7+
MarkdownString,
78
ProgressLocation,
89
TreeItem,
910
TreeItemCollapsibleState,
@@ -88,9 +89,9 @@ export class CommitsRepositoryNode extends RepositoryFolderNode<CommitsView, Bra
8889
const lastFetched = (await this.repo?.getLastFetched()) ?? 0;
8990

9091
const status = branch?.getTrackingStatus();
91-
item.description = `${status ? `${status} ${GlyphChars.Dot} ` : ''}${branch.name}${
92+
item.description = `${status ? `${status}${Strings.pad(GlyphChars.Dot, 1, 1)}` : ''}${branch.name}${
9293
lastFetched
93-
? `${Strings.pad(GlyphChars.Dot, 2, 2)}Last fetched ${Repository.formatLastFetched(lastFetched)}`
94+
? `${Strings.pad(GlyphChars.Dot, 1, 1)}Last fetched ${Repository.formatLastFetched(lastFetched)}`
9495
: ''
9596
}`;
9697

@@ -103,23 +104,31 @@ export class CommitsRepositoryNode extends RepositoryFolderNode<CommitsView, Bra
103104
providerName = remote?.provider?.name;
104105
}
105106

106-
item.tooltip = `${this.repo.formattedName ?? this.uri.repoPath ?? ''}${
107-
lastFetched
108-
? `${Strings.pad(GlyphChars.Dash, 2, 2)}Last fetched ${Repository.formatLastFetched(
109-
lastFetched,
110-
false,
111-
)}`
112-
: ''
113-
}${this.repo.formattedName ? `\n${this.uri.repoPath}` : ''}\n\nBranch ${branch.name}${
114-
branch.tracking
115-
? ` is ${branch.getTrackingStatus({
116-
empty: `up to date with ${branch.tracking}${providerName ? ` on ${providerName}` : ''}`,
117-
expand: true,
118-
separator: ', ',
119-
suffix: ` ${branch.tracking}${providerName ? ` on ${providerName}` : ''}`,
120-
})}`
121-
: `hasn't been published to ${providerName ?? 'a remote'}`
122-
}`;
107+
item.tooltip = new MarkdownString(
108+
`${this.repo.formattedName ?? this.uri.repoPath ?? ''}${
109+
lastFetched
110+
? `${Strings.pad(GlyphChars.Dash, 2, 2)}Last fetched ${Repository.formatLastFetched(
111+
lastFetched,
112+
false,
113+
)}`
114+
: ''
115+
}${this.repo.formattedName ? `\n${this.uri.repoPath}` : ''}\n\nCurrent branch $(git-branch) ${
116+
branch.name
117+
}${
118+
branch.tracking
119+
? ` is ${branch.getTrackingStatus({
120+
empty: `up to date with $(git-branch) ${branch.tracking}${
121+
providerName ? ` on ${providerName}` : ''
122+
}`,
123+
expand: true,
124+
icons: true,
125+
separator: ', ',
126+
suffix: ` $(git-branch) ${branch.tracking}${providerName ? ` on ${providerName}` : ''}`,
127+
})}`
128+
: `hasn't been published to ${providerName ?? 'a remote'}`
129+
}`,
130+
true,
131+
);
123132
}
124133

125134
return item;

src/views/nodes/branchNode.ts

Lines changed: 62 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
'use strict';
2-
import { TreeItem, TreeItemCollapsibleState, window } from 'vscode';
2+
import { MarkdownString, ThemeColor, ThemeIcon, TreeItem, TreeItemCollapsibleState, window } from 'vscode';
33
import { BranchesView } from '../branchesView';
44
import { BranchTrackingStatusNode } from './branchTrackingStatusNode';
55
import { CommitNode } from './commitNode';
@@ -38,6 +38,7 @@ export class BranchNode
3838
private _children: ViewNode[] | undefined;
3939
private readonly options: {
4040
expanded: boolean;
41+
showAsCommits: boolean;
4142
showComparison: false | ViewShowBranchComparison;
4243
showCurrent: boolean;
4344
showTracking: boolean;
@@ -50,11 +51,12 @@ export class BranchNode
5051
view: BranchesView | CommitsView | RemotesView | RepositoriesView,
5152
parent: ViewNode,
5253
public readonly branch: GitBranch,
53-
// Specifies that the node is shown as a root and not nested under the branches node
54+
// Specifies that the node is shown as a root
5455
public readonly root: boolean,
5556

5657
options?: {
5758
expanded?: boolean;
59+
showAsCommits?: boolean;
5860
showComparison?: false | ViewShowBranchComparison;
5961
showCurrent?: boolean;
6062
showTracking?: boolean;
@@ -65,6 +67,7 @@ export class BranchNode
6567

6668
this.options = {
6769
expanded: false,
70+
showAsCommits: false,
6871
showComparison: false,
6972
// Hide the current branch checkmark when the node is displayed as a root under the repository node
7073
showCurrent: !this.root,
@@ -89,6 +92,8 @@ export class BranchNode
8992
}
9093

9194
get label(): string {
95+
if (this.options.showAsCommits) return 'Commits';
96+
9297
const branchName = this.branch.getNameWithoutRemote();
9398
return this.view.config.branches?.layout !== ViewBranchesLayout.Tree ||
9499
this.compacted ||
@@ -132,11 +137,17 @@ export class BranchNode
132137
]);
133138
if (log == null) return [new MessageNode(this.view, this, 'No commits could be found.')];
134139

135-
if (
136-
this.options.showComparison !== false &&
137-
(this.view instanceof BranchesView || this.view instanceof CommitsView)
138-
) {
139-
children.push(new CompareBranchNode(this.uri, this.view, this, this.branch));
140+
if (this.options.showComparison !== false && !(this.view instanceof RemotesView)) {
141+
children.push(
142+
new CompareBranchNode(
143+
this.uri,
144+
this.view,
145+
this,
146+
this.branch,
147+
this.options.showComparison,
148+
this.splatted,
149+
),
150+
);
140151
}
141152

142153
if (pr != null) {
@@ -157,15 +168,15 @@ export class BranchNode
157168
new BranchTrackingStatusNode(this.view, this, this.branch, status, 'same', this.root),
158169
);
159170
} else {
160-
if (status.state.ahead) {
171+
if (status.state.behind) {
161172
children.push(
162-
new BranchTrackingStatusNode(this.view, this, this.branch, status, 'ahead', this.root),
173+
new BranchTrackingStatusNode(this.view, this, this.branch, status, 'behind', this.root),
163174
);
164175
}
165176

166-
if (status.state.behind) {
177+
if (status.state.ahead) {
167178
children.push(
168-
new BranchTrackingStatusNode(this.view, this, this.branch, status, 'behind', this.root),
179+
new BranchTrackingStatusNode(this.view, this, this.branch, status, 'ahead', this.root),
169180
);
170181
}
171182
}
@@ -214,9 +225,9 @@ export class BranchNode
214225
async getTreeItem(): Promise<TreeItem> {
215226
this.splatted = false;
216227

217-
const name = this.label;
218-
let tooltip = `Branch ${this.branch.getNameWithoutRemote()}${this.current ? ' (current)' : ''}`;
219-
let iconSuffix = '';
228+
let tooltip = `${
229+
this.current ? 'Current branch' : 'Branch'
230+
} $(git-branch) ${this.branch.getNameWithoutRemote()}`;
220231

221232
let contextValue: string = ContextValues.Branch;
222233
if (this.current) {
@@ -231,8 +242,13 @@ export class BranchNode
231242
if (this.branch.tracking) {
232243
contextValue += '+tracking';
233244
}
245+
if (this.options.showAsCommits) {
246+
contextValue += '+commits';
247+
}
234248

249+
let color: ThemeColor | undefined;
235250
let description;
251+
let iconSuffix = '';
236252
if (!this.branch.remote) {
237253
if (this.branch.tracking != null) {
238254
let arrows = GlyphChars.Dash;
@@ -262,27 +278,36 @@ export class BranchNode
262278
}
263279
}
264280

265-
description = `${this.branch.getTrackingStatus({ suffix: `${GlyphChars.Space} ` })}${arrows}${
266-
GlyphChars.Space
267-
} ${this.branch.tracking}`;
281+
description = this.options.showAsCommits
282+
? `${this.branch.getTrackingStatus({
283+
suffix: Strings.pad(GlyphChars.Dot, 1, 1),
284+
})}${this.branch.getNameWithoutRemote()}${Strings.pad(arrows, 2, 2)}${this.branch.tracking}`
285+
: `${this.branch.getTrackingStatus({ suffix: `${GlyphChars.Space} ` })}${arrows}${
286+
GlyphChars.Space
287+
} ${this.branch.tracking}`;
268288

269289
tooltip += ` is ${this.branch.getTrackingStatus({
270-
empty: `up to date with ${this.branch.tracking}${
290+
empty: `up to date with $(git-branch) ${this.branch.tracking}${
271291
remote?.provider?.name ? ` on ${remote.provider.name}` : ''
272292
}`,
273293
expand: true,
294+
icons: true,
274295
separator: ', ',
275-
suffix: ` ${this.branch.tracking}${remote?.provider?.name ? ` on ${remote.provider.name}` : ''}`,
296+
suffix: ` $(git-branch) ${this.branch.tracking}${
297+
remote?.provider?.name ? ` on ${remote.provider.name}` : ''
298+
}`,
276299
})}`;
277300

278301
if (this.branch.state.ahead || this.branch.state.behind) {
279-
if (this.branch.state.behind) {
280-
contextValue += '+behind';
281-
iconSuffix = '-red';
282-
}
283302
if (this.branch.state.ahead) {
284303
contextValue += '+ahead';
285-
iconSuffix = this.branch.state.behind ? '-yellow' : '-green';
304+
color = new ThemeColor('gitlens.viewChangesToPushIconColor');
305+
iconSuffix = '-green';
306+
}
307+
if (this.branch.state.behind) {
308+
contextValue += '+behind';
309+
color = new ThemeColor('gitlens.viewChangesToPullIconColor');
310+
iconSuffix = this.branch.state.ahead ? '-yellow' : '-red';
286311
}
287312
}
288313
} else {
@@ -295,28 +320,30 @@ export class BranchNode
295320
}
296321
}
297322

298-
if (this.branch.date !== undefined) {
323+
if (this.branch.date != null) {
299324
description = `${description ? `${description}${Strings.pad(GlyphChars.Dot, 2, 2)}` : ''}${
300325
this.branch.formattedDate
301326
}`;
302327

303-
tooltip += `\nLast commit ${this.branch.formatDateFromNow()} (${this.branch.formatDate(
328+
tooltip += `\n\nLast commit ${this.branch.formatDateFromNow()} (${this.branch.formatDate(
304329
BranchDateFormatting.dateFormat,
305330
)})`;
306331
}
307332

308333
const item = new TreeItem(
309-
`${this.options.showCurrent && this.current ? `${GlyphChars.Check} ${GlyphChars.Space}` : ''}${name}`,
334+
`${this.options.showCurrent && this.current ? Strings.pad(GlyphChars.Check, 0, 2) : ''}${this.label}`,
310335
this.options.expanded ? TreeItemCollapsibleState.Expanded : TreeItemCollapsibleState.Collapsed,
311336
);
337+
item.iconPath = this.options.showAsCommits
338+
? new ThemeIcon('git-commit', color)
339+
: {
340+
dark: Container.context.asAbsolutePath(`images/dark/icon-branch${iconSuffix}.svg`),
341+
light: Container.context.asAbsolutePath(`images/light/icon-branch${iconSuffix}.svg`),
342+
};
312343
item.contextValue = contextValue;
313344
item.description = description;
314-
item.iconPath = {
315-
dark: Container.context.asAbsolutePath(`images/dark/icon-branch${iconSuffix}.svg`),
316-
light: Container.context.asAbsolutePath(`images/light/icon-branch${iconSuffix}.svg`),
317-
};
318345
item.id = this.id;
319-
item.tooltip = tooltip;
346+
item.tooltip = new MarkdownString(tooltip, true);
320347

321348
return item;
322349
}
@@ -345,12 +372,10 @@ export class BranchNode
345372
private _log: GitLog | undefined;
346373
private async getLog() {
347374
if (this._log == null) {
348-
// Ensure we always show all unpublished commits (and the upstream tip)
349-
let limit =
350-
this.limit ??
351-
(this.view instanceof CommitsView ? this.view.config.pageItemLimit : this.view.config.defaultItemLimit);
375+
let limit = this.limit ?? (this.root ? this.view.config.pageItemLimit : this.view.config.defaultItemLimit);
376+
// Try to show more commits if they are unpublished
352377
if (limit !== 0 && this.branch.state.ahead > limit) {
353-
limit = this.branch.state.ahead + 1;
378+
limit = Math.min(this.branch.state.ahead + 1, limit * 2);
354379
}
355380

356381
this._log = await Container.git.getLog(this.uri.repoPath!, {

src/views/nodes/branchTrackingStatusFilesNode.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export class BranchTrackingStatusFilesNode extends ViewNode<ViewsWithFiles> {
2727
public readonly branch: GitBranch,
2828
public readonly status: Required<BranchTrackingStatus>,
2929
public readonly direction: 'ahead' | 'behind',
30+
// Specifies that the node is shown as a root
3031
private readonly root: boolean = false,
3132
) {
3233
super(GitUri.fromRepoPath(status.repoPath), view, parent);

0 commit comments

Comments
 (0)