diff --git a/package.json b/package.json index ed71f16..f2e1e4b 100644 --- a/package.json +++ b/package.json @@ -1720,6 +1720,29 @@ "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 _History_ view. Only applies when `#gitlens.views.history.files.layout#` is set to `auto`", "scope": "window" }, + "gitlens.views.history.showBranchComparison": { + "anyOf": [ + { + "enum": [ + false + ] + }, + { + "type": "string", + "enum": [ + "branch", + "working" + ], + "enumDescriptions": [ + "Compares the current branch to the user-selected reference", + "Compares the working tree to the 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 _History_ view", + "scope": "window" + }, "gitlens.views.history.showTrackingBranch": { "type": "boolean", "default": true, @@ -3333,7 +3356,7 @@ "icon": "$(refresh)" }, { - "command": "gitlens.views.repositories.setBranchComparisonToWorking", + "command": "gitlens.views.setBranchComparisonToWorking", "title": "Switch to Working Tree Comparison", "category": "GitLens", "icon": { @@ -3342,7 +3365,7 @@ } }, { - "command": "gitlens.views.repositories.setBranchComparisonToBranch", + "command": "gitlens.views.setBranchComparisonToBranch", "title": "Switch to Branch Comparison", "category": "GitLens", "icon": "$(compare-changes)" @@ -4589,11 +4612,11 @@ "when": "false" }, { - "command": "gitlens.views.repositories.setBranchComparisonToWorking", + "command": "gitlens.views.setBranchComparisonToWorking", "when": "false" }, { - "command": "gitlens.views.repositories.setBranchComparisonToBranch", + "command": "gitlens.views.setBranchComparisonToBranch", "when": "false" }, { @@ -6531,12 +6554,12 @@ "group": "inline@1" }, { - "command": "gitlens.views.repositories.setBranchComparisonToWorking", + "command": "gitlens.views.setBranchComparisonToWorking", "when": "viewItem =~ /gitlens:compare:branch\\b(?=.*?\\b\\+comparing\\b)(?=.*?\\b\\+branch\\b)/", "group": "inline@2" }, { - "command": "gitlens.views.repositories.setBranchComparisonToBranch", + "command": "gitlens.views.setBranchComparisonToBranch", "when": "viewItem =~ /gitlens:compare:branch\\b(?=.*?\\b\\+comparing\\b)(?=.*?\\b\\+working\\b)/", "group": "inline@2" }, @@ -6551,12 +6574,12 @@ "group": "1_gitlens@1" }, { - "command": "gitlens.views.repositories.setBranchComparisonToWorking", + "command": "gitlens.views.setBranchComparisonToWorking", "when": "viewItem =~ /gitlens:compare:branch\\b(?=.*?\\b\\+comparing\\b)(?=.*?\\b\\+branch\\b)/", "group": "1_gitlens@2" }, { - "command": "gitlens.views.repositories.setBranchComparisonToBranch", + "command": "gitlens.views.setBranchComparisonToBranch", "when": "viewItem =~ /gitlens:compare:branch\\b(?=.*?\\b\\+comparing\\b)(?=.*?\\b\\+working\\b)/", "group": "1_gitlens@2" }, diff --git a/src/config.ts b/src/config.ts index 1519512..1f1e3ad 100644 --- a/src/config.ts +++ b/src/config.ts @@ -504,6 +504,7 @@ export interface HistoryViewConfig { avatars: boolean; branches: undefined; files: ViewsFilesConfig; + showBranchComparison: false | ViewShowBranchComparison; showTrackingBranch: boolean; } diff --git a/src/views/historyView.ts b/src/views/historyView.ts index 8081936..628a54e 100644 --- a/src/views/historyView.ts +++ b/src/views/historyView.ts @@ -24,6 +24,7 @@ import { BranchesNode, BranchNode, BranchOrTagFolderNode, + CompareBranchNode, ContextValues, MessageNode, RemoteNode, @@ -38,7 +39,7 @@ import { debug, gate } from '../system'; import { ViewBase } from './viewBase'; export class HistoryRepositoryNode extends SubscribeableViewNode { - private children: BranchNode[] | undefined; + private children: (BranchNode | CompareBranchNode)[] | undefined; constructor( uri: GitUri, @@ -63,6 +64,10 @@ export class HistoryRepositoryNode extends SubscribeableViewNode { }), ]; + if (this.view.config.showBranchComparison !== false) { + this.children.push(new CompareBranchNode(this.uri, this.view, this, branch)); + } + void this.ensureSubscription(); } return this.children; diff --git a/src/views/nodes/compareBranchNode.ts b/src/views/nodes/compareBranchNode.ts index 77ddcb2..095eac1 100644 --- a/src/views/nodes/compareBranchNode.ts +++ b/src/views/nodes/compareBranchNode.ts @@ -1,19 +1,20 @@ 'use strict'; import { ThemeIcon, TreeItem, TreeItemCollapsibleState } from 'vscode'; import { BranchComparison, BranchComparisons, GlyphChars, WorkspaceState } from '../../constants'; -import { ContextValues, ViewNode } from './viewNode'; -import { RepositoriesView } from '../repositoriesView'; +import { ViewShowBranchComparison } from '../../config'; +import { Container } from '../../container'; import { GitBranch, GitRevision } from '../../git/git'; import { GitUri } from '../../git/gitUri'; +import { HistoryView } from '../historyView'; import { CommandQuickPickItem, ReferencePicker } from '../../quickpicks'; +import { RepositoriesView } from '../repositoriesView'; +import { RepositoryNode } from './repositoryNode'; import { CommitsQueryResults, ResultsCommitsNode } from './resultsCommitsNode'; -import { Container } from '../../container'; -import { debug, gate, log, Strings } from '../../system'; import { FilesQueryResults, ResultsFilesNode } from './resultsFilesNode'; -import { ViewShowBranchComparison } from '../../config'; -import { RepositoryNode } from './repositoryNode'; +import { debug, gate, log, Strings } from '../../system'; +import { ContextValues, ViewNode } from './viewNode'; -export class CompareBranchNode extends ViewNode { +export class CompareBranchNode extends ViewNode { static key = ':compare-branch'; static getId(repoPath: string, name: string): string { return `${RepositoryNode.getId(repoPath)}${this.key}(${name})`; @@ -22,7 +23,12 @@ export class CompareBranchNode extends ViewNode { private _children: ViewNode[] | undefined; private _compareWith: BranchComparison | undefined; - constructor(uri: GitUri, view: RepositoriesView, parent: ViewNode, public readonly branch: GitBranch) { + constructor( + uri: GitUri, + view: HistoryView | RepositoriesView, + parent: ViewNode, + public readonly branch: GitBranch, + ) { super(uri, view, parent); const comparisons = Container.context.workspaceState.get(WorkspaceState.BranchComparisons); diff --git a/src/views/repositoriesView.ts b/src/views/repositoriesView.ts index 9d93dcf..b0e8232 100644 --- a/src/views/repositoriesView.ts +++ b/src/views/repositoriesView.ts @@ -8,13 +8,7 @@ import { ProgressLocation, window, } from 'vscode'; -import { - configuration, - RepositoriesViewConfig, - ViewBranchesLayout, - ViewFilesLayout, - ViewShowBranchComparison, -} from '../configuration'; +import { configuration, RepositoriesViewConfig, ViewBranchesLayout, ViewFilesLayout } from '../configuration'; import { CommandContext, setCommandContext, WorkspaceState } from '../constants'; import { Container } from '../container'; import { @@ -30,7 +24,6 @@ import { BranchesNode, BranchNode, BranchOrTagFolderNode, - CompareBranchNode, RemoteNode, RemotesNode, RepositoriesNode, @@ -38,7 +31,6 @@ import { StashesNode, StashNode, TagsNode, - ViewNode, } from './nodes'; import { gate } from '../system'; import { ViewBase } from './viewBase'; @@ -109,16 +101,6 @@ export class RepositoriesView extends ViewBase this.setShowAvatars(true), this); commands.registerCommand(this.getQualifiedCommand('setShowAvatarsOff'), () => this.setShowAvatars(false), this); - commands.registerCommand( - this.getQualifiedCommand('setBranchComparisonToWorking'), - n => this.setBranchComparison(n, ViewShowBranchComparison.Working), - this, - ); - commands.registerCommand( - this.getQualifiedCommand('setBranchComparisonToBranch'), - n => this.setBranchComparison(n, ViewShowBranchComparison.Branch), - this, - ); } protected filterConfigurationChanged(e: ConfigurationChangeEvent) { @@ -563,12 +545,6 @@ export class RepositoriesView extends ViewBase) { - if (!(node instanceof CompareBranchNode)) return undefined; - - return node.setComparisonType(comparisonType); - } - private setBranchesLayout(layout: ViewBranchesLayout) { return configuration.updateEffective('views', this.configKey, 'branches', 'layout', layout); } diff --git a/src/views/viewCommands.ts b/src/views/viewCommands.ts index f5e77a9..b0ff6ae 100644 --- a/src/views/viewCommands.ts +++ b/src/views/viewCommands.ts @@ -11,7 +11,7 @@ import { OpenFileAtRevisionCommandArgs, OpenFileOnRemoteCommandArgs, } from '../commands'; -import { FileAnnotationType } from '../config'; +import { FileAnnotationType, ViewShowBranchComparison } from '../config'; import { BuiltInCommands, CommandContext, setCommandContext } from '../constants'; import { Container } from '../container'; import { GitReference, GitRevision } from '../git/git'; @@ -156,6 +156,16 @@ export class ViewCommands { n => this.setComparisonNotation(n, '...'), this, ); + commands.registerCommand( + 'gitlens.views.setBranchComparisonToWorking', + n => this.setBranchComparison(n, ViewShowBranchComparison.Working), + this, + ); + commands.registerCommand( + 'gitlens.views.setBranchComparisonToBranch', + n => this.setBranchComparison(n, ViewShowBranchComparison.Branch), + this, + ); commands.registerCommand('gitlens.views.cherryPick', this.cherryPick, this); commands.registerCommand('gitlens.views.createBranch', this.createBranch, this); @@ -430,6 +440,13 @@ export class ViewCommands { } @debug() + private setBranchComparison(node: ViewNode, comparisonType: Exclude) { + if (!(node instanceof CompareBranchNode)) return undefined; + + return node.setComparisonType(comparisonType); + } + + @debug() private setComparisonNotation(node: ViewNode, comparisonNotation: '...' | '..') { if (!(node instanceof CompareResultsNode) && !(node instanceof CompareBranchNode)) return Promise.resolve();