diff --git a/CHANGELOG.md b/CHANGELOG.md index f19aa9e..edfd63e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p ## [Unreleased] ### Added -- Adds `gitlens.statusBar.reduceFlicker` setting to specify whether to reduce the status bar "flickering" when changing lines by not first clearing the previous blame information -- closes [#272](https://github.com/eamodio/vscode-gitlens/issues/272) +- Adds `gitlens.statusBar.reduceFlicker` setting to specify whether to reduce the status bar "flickering" when changing lines by not first clearing the previous blame information — closes [#272](https://github.com/eamodio/vscode-gitlens/issues/272) +- Adds *Compare Index (HEAD) with Branch or Tag...* (`gitlens.explorers.diffHeadWithBranch`) command - compares the index (HEAD) to the selected branch or tag — thanks to [PR #278](https://github.com/eamodio/vscode-gitlens/pull/278) by Geoffrey ([@g3offrey](https://github.com/g3offrey))! +- Adds *Compare Working Tree with Branch or Tag...* (`gitlens.explorers.diffWorkingWithBranch`) command - compares the working tree to the selected branch or tag - Adds the *Open File* (`gitlens.explorers.openFile`) command to the *GitLens* explorer inline for file nodes - Adds the *Clear Results* (`gitlen.resultsExplorer.clearResultsNode`) command to the *GitLens Results* view inline for results nodes - Adds *Push to Commit (via Terminal)* (`gitlens.explorers.terminalPushCommit`) command to commit nodes on the current branch in the *GitLens* explorer diff --git a/README.md b/README.md index 33a89ca..98717c4 100644 --- a/README.md +++ b/README.md @@ -451,6 +451,10 @@ An on-demand, [customizable](#gitlens-results-view-settings "Jump to the GitLens - Adds a *Directory Compare Working Tree with...* command (`gitlens.diffDirectory`) to open the configured Git difftool to compare the working tree with the selected branch or tag +- Adds a *Compare Index (HEAD) with Branch or Tag...* command (`gitlens.diffHeadWithBranch`) to compare the index (HEAD) with the selected branch or tag + +- Adds a *Compare Working Tree with Branch or Tag...* command (`gitlens.diffWorkingWithBranch`) to compare the working tree with the selected branch or tag + - Adds a *Compare File with Branch or Tag...* command (`gitlens.diffWithBranch`) to compare the active file with the same file on the selected branch or tag - Adds a *Compare File with Next Revision* command (`gitlens.diffWithNext`) with a shortcut of `alt+.` to compare the active file/diff with the next commit revision @@ -667,6 +671,7 @@ Add [`"gitlens.insiders": true`](#general-settings "Jump to GitLens settings") t A big thanks to the people that have contributed to this project: - Amanda Cameron ([@AmandaCameron](https://github.com/AmandaCameron)) — [contributions](https://github.com/eamodio/vscode-gitlens/commits?author=AmandaCameron)) +- Geoffrey ([@g3offrey](https://github.com/g3offrey)) — [contributions](https://github.com/eamodio/vscode-gitlens/commits?author=g3offrey)) - Yukai Huang ([@Yukaii](https://github.com/Yukaii)) — [contributions](https://github.com/eamodio/vscode-gitlens/commits?author=Yukaii)) - Helmut Januschka ([@hjanuschka](https://github.com/hjanuschka)) — [contributions](https://github.com/eamodio/vscode-gitlens/commits?author=hjanuschka)) - Chris Kaczor ([@ckaczor](https://github.com/ckaczor)) — [contributions](https://github.com/eamodio/vscode-gitlens/commits?author=ckaczor)) diff --git a/package.json b/package.json index ab50226..836e616 100644 --- a/package.json +++ b/package.json @@ -1107,6 +1107,11 @@ "category": "GitLens" }, { + "command": "gitlens.diffWorkingWithBranch", + "title": "Compare Working Tree with Branch or Tag...", + "category": "GitLens" + }, + { "command": "gitlens.diffWith", "title": "Compare File Revisions", "category": "GitLens" @@ -1662,6 +1667,10 @@ "when": "gitlens:enabled" }, { + "command": "gitlens.diffWorkingWithBranch", + "when": "gitlens:enabled" + }, + { "command": "gitlens.diffWith", "when": "false" }, diff --git a/src/commands/common.ts b/src/commands/common.ts index 0fd7f70..c873dfe 100644 --- a/src/commands/common.ts +++ b/src/commands/common.ts @@ -13,6 +13,7 @@ export enum Commands { CopyShaToClipboard = 'gitlens.copyShaToClipboard', DiffDirectory = 'gitlens.diffDirectory', DiffHeadWithBranch = 'gitlens.diffHeadWithBranch', + DiffWorkingWithBranch = 'gitlens.diffWorkingWithBranch', ExternalDiffAll = 'gitlens.externalDiffAll', DiffWith = 'gitlens.diffWith', DiffWithBranch = 'gitlens.diffWithBranch', diff --git a/src/commands/diffBranchWithBranch.ts b/src/commands/diffBranchWithBranch.ts index 7ecc0a1..7cf84c0 100644 --- a/src/commands/diffBranchWithBranch.ts +++ b/src/commands/diffBranchWithBranch.ts @@ -1,19 +1,40 @@ 'use strict'; import { CancellationTokenSource, TextEditor, Uri, window } from 'vscode'; -import { ActiveEditorCommand, Commands, getCommandUri } from './common'; +import { ActiveEditorCommand, CommandContext, Commands, getCommandUri } from './common'; import { GlyphChars } from '../constants'; import { Container } from '../container'; import { Logger } from '../logger'; import { Messages } from '../messages'; import { BranchesAndTagsQuickPick, CommandQuickPickItem } from '../quickPicks'; +export interface DiffBranchWithBranchCommandArgs { + ref1?: string; + ref2?: string; +} + export class DiffBranchWithBranchCommand extends ActiveEditorCommand { constructor() { - super(Commands.DiffHeadWithBranch); + super([Commands.DiffHeadWithBranch, Commands.DiffWorkingWithBranch]); } - async execute(editor?: TextEditor, uri?: Uri): Promise { + protected async preExecute(context: CommandContext, args: DiffBranchWithBranchCommandArgs = {}): Promise { + switch (context.command) { + case Commands.DiffHeadWithBranch: + args.ref2 = 'HEAD'; + break; + + case Commands.DiffWorkingWithBranch: + args.ref2 = ''; + break; + } + + return this.execute(context.editor, context.uri, args); + } + + async execute(editor?: TextEditor, uri?: Uri, args: DiffBranchWithBranchCommandArgs = {}): Promise { + if (args.ref2 === undefined) return; + uri = getCommandUri(uri, editor); let progressCancellation: CancellationTokenSource | undefined; @@ -22,26 +43,39 @@ export class DiffBranchWithBranchCommand extends ActiveEditorCommand { const repoPath = await Container.git.getRepoPath(uri); if (!repoPath) return Messages.showNoRepositoryWarningMessage(`Unable to open branch compare`); - const placeHolder = `Compare Index (HEAD) to ${GlyphChars.Ellipsis}`; + if (!args.ref1) { + let placeHolder; + switch (args.ref2) { + case '': + placeHolder = `Compare Working Tree to ${GlyphChars.Ellipsis}`; + break; + case 'HEAD': + placeHolder = `Compare Index (HEAD) to ${GlyphChars.Ellipsis}`; + break; + default: + placeHolder = `Compare ${args.ref2} to ${GlyphChars.Ellipsis}`; + break; + } - progressCancellation = BranchesAndTagsQuickPick.showProgress(placeHolder); + progressCancellation = BranchesAndTagsQuickPick.showProgress(placeHolder); - const [branches, tags] = await Promise.all([ - Container.git.getBranches(repoPath), - Container.git.getTags(repoPath) - ]); + const [branches, tags] = await Promise.all([ + Container.git.getBranches(repoPath), + Container.git.getTags(repoPath) + ]); - if (progressCancellation.token.isCancellationRequested) return undefined; + if (progressCancellation.token.isCancellationRequested) return undefined; - const pick = await BranchesAndTagsQuickPick.show(branches, tags, placeHolder, { progressCancellation: progressCancellation }); - if (pick === undefined) return undefined; + const pick = await BranchesAndTagsQuickPick.show(branches, tags, placeHolder, { progressCancellation: progressCancellation }); + if (pick === undefined) return undefined; - if (pick instanceof CommandQuickPickItem) return pick.execute(); + if (pick instanceof CommandQuickPickItem) return pick.execute(); - const compareWith = pick.name; - if (compareWith === undefined) return undefined; + args.ref1 = pick.name; + if (args.ref1 === undefined) return undefined; + } - Container.resultsExplorer.showComparisonInResults(repoPath, compareWith, 'HEAD'); + Container.resultsExplorer.showComparisonInResults(repoPath, args.ref1, args.ref2); return undefined; }