From 266b43b012212130a5413b6ee0710b599e6edcb4 Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Sat, 24 Feb 2018 19:20:46 -0500 Subject: [PATCH] Closes #279 - removes selected from ancestor compare Adds custom label support to result view --- CHANGELOG.md | 3 +++ README.md | 4 ++-- package.json | 18 +++++++++--------- src/commands/diffDirectory.ts | 4 ++-- src/views/comparisonResultsNode.ts | 14 +++++++------- src/views/explorerCommands.ts | 12 ++++++------ src/views/explorerNode.ts | 5 +++++ src/views/resultsExplorer.ts | 6 +++--- 8 files changed, 37 insertions(+), 29 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dd57020..fb7ee26 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p ### Added - Adds multi-cursor support to current line annotations — closes [#291](https://github.com/eamodio/vscode-gitlens/issues/291) +### Changed +- Renames *Compare Selected Ancestor with Working Tree* command to *Compare Ancestry with Working Tree* and removes the need to select a branch first, since all compares are done to the working tree — closes [#279](https://github.com/eamodio/vscode-gitlens/issues/279) + ### Fixed - Fixes [#294](https://github.com/eamodio/vscode-gitlens/issues/294) - Keyboard shortcuts will now default to *chorded* to avoid conflicts. FYI, only affects new installs or if you remove the `gitlens.keymap` setting) diff --git a/README.md b/README.md index f98b396..f17cb2f 100644 --- a/README.md +++ b/README.md @@ -107,7 +107,7 @@ The repository view provides a full Git repository explorer, which has the follo - *Red* — behind the upstream - *Yellow* — both ahead of and behind the upstream - Context menus for each branch provide - - *Open Branch in Remote* (if available), *Compare with Remote* (if available), *Compare with Index (HEAD)*, *Compare with Working Tree*, *Compare with Selected* (when available), *Compare Selected Ancestor with Working Tree* (when available), *Select for Compare*, *Open Directory Compare with Working Tree*, *Checkout Branch (via Terminal)*, *Merge Branch (via Terminal)*, *Rebase (Interactive) Branch (via Terminal)*, *Rebase (Interactive) Branch to Remote (via Terminal)*, *Squash Branch into Commit (via Terminal)*, *Create Branch (via Terminal)...*, *Delete Branch (via Terminal)*, *Create Tag (via Terminal)...*, and *Refresh* commands + - *Open Branch in Remote* (if available), *Compare with Remote* (if available), *Compare with Index (HEAD)*, *Compare with Working Tree*, *Compare with Selected* (when available), *Compare Ancestry with Working Tree* (when available), *Select for Compare*, *Open Directory Compare with Working Tree*, *Checkout Branch (via Terminal)*, *Merge Branch (via Terminal)*, *Rebase (Interactive) Branch (via Terminal)*, *Rebase (Interactive) Branch to Remote (via Terminal)*, *Squash Branch into Commit (via Terminal)*, *Create Branch (via Terminal)...*, *Delete Branch (via Terminal)*, *Create Tag (via Terminal)...*, and *Refresh* commands - Revisions (commits) expand to show the set of files changed, complete with status indicators for adds, changes, renames, and deletes - 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 Index (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 @@ -183,7 +183,7 @@ An on-demand, [customizable](#gitlens-results-view-settings "Jump to the GitLens - *Compare with Index (HEAD)* command (`gitlens.explorers.compareWithHead`) - *Compare with Working Tree* command (`gitlens.explorers.compareWithWorking`) - *Compare with Selected* command (`gitlens.explorers.compareWithSelected`) - - *Compare Selected Ancestor with Working Tree* command (`gitlens.explorers.compareSelectedAncestorWithWorking`) + - *Compare Ancestry with Working Tree* command (`gitlens.explorers.compareAncestryWithWorking`) - An inline toolbar provides *Swap Comparision*, and *Clear Results* commands - A context menu provides *Clear Results*, *Swap Comparision*, *Open Directory Compare*, and *Refresh* commands diff --git a/package.json b/package.json index 6ae3c35..ec36841 100644 --- a/package.json +++ b/package.json @@ -1419,8 +1419,8 @@ "category": "GitLens" }, { - "command": "gitlens.explorers.compareSelectedAncestorWithWorking", - "title": "Compare Selected Ancestor with Working Tree", + "command": "gitlens.explorers.compareAncestryWithWorking", + "title": "Compare Ancestry with Working Tree", "category": "GitLens" }, { @@ -1900,7 +1900,7 @@ "when": "false" }, { - "command": "gitlens.explorers.compareSelectedAncestorWithWorking", + "command": "gitlens.explorers.compareAncestryWithWorking", "when": "false" }, { @@ -2410,19 +2410,19 @@ "group": "7_gitlens@3" }, { + "command": "gitlens.explorers.compareAncestryWithWorking", + "when": "viewItem =~ /gitlens:branch\\b/", + "group": "7_gitlens@4" + }, + { "command": "gitlens.explorers.compareWithSelected", "when": "viewItem =~ /gitlens:(branch|commit|stash|tag)\\b/ && gitlens:explorers:canCompare", "group": "7_gitlens_@1" }, { - "command": "gitlens.explorers.compareSelectedAncestorWithWorking", - "when": "viewItem =~ /gitlens:branch\\b/ && gitlens:explorers:canCompare == branch", - "group": "7_gitlens_@2" - }, - { "command": "gitlens.explorers.selectForCompare", "when": "viewItem =~ /gitlens:(branch|commit|stash|tag)\\b/", - "group": "7_gitlens_@3" + "group": "7_gitlens_@2" }, { "command": "gitlens.explorers.openDirectoryDiffWithWorking", diff --git a/src/commands/diffDirectory.ts b/src/commands/diffDirectory.ts index 269ed32..3fcf44c 100644 --- a/src/commands/diffDirectory.ts +++ b/src/commands/diffDirectory.ts @@ -29,8 +29,8 @@ export class DiffDirectoryCommand extends ActiveEditorCommand { case Commands.ExplorersOpenDirectoryDiff: if (context.type === 'view' && context.node instanceof ComparisonResultsNode) { - args.ref1 = context.node.ref1; - args.ref2 = context.node.ref2; + args.ref1 = context.node.ref1.ref; + args.ref2 = context.node.ref2.ref; } break; diff --git a/src/views/comparisonResultsNode.ts b/src/views/comparisonResultsNode.ts index 25d5685..b89be8b 100644 --- a/src/views/comparisonResultsNode.ts +++ b/src/views/comparisonResultsNode.ts @@ -4,7 +4,7 @@ import { TreeItem, TreeItemCollapsibleState } from 'vscode'; import { CommitsResultsNode } from './commitsResultsNode'; import { GlyphChars } from '../constants'; import { Container } from '../container'; -import { Explorer, ExplorerNode, ResourceType } from './explorerNode'; +import { Explorer, ExplorerNode, NamedRef, ResourceType } from './explorerNode'; import { GitLog, GitService, GitStatusFile, GitUri } from '../gitService'; import { StatusFilesResultsNode } from './statusFilesResultsNode'; @@ -12,8 +12,8 @@ export class ComparisonResultsNode extends ExplorerNode { constructor( public readonly repoPath: string, - public readonly ref1: string, - public readonly ref2: string, + public readonly ref1: NamedRef, + public readonly ref2: NamedRef, private readonly explorer: Explorer ) { super(GitUri.fromRepoPath(repoPath)); @@ -22,7 +22,7 @@ export class ComparisonResultsNode extends ExplorerNode { async getChildren(): Promise { this.resetChildren(); - const commitsQueryFn = (maxCount: number | undefined) => Container.git.getLog(this.uri.repoPath!, { maxCount: maxCount, ref: `${this.ref1}...${this.ref2 || 'HEAD'}` }); + const commitsQueryFn = (maxCount: number | undefined) => Container.git.getLog(this.uri.repoPath!, { maxCount: maxCount, ref: `${this.ref1.ref}...${this.ref2.ref || 'HEAD'}` }); const commitsLabelFn = async (log: GitLog | undefined) => { const count = log !== undefined ? log.count : 0; const truncated = log !== undefined ? log.truncated : false; @@ -31,7 +31,7 @@ export class ComparisonResultsNode extends ExplorerNode { return `${count === 0 ? 'No' : `${count}${truncated ? '+' : ''}`} commits`; }; - const filesQueryFn = () => Container.git.getDiffStatus(this.uri.repoPath!, this.ref1, this.ref2); + const filesQueryFn = () => Container.git.getDiffStatus(this.uri.repoPath!, this.ref1.ref, this.ref2.ref); const filesLabelFn = (diff: GitStatusFile[] | undefined) => { const count = diff !== undefined ? diff.length : 0; @@ -41,7 +41,7 @@ export class ComparisonResultsNode extends ExplorerNode { this.children = [ new CommitsResultsNode(this.uri.repoPath!, commitsLabelFn, commitsQueryFn, this.explorer), - new StatusFilesResultsNode(this.uri.repoPath!, this.ref1, this.ref2, filesLabelFn, filesQueryFn, this.explorer) + new StatusFilesResultsNode(this.uri.repoPath!, this.ref1.ref, this.ref2.ref, filesLabelFn, filesQueryFn, this.explorer) ]; return this.children; @@ -54,7 +54,7 @@ export class ComparisonResultsNode extends ExplorerNode { repository = ` ${Strings.pad(GlyphChars.Dash, 1, 1)} ${(repo && repo.formattedName) || this.uri.repoPath}`; } - const item = new TreeItem(`Comparing ${GitService.shortenSha(this.ref1, { working: 'Working Tree' })} to ${GitService.shortenSha(this.ref2, { working: 'Working Tree' })}${repository}`, TreeItemCollapsibleState.Expanded); + const item = new TreeItem(`Comparing ${this.ref1.label || GitService.shortenSha(this.ref1.ref, { working: 'Working Tree' })} to ${this.ref2.label || GitService.shortenSha(this.ref2.ref, { working: 'Working Tree' })}${repository}`, TreeItemCollapsibleState.Expanded); item.contextValue = ResourceType.ComparisonResults; return item; } diff --git a/src/views/explorerCommands.ts b/src/views/explorerCommands.ts index c3d4dcd..ef7863d 100644 --- a/src/views/explorerCommands.ts +++ b/src/views/explorerCommands.ts @@ -35,7 +35,7 @@ export class ExplorerCommands extends Disposable { commands.registerCommand('gitlens.explorers.openChangedFileChangesWithWorking', this.openChangedFileChangesWithWorking, this); commands.registerCommand('gitlens.explorers.openChangedFileRevisions', this.openChangedFileRevisions, this); commands.registerCommand('gitlens.explorers.applyChanges', this.applyChanges, this); - commands.registerCommand('gitlens.explorers.compareSelectedAncestorWithWorking', this.compareSelectedAncestorWithWorking, this); + commands.registerCommand('gitlens.explorers.compareAncestryWithWorking', this.compareAncestryWithWorking, this); commands.registerCommand('gitlens.explorers.compareWithHead', this.compareWithHead, this); commands.registerCommand('gitlens.explorers.compareWithRemote', this.compareWithRemote, this); commands.registerCommand('gitlens.explorers.compareWithSelected', this.compareWithSelected, this); @@ -85,14 +85,14 @@ export class ExplorerCommands extends Disposable { Container.resultsExplorer.showComparisonInResults(node.repoPath, node.ref, ''); } - private async compareSelectedAncestorWithWorking(node: BranchNode) { - if (this._selection === undefined || !(node instanceof BranchNode)) return; - if (this._selection.repoPath !== node.repoPath || this._selection.type !== 'branch') return; + private async compareAncestryWithWorking(node: BranchNode) { + const branch = await Container.git.getBranch(node.repoPath); + if (branch === undefined) return; - const commonAncestor = await Container.git.getMergeBase(this._selection.repoPath, this._selection.ref, node.ref); + const commonAncestor = await Container.git.getMergeBase(node.repoPath, branch.name, node.ref); if (commonAncestor === undefined) return; - Container.resultsExplorer.showComparisonInResults(this._selection.repoPath, commonAncestor, ''); + Container.resultsExplorer.showComparisonInResults(node.repoPath, { ref: commonAncestor, label: `ancestry with ${node.ref} (${GitService.shortenSha(commonAncestor)})` }, ''); } private compareWithSelected(node: ExplorerNode) { diff --git a/src/views/explorerNode.ts b/src/views/explorerNode.ts index bd96629..a33ab3b 100644 --- a/src/views/explorerNode.ts +++ b/src/views/explorerNode.ts @@ -7,6 +7,11 @@ import { GitUri } from '../gitService'; import { GitExplorer } from './gitExplorer'; import { ResultsExplorer } from './resultsExplorer'; +export interface NamedRef { + label?: string; + ref: string; +} + export enum RefreshReason { ActiveEditorChanged = 'active-editor-changed', AutoRefreshChanged = 'auto-refresh-changed', diff --git a/src/views/resultsExplorer.ts b/src/views/resultsExplorer.ts index ee021ec..d050780 100644 --- a/src/views/resultsExplorer.ts +++ b/src/views/resultsExplorer.ts @@ -5,7 +5,7 @@ import { configuration, ExplorerFilesLayout, IExplorersConfig, IResultsExplorerC import { CommandContext, GlyphChars, setCommandContext, WorkspaceState } from '../constants'; import { Container } from '../container'; import { RefreshNodeCommandArgs } from './explorerCommands'; -import { CommitResultsNode, CommitsResultsNode, ComparisonResultsNode, ExplorerNode, MessageNode, RefreshReason, ResourceType } from './explorerNodes'; +import { CommitResultsNode, CommitsResultsNode, ComparisonResultsNode, ExplorerNode, MessageNode, NamedRef, RefreshReason, ResourceType } from './explorerNodes'; import { GitLog, GitLogCommit } from '../gitService'; import { Logger } from '../logger'; import { Messages } from '../messages'; @@ -132,8 +132,8 @@ export class ResultsExplorer extends Disposable implements TreeDataProvider