Browse Source

Adds working tree compare to branch compare node

main
Eric Amodio 5 years ago
parent
commit
825e3d937a
8 changed files with 138 additions and 21 deletions
  1. +1
    -1
      README.md
  2. +59
    -4
      package.json
  3. +6
    -1
      src/config.ts
  4. +8
    -2
      src/extension.ts
  5. +30
    -9
      src/views/nodes/compareBranchNode.ts
  6. +1
    -1
      src/views/nodes/repositoryNode.ts
  7. +19
    -0
      src/views/repositoriesView.ts
  8. +14
    -3
      src/webviews/apps/settings/index.html

+ 1
- 1
README.md View File

@ -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')

+ 59
- 4
package.json View File

@ -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": {
@ -2692,6 +2709,24 @@
}
},
{
"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",
"category": "GitLens"
@ -4712,6 +4747,26 @@
"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.*?)/",
"group": "inline@1"
@ -4728,7 +4783,7 @@
},
{
"command": "gitlens.views.refreshNode",
"when": "viewItem =~ /gitlens:compare:results\\b/",
"when": "viewItem =~ /gitlens:compare:(branch|results)\\b/",
"group": "inline@3"
},
{

+ 6
- 1
src/config.ts View File

@ -193,6 +193,11 @@ export enum ViewLocation {
SourceControl = 'scm'
}
export enum ViewShowBranchComparison {
Branch = 'branch',
Working = 'working'
}
export interface AdvancedConfig {
abbreviatedShaLength: number;
blame: {
@ -364,7 +369,7 @@ export interface RepositoriesViewConfig {
files: ViewsFilesConfig;
includeWorkingTree: boolean;
location: ViewLocation;
showBranchComparison: boolean;
showBranchComparison: false | ViewShowBranchComparison;
showTrackingBranch: boolean;
}

+ 8
- 2
src/extension.ts View File

@ -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';
@ -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;

+ 30
- 9
src/views/nodes/compareBranchNode.ts View File

@ -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;
@ -42,7 +43,13 @@ export class CompareBranchNode extends ViewNode {
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;
@ -53,11 +60,13 @@ export class CompareBranchNode extends ViewNode {
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,
{
@ -69,25 +78,37 @@ export class CompareBranchNode extends ViewNode {
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;
@ -104,7 +125,7 @@ export class CompareBranchNode extends ViewNode {
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;

+ 1
- 1
src/views/nodes/repositoryNode.ts View File

@ -75,7 +75,7 @@ export class RepositoryNode extends SubscribeableViewNode {
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));
}

+ 19
- 0
src/views/repositoriesView.ts View File

@ -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() {
@ -54,6 +55,17 @@ export class RepositoriesView extends ViewBase {
() => 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) {
@ -110,6 +122,13 @@ export class RepositoriesView extends ViewBase {
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,

+ 14
- 3
src/webviews/apps/settings/index.html View File

@ -2441,7 +2441,7 @@
</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"
>
@ -2450,11 +2450,22 @@
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

Loading…
Cancel
Save