Skip to content

Commit

Permalink
Adds compare node to branches view
Browse files Browse the repository at this point in the history
  • Loading branch information
eamodio committed Oct 13, 2020
1 parent 208d9e7 commit e2ecc34
Show file tree
Hide file tree
Showing 9 changed files with 134 additions and 28 deletions.
74 changes: 64 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1576,6 +1576,27 @@
"markdownDescription": "Specifies whether to show pull requests (if any) associated with commits in the _Branches_ view. Requires a connection to a supported remote service (e.g. GitHub)",
"scope": "window"
},
"gitlens.views.branches.showBranchComparison": {
"anyOf": [
{
"enum": [
false
]
},
{
"type": "string",
"enum": [
"branch"
],
"enumDescriptions": [
"Compares the branch with a user-selected reference"
]
}
],
"default": "branch",
"markdownDescription": "Specifies whether to show a comparison of the branch with a user-selected reference (branch, tag. etc) in the _Branches_ view",
"scope": "window"
},
"gitlens.views.commitFileFormat": {
"type": "string",
"default": "${file}",
Expand Down Expand Up @@ -1666,13 +1687,13 @@
"working"
],
"enumDescriptions": [
"Compares the current branch to the user-selected reference",
"Compares the working tree to the user-selected reference"
"Compares the current branch with a user-selected reference",
"Compares the working tree with a user-selected reference"
]
}
],
"default": "working",
"markdownDescription": "Specifies whether to show a comparison of a user-selected reference (branch, tag. etc) to the current branch or the working tree in the _Commits_ view",
"markdownDescription": "Specifies whether to show a comparison of the current branch or the working tree with a user-selected reference (branch, tag. etc) in the _Commits_ view",
"scope": "window"
},
"gitlens.views.compare.avatars": {
Expand Down Expand Up @@ -1973,13 +1994,13 @@
"working"
],
"enumDescriptions": [
"Compares the current branch to the user-selected reference",
"Compares the working tree to the user-selected reference"
"Compares the current branch with a user-selected reference",
"Compares the working tree with a user-selected reference"
]
}
],
"default": "working",
"markdownDescription": "Specifies whether to show a comparison of a user-selected reference (branch, tag. etc) to the current branch or the working tree in the _Repositories_ view",
"markdownDescription": "Specifies whether to show a comparison of the current branch or the working tree with a user-selected reference (branch, tag. etc) in the _Repositories_ view",
"scope": "window"
},
"gitlens.views.search.avatars": {
Expand Down Expand Up @@ -3687,6 +3708,16 @@
"title": "Hide Avatars",
"category": "GitLens"
},
{
"command": "gitlens.views.branches.setShowBranchComparisonOn",
"title": "Show Branch Comparison",
"category": "GitLens"
},
{
"command": "gitlens.views.branches.setShowBranchComparisonOff",
"title": "Hide Branch Comparison",
"category": "GitLens"
},
{
"command": "gitlens.views.commits.copy",
"title": "Copy",
Expand Down Expand Up @@ -5020,6 +5051,14 @@
"command": "gitlens.views.branches.setShowAvatarsOff",
"when": "false"
},
{
"command": "gitlens.views.branches.setShowBranchComparisonOn",
"when": "false"
},
{
"command": "gitlens.views.branches.setShowBranchComparisonOff",
"when": "false"
},
{
"command": "gitlens.views.commits.copy",
"when": "false"
Expand Down Expand Up @@ -5879,6 +5918,16 @@
"when": "view =~ /^gitlens\\.views\\.branches/ && config.gitlens.views.branches.avatars",
"group": "1_gitlens@0"
},
{
"command": "gitlens.views.branches.setShowBranchComparisonOn",
"when": "view =~ /^gitlens\\.views\\.branches/ && !config.gitlens.views.branches.showBranchComparison",
"group": "1_gitlens@1"
},
{
"command": "gitlens.views.branches.setShowBranchComparisonOff",
"when": "view =~ /^gitlens\\.views\\.branches/ && config.gitlens.views.branches.showBranchComparison",
"group": "1_gitlens@1"
},
{
"command": "gitlens.views.switchToAnotherBranch",
"when": "!gitlens:readonly && view =~ /^gitlens\\.views\\.commits/",
Expand Down Expand Up @@ -7130,12 +7179,12 @@
},
{
"command": "gitlens.views.setBranchComparisonToWorking",
"when": "viewItem =~ /gitlens:compare:branch\\b(?=.*?\\b\\+comparing\\b)(?=.*?\\b\\+branch\\b)/",
"when": "viewItem =~ /gitlens:compare:branch\\b(?=.*?\\b\\+comparing\\b)(?=.*?\\b\\+current\\b)(?=.*?\\b\\+branch\\b)/",
"group": "inline@2"
},
{
"command": "gitlens.views.setBranchComparisonToBranch",
"when": "viewItem =~ /gitlens:compare:branch\\b(?=.*?\\b\\+comparing\\b)(?=.*?\\b\\+working\\b)/",
"when": "viewItem =~ /gitlens:compare:branch\\b(?=.*?\\b\\+comparing\\b)(?=.*?\\b\\+current\\b)(?=.*?\\b\\+working\\b)/",
"group": "inline@2"
},
{
Expand All @@ -7150,14 +7199,19 @@
},
{
"command": "gitlens.views.setBranchComparisonToWorking",
"when": "viewItem =~ /gitlens:compare:branch\\b(?=.*?\\b\\+comparing\\b)(?=.*?\\b\\+branch\\b)/",
"when": "viewItem =~ /gitlens:compare:branch\\b(?=.*?\\b\\+comparing\\b)(?=.*?\\b\\+current\\b)(?=.*?\\b\\+branch\\b)/",
"group": "1_gitlens@2"
},
{
"command": "gitlens.views.setBranchComparisonToBranch",
"when": "viewItem =~ /gitlens:compare:branch\\b(?=.*?\\b\\+comparing\\b)(?=.*?\\b\\+working\\b)/",
"when": "viewItem =~ /gitlens:compare:branch\\b(?=.*?\\b\\+comparing\\b)(?=.*?\\b\\+current\\b)(?=.*?\\b\\+working\\b)/",
"group": "1_gitlens@2"
},
{
"command": "gitlens.views.branches.setShowBranchComparisonOff",
"when": "view =~ /gitlens\\.views\\.branches\\b/ && viewItem =~ /gitlens:compare:branch\\b/",
"group": "8_gitlens@1"
},
{
"command": "gitlens.views.commits.setShowBranchComparisonOff",
"when": "view =~ /gitlens\\.views\\.commits\\b/ && viewItem =~ /gitlens:compare:branch\\b/",
Expand Down
1 change: 1 addition & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,7 @@ export interface BranchesViewConfig {
showForBranches: boolean;
showForCommits: boolean;
};
showBranchComparison: false | ViewShowBranchComparison;
}

export interface CommitsViewConfig {
Expand Down
27 changes: 26 additions & 1 deletion src/views/branchesView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ import {
TreeItemCollapsibleState,
window,
} from 'vscode';
import { BranchesViewConfig, configuration, ViewBranchesLayout, ViewFilesLayout } from '../configuration';
import {
BranchesViewConfig,
configuration,
ViewBranchesLayout,
ViewFilesLayout,
ViewShowBranchComparison,
} from '../configuration';
import { Container } from '../container';
import {
GitBranchReference,
Expand Down Expand Up @@ -223,6 +229,16 @@ export class BranchesView extends ViewBase<BranchesViewNode, BranchesViewConfig>
);
commands.registerCommand(this.getQualifiedCommand('setShowAvatarsOn'), () => this.setShowAvatars(true), this);
commands.registerCommand(this.getQualifiedCommand('setShowAvatarsOff'), () => this.setShowAvatars(false), this);
commands.registerCommand(
this.getQualifiedCommand('setShowBranchComparisonOn'),
() => this.setShowBranchComparison(true),
this,
);
commands.registerCommand(
this.getQualifiedCommand('setShowBranchComparisonOff'),
() => this.setShowBranchComparison(false),
this,
);
}

protected filterConfigurationChanged(e: ConfigurationChangeEvent) {
Expand Down Expand Up @@ -353,4 +369,13 @@ export class BranchesView extends ViewBase<BranchesViewNode, BranchesViewConfig>
private setShowAvatars(enabled: boolean) {
return configuration.updateEffective('views', this.configKey, 'avatars', enabled);
}

private setShowBranchComparison(enabled: boolean) {
return configuration.updateEffective(
'views',
this.configKey,
'showBranchComparison',
enabled ? ViewShowBranchComparison.Working : false,
);
}
}
19 changes: 10 additions & 9 deletions src/views/nodes/branchNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,18 @@ export class BranchNode
]);
if (log == null) return [new MessageNode(this.view, this, 'No commits could be found.')];

if (this.options.showTracking) {
if (this.options.showComparison !== false && this.view instanceof CommitsView) {
children.push(new CompareBranchNode(this.uri, this.view, this, this.branch));
}
if (
this.options.showComparison !== false &&
(this.view instanceof BranchesView || this.view instanceof CommitsView)
) {
children.push(new CompareBranchNode(this.uri, this.view, this, this.branch));
}

if (pr != null) {
children.push(new PullRequestNode(this.view, this, pr, this.branch));
}
if (pr != null) {
children.push(new PullRequestNode(this.view, this, pr, this.branch));
}

if (this.options.showTracking) {
const status = {
ref: this.branch.ref,
repoPath: this.branch.repoPath,
Expand Down Expand Up @@ -170,8 +173,6 @@ export class BranchNode
new BranchTrackingStatusNode(this.view, this, this.branch, status, 'none', this.root),
);
}
} else if (pr != null) {
children.push(new PullRequestNode(this.view, this, pr, this.branch));
}

if (children.length !== 0) {
Expand Down
5 changes: 4 additions & 1 deletion src/views/nodes/branchesNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ export class BranchesNode extends ViewNode<BranchesView | RepositoriesView> {
if (branches.length === 0) return [new MessageNode(this.view, this, 'No branches could be found.')];

const branchNodes = branches.map(
b => new BranchNode(GitUri.fromRepoPath(this.uri.repoPath!, b.ref), this.view, this, b, false),
b =>
new BranchNode(GitUri.fromRepoPath(this.uri.repoPath!, b.ref), this.view, this, b, false, {
showComparison: this.view.config.showBranchComparison,
}),
);
if (this.view.config.branches.layout === ViewBranchesLayout.List) return branchNodes;

Expand Down
11 changes: 6 additions & 5 deletions src/views/nodes/compareBranchNode.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';
import { ThemeIcon, TreeItem, TreeItemCollapsibleState } from 'vscode';
import { BranchesView } from '../branchesView';
import { CommitsView } from '../commitsView';
import { BranchComparison, BranchComparisons, GlyphChars, WorkspaceState } from '../../constants';
import { BranchSorting, TagSorting, ViewShowBranchComparison } from '../../configuration';
Expand All @@ -14,7 +15,7 @@ import { FilesQueryResults, ResultsFilesNode } from './resultsFilesNode';
import { debug, gate, log, Strings } from '../../system';
import { ContextValues, ViewNode } from './viewNode';

export class CompareBranchNode extends ViewNode<CommitsView | RepositoriesView> {
export class CompareBranchNode extends ViewNode<BranchesView | CommitsView | RepositoriesView> {
static key = ':compare-branch';
static getId(repoPath: string, name: string): string {
return `${RepositoryNode.getId(repoPath)}${this.key}(${name})`;
Expand All @@ -25,7 +26,7 @@ export class CompareBranchNode extends ViewNode<CommitsView | RepositoriesView>

constructor(
uri: GitUri,
view: CommitsView | RepositoriesView,
view: BranchesView | CommitsView | RepositoriesView,
parent: ViewNode,
public readonly branch: GitBranch,
) {
Expand Down Expand Up @@ -108,9 +109,9 @@ export class CompareBranchNode extends ViewNode<CommitsView | RepositoriesView>
command: 'gitlens.views.executeNodeCallback',
arguments: [() => this.compareWith()],
};
item.contextValue = `${ContextValues.CompareBranch}${this._compareWith === undefined ? '' : '+comparing'}+${
this.comparisonNotation === '..' ? 'twodot' : 'threedot'
}+${this.comparisonType}`;
item.contextValue = `${ContextValues.CompareBranch}${this.branch.current ? '+current' : ''}${
this._compareWith === undefined ? '' : '+comparing'
}+${this.comparisonNotation === '..' ? 'twodot' : 'threedot'}+${this.comparisonType}`;
item.description = description;
if (this.compareWithWorkingTree) {
item.iconPath = {
Expand Down
15 changes: 15 additions & 0 deletions src/webviews/apps/settings/partials/views.branches.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,21 @@ <h2>
<div class="section__group">
<div class="section__content">
<div class="settings settings--fixed ml-1">
<div class="setting">
<div class="setting__input">
<input
id="views.branches.showBranchComparison"
name="views.branches.showBranchComparison"
type="checkbox"
value="branch"
data-setting
/>
<label for="views.branches.showBranchComparison"
>Show a comparison of the branch with a user-selected reference (branch, tag, etc)
</label>
</div>
</div>

<div class="setting">
<div class="setting__input">
<label for="views.branches.branches.layout">Layout branches</label>
Expand Down
5 changes: 4 additions & 1 deletion src/webviews/apps/settings/partials/views.commits.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ <h2>
data-setting
/>
<label for="views.commits.showBranchComparison"
>Show a comparison of a user-selected reference (branch, tag, etc) to the
>Show a comparison of the
<div class="select-container">
<select
id="views.commits.showBranchComparison"
Expand All @@ -41,6 +41,9 @@ <h2>
</select>
</div>
</label>
<label for="views.commits.showBranchComparison"
>with a user-selected reference (branch, tag, etc)
</label>
</div>
</div>

Expand Down
5 changes: 4 additions & 1 deletion src/webviews/apps/settings/partials/views.repositories.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
disabled
/>
<label for="views.repositories.showBranchComparison"
>Show a comparison of a user-selected reference (branch, tag, etc) to the
>Show a comparison of the
<div class="select-container">
<select
id="views.repositories.showBranchComparison"
Expand All @@ -46,6 +46,9 @@
</select>
</div>
</label>
<label for="views.repositories.showBranchComparison"
>with a user-selected reference (branch, tag, etc)
</label>
</div>
</div>

Expand Down

0 comments on commit e2ecc34

Please sign in to comment.