Skip to content

Commit

Permalink
Adds working tree compare to branch compare node
Browse files Browse the repository at this point in the history
  • Loading branch information
eamodio committed Jul 9, 2019
1 parent 58e07e5 commit 825e3d9
Show file tree
Hide file tree
Showing 8 changed files with 138 additions and 21 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,7 @@ See also [View Settings](#view-settings- 'Jump to the View settings')
| `gitlens.views.repositories.files.threshold` | Specifies when to switch between displaying files as a `tree` or `list` based on the number of files in a nesting level in the _Repositories_ view. Only applies when `gitlens.views.repositories.files.layout` is set to `auto` |
| `gitlens.views.repositories.includeWorkingTree` | Specifies whether to include working tree file status for each repository in the _Repositories_ view |
| `gitlens.views.repositories.location` | Specifies where to show the _Repositories_ view<br /><br />`gitlens` - adds to the GitLens side bar<br />`explorer` - adds to the Explorer side bar<br />`scm` - adds to the Source Control side bar |
| `gitlens.views.repositories.showBranchComparison` | Specifies whether to show a comparison of the current branch to a user-selected reference in the _Repositories_ view |
| `gitlens.views.repositories.showBranchComparison` | 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 |
| `gitlens.views.repositories.showTrackingBranch` | Specifies whether to show the tracking branch when displaying local branches in the _Repositories_ view |

### File History View Settings [#](#file-history-view-settings- 'File History View Settings')
Expand Down
63 changes: 59 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1520,9 +1520,26 @@
"scope": "window"
},
"gitlens.views.repositories.showBranchComparison": {
"type": "boolean",
"default": true,
"markdownDescription": "Specifies whether to show a comparison of the current branch to a user-selected reference in the _Repositories_ view",
"anyOf": [
{
"enum": [
false
]
},
{
"type": "string",
"default": "working",
"enum": [
"branch",
"working"
],
"enumDescriptions": [
"Compares the current branch to the user-selected reference",
"Compares the working tree to the user-selected reference"
]
}
],
"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",
"scope": "window"
},
"gitlens.views.repositories.showTrackingBranch": {
Expand Down Expand Up @@ -2691,6 +2708,24 @@
"light": "images/light/icon-refresh.svg"
}
},
{
"command": "gitlens.views.repositories.setBranchComparisonToWorking",
"title": "Switch to Working Tree Comparison",
"category": "GitLens",
"icon": {
"dark": "images/dark/icon-compare-ref-working.svg",
"light": "images/light/icon-compare-ref-working.svg"
}
},
{
"command": "gitlens.views.repositories.setBranchComparisonToBranch",
"title": "Switch to Branch Comparison",
"category": "GitLens",
"icon": {
"dark": "images/dark/icon-compare-refs.svg",
"light": "images/light/icon-compare-refs.svg"
}
},
{
"command": "gitlens.views.repositories.setFilesLayoutToAuto",
"title": "Automatic Layout",
Expand Down Expand Up @@ -4711,6 +4746,26 @@
"when": "viewItem =~ /gitlens:(compare:picker:ref|compare:results\\b(?!.*?\\+pinned\\b.*?)|search)\\b(?!:(commits|files))/",
"group": "inline@99"
},
{
"command": "gitlens.views.repositories.setBranchComparisonToWorking",
"when": "config.gitlens.views.repositories.showBranchComparison == branch && viewItem =~ /gitlens:compare:branch\\b/",
"group": "inline@1"
},
{
"command": "gitlens.views.repositories.setBranchComparisonToBranch",
"when": "config.gitlens.views.repositories.showBranchComparison == working && viewItem =~ /gitlens:compare:branch\\b/",
"group": "inline@1"
},
{
"command": "gitlens.views.repositories.setBranchComparisonToWorking",
"when": "config.gitlens.views.repositories.showBranchComparison == branch && viewItem =~ /gitlens:compare:branch\\b/",
"group": "1_gitlens@1"
},
{
"command": "gitlens.views.repositories.setBranchComparisonToBranch",
"when": "config.gitlens.views.repositories.showBranchComparison == working && viewItem =~ /gitlens:compare:branch\\b/",
"group": "1_gitlens@1"
},
{
"command": "gitlens.views.compare.pinComparison",
"when": "viewItem =~ /gitlens:compare:results\\b(?!.*?\\+pinned\\b.*?)/",
Expand All @@ -4728,7 +4783,7 @@
},
{
"command": "gitlens.views.refreshNode",
"when": "viewItem =~ /gitlens:compare:results\\b/",
"when": "viewItem =~ /gitlens:compare:(branch|results)\\b/",
"group": "inline@3"
},
{
Expand Down
7 changes: 6 additions & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,11 @@ export enum ViewLocation {
SourceControl = 'scm'
}

export enum ViewShowBranchComparison {
Branch = 'branch',
Working = 'working'
}

export interface AdvancedConfig {
abbreviatedShaLength: number;
blame: {
Expand Down Expand Up @@ -364,7 +369,7 @@ export interface RepositoriesViewConfig {
files: ViewsFilesConfig;
includeWorkingTree: boolean;
location: ViewLocation;
showBranchComparison: boolean;
showBranchComparison: false | ViewShowBranchComparison;
showTrackingBranch: boolean;
}

Expand Down
10 changes: 8 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';
import { commands, ExtensionContext, extensions, window, workspace } from 'vscode';
import { Commands, registerCommands } from './commands';
import { ModeConfig } from './config';
import { ModeConfig, ViewShowBranchComparison } from './config';
import { Config, configuration, Configuration } from './configuration';
import { CommandContext, extensionQualifiedId, GlobalState, GlyphChars, setCommandContext } from './constants';
import { Container } from './container';
Expand Down Expand Up @@ -105,7 +105,13 @@ async function migrateSettings(context: ExtensionContext, previousVersion: strin
const previous = Versions.fromString(previousVersion);

try {
if (Versions.compare(previous, Versions.from(9, 6, 3)) !== 1) {
if (Versions.compare(previous, Versions.from(9, 8, 2)) !== 1) {
const name = configuration.name('views')('repositories')('showBranchComparison').value;
await configuration.migrate(name, name, {
migrationFn: (v: boolean) => (v === false ? false : ViewShowBranchComparison.Working)
});
}
else if (Versions.compare(previous, Versions.from(9, 6, 3)) !== 1) {
const formatMigrationFn = (v: string) => {
if (v == null || v.length === 0) return v;

Expand Down
39 changes: 30 additions & 9 deletions src/views/nodes/compareBranchNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { CommitsQueryResults, ResultsCommitsNode } from './resultsCommitsNode';
import { Container } from '../../container';
import { Strings } from '../../system';
import { ResultsFilesNode } from './resultsFilesNode';
import { ViewShowBranchComparison } from '../../config';

export class CompareBranchNode extends ViewNode<RepositoriesView> {
private _children: ViewNode[] | undefined;
Expand Down Expand Up @@ -42,7 +43,13 @@ export class CompareBranchNode extends ViewNode<RepositoriesView> {
querying: true
}
),
new ResultsFilesNode(this.view, this, this.uri.repoPath!, this._compareWith, this.branch.ref)
new ResultsFilesNode(
this.view,
this,
this.uri.repoPath!,
this._compareWith,
this.compareWithWorkingTree ? '' : this.branch.ref
)
];
}
return this._children;
Expand All @@ -53,11 +60,13 @@ export class CompareBranchNode extends ViewNode<RepositoriesView> {
let label;
let description;
if (this._compareWith === undefined) {
label = `Compare ${this.branch.name} with <branch, tag, or ref>`;
label = `Compare ${this.branch.name}${
this.compareWithWorkingTree ? ' (working)' : ''
} with <branch, tag, or ref>`;
state = TreeItemCollapsibleState.None;
}
else {
label = `${this.branch.name}`;
label = `${this.branch.name}${this.compareWithWorkingTree ? ' (working)' : ''}`;
description = `${GlyphChars.ArrowLeftRightLong}${GlyphChars.Space} ${GitService.shortenSha(
this._compareWith,
{
Expand All @@ -69,25 +78,37 @@ export class CompareBranchNode extends ViewNode<RepositoriesView> {

const item = new TreeItem(label, state);
item.command = {
title: `Compare ${this.branch.name} with${GlyphChars.Ellipsis}`,
title: `Compare ${this.branch.name}${this.compareWithWorkingTree ? ' (working)' : ''} with${
GlyphChars.Ellipsis
}`,
command: 'gitlens.views.executeNodeCallback',
arguments: [() => this.compareWith()]
};
item.contextValue = ResourceType.CompareBranch;
item.description = description;
item.iconPath = {
dark: Container.context.asAbsolutePath('images/dark/icon-compare-refs.svg'),
light: Container.context.asAbsolutePath('images/light/icon-compare-refs.svg')
dark: Container.context.asAbsolutePath(
`images/dark/icon-compare-${this.compareWithWorkingTree ? 'ref-working' : 'refs'}.svg`
),
light: Container.context.asAbsolutePath(
`images/light/icon-compare-${this.compareWithWorkingTree ? 'ref-working' : 'refs'}.svg`
)
};
item.id = this.id;
item.tooltip = `Click to compare ${this.branch.name} with${GlyphChars.Ellipsis}`;
item.tooltip = `Click to compare ${this.branch.name}${this.compareWithWorkingTree ? ' (working)' : ''} with${
GlyphChars.Ellipsis
}`;

return item;
}

get compareWithWorkingTree() {
return this.view.config.showBranchComparison === ViewShowBranchComparison.Working;
}

async compareWith() {
const pick = await new ReferencesQuickPick(this.branch.repoPath).show(
`Compare ${this.branch.name} with${GlyphChars.Ellipsis}`,
`Compare ${this.branch.name}${this.compareWithWorkingTree ? ' (working)' : ''} with${GlyphChars.Ellipsis}`,
{ allowEnteringRefs: true, checked: this.branch.ref, checkmarks: true }
);
if (pick === undefined || pick instanceof CommandQuickPickItem) return;
Expand All @@ -104,7 +125,7 @@ export class CompareBranchNode extends ViewNode<RepositoriesView> {

const log = await Container.git.getLog(this.uri.repoPath!, {
maxCount: maxCount,
ref: `${this._compareWith || 'HEAD'}${notation}${this.branch.ref}`
ref: `${this._compareWith || 'HEAD'}${notation}${this.compareWithWorkingTree ? '' : this.branch.ref}`
});

const count = log !== undefined ? log.count : 0;
Expand Down
2 changes: 1 addition & 1 deletion src/views/nodes/repositoryNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export class RepositoryNode extends SubscribeableViewNode<RepositoriesView> {
children.push(new StatusFilesNode(this.view, this, status, range));
}

if (this.view.config.showBranchComparison) {
if (this.view.config.showBranchComparison !== false) {
children.push(new CompareBranchNode(this.uri, this.view, this, branch));
}

Expand Down
19 changes: 19 additions & 0 deletions src/views/repositoriesView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { CommandContext, setCommandContext, WorkspaceState } from '../constants'
import { Container } from '../container';
import { RepositoriesNode } from './nodes';
import { ViewBase } from './viewBase';
import { ViewShowBranchComparison } from '../config';

export class RepositoriesView extends ViewBase<RepositoriesNode> {
constructor() {
Expand Down Expand Up @@ -54,6 +55,17 @@ export class RepositoriesView extends ViewBase<RepositoriesNode> {
() => this.setAutoRefresh(Container.config.views.repositories.autoRefresh, false),
this
);

commands.registerCommand(
this.getQualifiedCommand('setBranchComparisonToWorking'),
() => this.setBranchComparison(ViewShowBranchComparison.Working),
this
);
commands.registerCommand(
this.getQualifiedCommand('setBranchComparisonToBranch'),
() => this.setBranchComparison(ViewShowBranchComparison.Branch),
this
);
}

protected onConfigurationChanged(e: ConfigurationChangeEvent) {
Expand Down Expand Up @@ -110,6 +122,13 @@ export class RepositoriesView extends ViewBase<RepositoriesNode> {
this._onDidChangeAutoRefresh.fire();
}

private setBranchComparison(comparison: ViewShowBranchComparison) {
return configuration.updateEffective(
configuration.name('views')('repositories')('showBranchComparison').value,
comparison
);
}

private setFilesLayout(layout: ViewFilesLayout) {
return configuration.updateEffective(
configuration.name('views')('repositories')('files')('layout').value,
Expand Down
17 changes: 14 additions & 3 deletions src/webviews/apps/settings/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2441,7 +2441,7 @@ <h2 class="section__title">
</div>

<div
class="settings-group__setting ml-2 hidden"
class="settings-group__setting nowrap ml-2 hidden"
data-enablement="views.repositories.enabled"
data-visibility="settings.mode =advanced"
>
Expand All @@ -2450,11 +2450,22 @@ <h2 class="section__title">
id="views.repositories.showBranchComparison"
name="views.repositories.showBranchComparison"
type="checkbox"
value="working"
disabled
/>
<label for="views.repositories.showBranchComparison"
>Show a comparison of the current branch to a user-selected reference</label
>
>Show a comparison of a user-selected reference (branch, tag, etc) to the
<select
class="setting"
id="views.repositories.showBranchComparison"
name="views.repositories.showBranchComparison"
data-enablement="views.repositories.enabled &amp; views.repositories.showBranchComparison !false"
disabled
>
<option value="branch">current branch</option>
<option value="working">working tree</option>
</select>
</label>
</div>

<div
Expand Down

0 comments on commit 825e3d9

Please sign in to comment.