diff --git a/CHANGELOG.md b/CHANGELOG.md index b280f24..afffe4e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] +### Added +- Adds *Compare with Selected* and *Select for Compare* commands to file nodes in the *GitLens*, *GitLens File History*, and *GitLens Results* explorers — closes [#446](https://github.com/eamodio/vscode-gitlens/issues/446) + ### Fixed - Fixes [#444](https://github.com/eamodio/vscode-gitlens/issues/444) - GitLens custom viewlet icon slightly larger than standard diff --git a/README.md b/README.md index 0c50362..ea71117 100644 --- a/README.md +++ b/README.md @@ -153,7 +153,7 @@ The repository view provides a full Git repository explorer, which has the follo - Context menus for each revision (commit) provide - *Open Commit in Remote* (if available), *Open All Changes*, *Open All Changes with Working Tree*, *Open Files*, *Open Revisions*, *Copy Commit ID to Clipboard*, *Copy Commit Message to Clipboard*, *Show Commit Details*, *Compare with HEAD*, *Compare with Working Tree*, *Compare with Selected* (when available), *Select for Compare*, *Cherry Pick Commit (via Terminal)* (when available), *Push to Commit (via Terminal)* (when available), *Revert Commit (via Terminal)* (when available), *Rebase to Commit (via Terminal)* (when available), *Reset to Commit (via Terminal)* (when available), *Create Branch (via Terminal)...*, *Create Tag (via Terminal)...*, and *Refresh* commands - Context menus for each changed file provide - - *Open Changes*, *Open Changes with Working File*, *Open File*, *Open Revision*, *Open File in Remote*, *Open Revision in Remote*, *Copy Commit ID to Clipboard*, *Copy Commit Message to Clipboard*, *Apply Changes*, and *Show Commit File Details* commands + - *Open Changes*, *Open Changes with Working File*, *Open File*, *Open Revision*, *Open File in Remote*, *Open Revision in Remote*, *Copy Commit ID to Clipboard*, *Copy Commit Message to Clipboard*, *Apply Changes*, *Compare with Selected* (when available), *Select for Compare*, and *Show Commit File Details* commands - Inline toolbars for each changed file provide an *Open File* command - **Remotes** — lists the remotes @@ -171,7 +171,7 @@ The repository view provides a full Git repository explorer, which has the follo - Context menus for each stash provide - *Apply Stashed Changes* (confirmation required), *Delete Stashed Changes* (confirmation required), *Open All Changes*, *Open All Changes with Working Tree*, *Open Files*, *Open Revisions*, *Copy Commit Message to Clipboard*, *Compare with HEAD*, *Compare with Working Tree*, *Compare with Selected* (when available), *Select for Compare*, and *Refresh* commands - Context menus for each stashed file provide - - *Apply Changes*, *Open Changes*, *Open Changes with Working File*, *Open File*, *Open Revision*, *Open File in Remote* (if available), and *Show File History* commands + - *Apply Changes*, *Open Changes*, *Open Changes with Working File*, *Open File*, *Open Revision*, *Open File in Remote* (if available), *Compare with Selected* (when available), *Select for Compare*, and *Show File History* commands - **Tags** — lists the tags - A context menu provides a *Refresh* command @@ -191,7 +191,7 @@ The file history view provides the revision history of the current file, which h - A context menu provides *Open File*, *Open File in Remote* (if available), and *Refresh* commands - An inline toolbar provides an *Open File* command - Context menus for each revision (commit) provides - - *Open Changes*, *Open Changes with Working File*, *Open File*, *Open Revision*, *Open File in Remote* (if available), *Open Revision in Remote* (if available), *Apply Changes*, and *Show Commit File Details* commands + - *Open Changes*, *Open Changes with Working File*, *Open File*, *Open Revision*, *Open File in Remote* (if available), *Open Revision in Remote* (if available), *Apply Changes*, *Compare with Selected* (when available), *Select for Compare*, and *Show Commit File Details* commands --- ### GitLens File History Explorer @@ -204,7 +204,7 @@ A [customizable](#gitlens-file-history-explorer-settings "Jump to the GitLens Fi - A context menu provides *Open File*, *Open File in Remote* (if available), and *Refresh* commands - An inline toolbar provides an *Open File* command - Context menus for each revision (commit) provides - - *Open Changes*, *Open Changes with Working File*, *Open File*, *Open Revision*, *Open File in Remote* (if available), *Open Revision in Remote* (if available), *Apply Changes*, and *Show Commit File Details* commands + - *Open Changes*, *Open Changes with Working File*, *Open File*, *Open Revision*, *Open File in Remote* (if available), *Open Revision in Remote* (if available), *Apply Changes*, *Compare with Selected* (when available), *Select for Compare*, and *Show Commit File Details* commands --- ### GitLens Results Explorer @@ -228,7 +228,7 @@ An on-demand, [customizable](#gitlens-results-explorer-settings "Jump to the Git - Context menus for each revision (commit) provide - *Open Commit in Remote* (if available), *Open All Changes*, *Open All Changes with Working Tree*, *Open Files*, *Open Revisions*, *Copy Commit ID to Clipboard*, *Copy Commit Message to Clipboard*, *Show Commit Details*, *Compare with HEAD*, *Compare with Working Tree*, *Compare with Selected* (when available), *Select for Compare*, *Cherry Pick Commit (via Terminal)* (when available), *Push to Commit (via Terminal)* (when available), *Revert Commit (via Terminal)* (when available), *Rebase to Commit (via Terminal)* (when available), *Reset to Commit (via Terminal)* (when available), *Create Branch (via Terminal)...*, *Create Tag (via Terminal)...*, and *Refresh* commands - Context menus for each changed file provide - - *Open Changes*, *Open Changes with Working File*, *Open File*, *Open Revision*, *Open File in Remote*, *Open Revision in Remote*, *Copy Commit ID to Clipboard*, *Copy Commit Message to Clipboard*, *Apply Changes*, and *Show Commit File Details* commands + - *Open Changes*, *Open Changes with Working File*, *Open File*, *Open Revision*, *Open File in Remote*, *Open Revision in Remote*, *Copy Commit ID to Clipboard*, *Copy Commit Message to Clipboard*, *Apply Changes*, *Compare with Selected* (when available), *Select for Compare*, and *Show Commit File Details* commands #### Compare - Provides a semi-persistent results view for comparison operations @@ -248,7 +248,7 @@ An on-demand, [customizable](#gitlens-results-explorer-settings "Jump to the Git - **Changed Files** — lists the files changed between the compared revisions (branches or commits) - Expands to a file-based view of all changed files - Context menus for each changed file provide - - *Open Changes*, *Open Changes with Working File*, *Open File*, *Open Revision*, *Open File in Remote*, *Open Revision in Remote*, *Copy Commit ID to Clipboard*, *Copy Commit Message to Clipboard*, *Apply Changes*, and *Show Commit File Details* commands + - *Open Changes*, *Open Changes with Working File*, *Open File*, *Open Revision*, *Open File in Remote*, *Open Revision in Remote*, *Copy Commit ID to Clipboard*, *Copy Commit Message to Clipboard*, *Apply Changes*, *Compare with Selected* (when available), *Select for Compare*, and *Show Commit File Details* commands --- ### Code Lens diff --git a/package.json b/package.json index 7f6b80c..2ccfeff 100644 --- a/package.json +++ b/package.json @@ -2854,12 +2854,12 @@ }, { "command": "gitlens.explorers.compareWithSelected", - "when": "viewItem =~ /gitlens:(branch|commit|stash|tag)\\b/ && gitlens:explorers:canCompare", + "when": "viewItem =~ /gitlens:(branch|commit|stash|tag|file:)\\b/ && gitlens:explorers:canCompare", "group": "7_gitlens_@1" }, { "command": "gitlens.explorers.selectForCompare", - "when": "viewItem =~ /gitlens:(branch|commit|stash|tag)\\b/", + "when": "viewItem =~ /gitlens:(branch|commit|stash|tag|file:)\\b/", "group": "7_gitlens_@2" }, { @@ -2939,7 +2939,7 @@ }, { "command": "gitlens.copyMessageToClipboard", - "when": "viewItem =~ /gitlens:(file:)?(commit|stash)\\b/", + "when": "viewItem =~ /gitlens:(commit|stash|file:commit)\\b/", "group": "5_gitlens@2" }, { diff --git a/src/views/explorerCommands.ts b/src/views/explorerCommands.ts index 088b2a1..58c008e 100644 --- a/src/views/explorerCommands.ts +++ b/src/views/explorerCommands.ts @@ -38,7 +38,7 @@ export interface RefreshNodeCommandArgs { interface ICompareSelected { ref: string; repoPath: string | undefined; - type: 'branch' | 'ref'; + uri?: Uri; } export class ExplorerCommands extends Disposable { @@ -146,6 +146,25 @@ export class ExplorerCommands extends Disposable { if (this._selection === undefined || !(node instanceof ExplorerRefNode)) return; if (this._selection.repoPath !== node.repoPath) return; + if (this._selection.uri !== undefined) { + if (!(node instanceof CommitFileNode)) return; + + const diffArgs: DiffWithCommandArgs = { + repoPath: this._selection.repoPath, + lhs: { + sha: this._selection.ref, + uri: this._selection.uri! + }, + rhs: { + sha: node.ref, + uri: node.uri + } + }; + commands.executeCommand(Commands.DiffWith, diffArgs); + + return; + } + Container.resultsExplorer.showComparisonInResults(this._selection.repoPath, this._selection.ref, node.ref); } @@ -154,14 +173,13 @@ export class ExplorerCommands extends Disposable { private selectForCompare(node: ExplorerNode) { if (!(node instanceof ExplorerRefNode)) return; - const type = node instanceof BranchNode ? 'branch' : 'ref'; this._selection = { ref: node.ref, repoPath: node.repoPath, - type: type + uri: node instanceof CommitFileNode ? node.uri : undefined }; - setCommandContext(CommandContext.ExplorersCanCompare, type); + setCommandContext(CommandContext.ExplorersCanCompare, true); } private openChanges(node: CommitNode | StashNode) { diff --git a/src/views/nodes/commitFileNode.ts b/src/views/nodes/commitFileNode.ts index 0a680d8..f7f3802 100644 --- a/src/views/nodes/commitFileNode.ts +++ b/src/views/nodes/commitFileNode.ts @@ -14,7 +14,7 @@ import { IStatusFormatOptions, StatusFileFormatter } from '../../gitService'; -import { Explorer, ExplorerNode, ResourceType } from './explorerNode'; +import { Explorer, ExplorerNode, ExplorerRefNode, ResourceType } from './explorerNode'; export enum CommitFileNodeDisplayAs { CommitLabel = 1 << 0, @@ -27,9 +27,8 @@ export enum CommitFileNodeDisplayAs { File = FileLabel | StatusIcon } -export class CommitFileNode extends ExplorerNode { +export class CommitFileNode extends ExplorerRefNode { readonly priority: boolean = false; - readonly repoPath: string; constructor( public readonly status: IGitStatusFile, @@ -38,7 +37,10 @@ export class CommitFileNode extends ExplorerNode { private displayAs: CommitFileNodeDisplayAs ) { super(GitUri.fromFileStatus(status, commit.repoPath, commit.sha)); - this.repoPath = commit.repoPath; + } + + get ref(): string { + return this.commit.sha; } async getChildren(): Promise {