Skip to content

Commit 3d994bd

Browse files
committed
Adds compare working tree to branch/tag command
1 parent cb15bd6 commit 3d994bd

File tree

5 files changed

+68
-17
lines changed

5 files changed

+68
-17
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
66

77
## [Unreleased]
88
### Added
9-
- 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)
9+
- 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)
10+
- 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))!
11+
- Adds *Compare Working Tree with Branch or Tag...* (`gitlens.explorers.diffWorkingWithBranch`) command - compares the working tree to the selected branch or tag
1012
- Adds the *Open File* (`gitlens.explorers.openFile`) command to the *GitLens* explorer inline for file nodes
1113
- Adds the *Clear Results* (`gitlen.resultsExplorer.clearResultsNode`) command to the *GitLens Results* view inline for results nodes
1214
- Adds *Push to Commit (via Terminal)* (`gitlens.explorers.terminalPushCommit`) command to commit nodes on the current branch in the *GitLens* explorer

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,10 @@ An on-demand, [customizable](#gitlens-results-view-settings "Jump to the GitLens
451451

452452
- 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
453453

454+
- Adds a *Compare Index (HEAD) with Branch or Tag...* command (`gitlens.diffHeadWithBranch`) to compare the index (HEAD) with the selected branch or tag
455+
456+
- Adds a *Compare Working Tree with Branch or Tag...* command (`gitlens.diffWorkingWithBranch`) to compare the working tree with the selected branch or tag
457+
454458
- 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
455459

456460
- 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
667671
A big thanks to the people that have contributed to this project:
668672

669673
- Amanda Cameron ([@AmandaCameron](https://github.com/AmandaCameron)) — [contributions](https://github.com/eamodio/vscode-gitlens/commits?author=AmandaCameron))
674+
- Geoffrey ([@g3offrey](https://github.com/g3offrey)) — [contributions](https://github.com/eamodio/vscode-gitlens/commits?author=g3offrey))
670675
- Yukai Huang ([@Yukaii](https://github.com/Yukaii)) — [contributions](https://github.com/eamodio/vscode-gitlens/commits?author=Yukaii))
671676
- Helmut Januschka ([@hjanuschka](https://github.com/hjanuschka)) — [contributions](https://github.com/eamodio/vscode-gitlens/commits?author=hjanuschka))
672677
- Chris Kaczor ([@ckaczor](https://github.com/ckaczor)) — [contributions](https://github.com/eamodio/vscode-gitlens/commits?author=ckaczor))

package.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,6 +1106,11 @@
11061106
"title": "Compare Index (HEAD) with Branch or Tag...",
11071107
"category": "GitLens"
11081108
},
1109+
{
1110+
"command": "gitlens.diffWorkingWithBranch",
1111+
"title": "Compare Working Tree with Branch or Tag...",
1112+
"category": "GitLens"
1113+
},
11091114
{
11101115
"command": "gitlens.diffWith",
11111116
"title": "Compare File Revisions",
@@ -1661,6 +1666,10 @@
16611666
"command": "gitlens.diffHeadWithBranch",
16621667
"when": "gitlens:enabled"
16631668
},
1669+
{
1670+
"command": "gitlens.diffWorkingWithBranch",
1671+
"when": "gitlens:enabled"
1672+
},
16641673
{
16651674
"command": "gitlens.diffWith",
16661675
"when": "false"

src/commands/common.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export enum Commands {
1313
CopyShaToClipboard = 'gitlens.copyShaToClipboard',
1414
DiffDirectory = 'gitlens.diffDirectory',
1515
DiffHeadWithBranch = 'gitlens.diffHeadWithBranch',
16+
DiffWorkingWithBranch = 'gitlens.diffWorkingWithBranch',
1617
ExternalDiffAll = 'gitlens.externalDiffAll',
1718
DiffWith = 'gitlens.diffWith',
1819
DiffWithBranch = 'gitlens.diffWithBranch',

src/commands/diffBranchWithBranch.ts

Lines changed: 50 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,40 @@
11
'use strict';
22
import { CancellationTokenSource, TextEditor, Uri, window } from 'vscode';
3-
import { ActiveEditorCommand, Commands, getCommandUri } from './common';
3+
import { ActiveEditorCommand, CommandContext, Commands, getCommandUri } from './common';
44
import { GlyphChars } from '../constants';
55
import { Container } from '../container';
66
import { Logger } from '../logger';
77
import { Messages } from '../messages';
88
import { BranchesAndTagsQuickPick, CommandQuickPickItem } from '../quickPicks';
99

10+
export interface DiffBranchWithBranchCommandArgs {
11+
ref1?: string;
12+
ref2?: string;
13+
}
14+
1015
export class DiffBranchWithBranchCommand extends ActiveEditorCommand {
1116

1217
constructor() {
13-
super(Commands.DiffHeadWithBranch);
18+
super([Commands.DiffHeadWithBranch, Commands.DiffWorkingWithBranch]);
1419
}
1520

16-
async execute(editor?: TextEditor, uri?: Uri): Promise<any> {
21+
protected async preExecute(context: CommandContext, args: DiffBranchWithBranchCommandArgs = {}): Promise<any> {
22+
switch (context.command) {
23+
case Commands.DiffHeadWithBranch:
24+
args.ref2 = 'HEAD';
25+
break;
26+
27+
case Commands.DiffWorkingWithBranch:
28+
args.ref2 = '';
29+
break;
30+
}
31+
32+
return this.execute(context.editor, context.uri, args);
33+
}
34+
35+
async execute(editor?: TextEditor, uri?: Uri, args: DiffBranchWithBranchCommandArgs = {}): Promise<any> {
36+
if (args.ref2 === undefined) return;
37+
1738
uri = getCommandUri(uri, editor);
1839

1940
let progressCancellation: CancellationTokenSource | undefined;
@@ -22,26 +43,39 @@ export class DiffBranchWithBranchCommand extends ActiveEditorCommand {
2243
const repoPath = await Container.git.getRepoPath(uri);
2344
if (!repoPath) return Messages.showNoRepositoryWarningMessage(`Unable to open branch compare`);
2445

25-
const placeHolder = `Compare Index (HEAD) to ${GlyphChars.Ellipsis}`;
46+
if (!args.ref1) {
47+
let placeHolder;
48+
switch (args.ref2) {
49+
case '':
50+
placeHolder = `Compare Working Tree to ${GlyphChars.Ellipsis}`;
51+
break;
52+
case 'HEAD':
53+
placeHolder = `Compare Index (HEAD) to ${GlyphChars.Ellipsis}`;
54+
break;
55+
default:
56+
placeHolder = `Compare ${args.ref2} to ${GlyphChars.Ellipsis}`;
57+
break;
58+
}
2659

27-
progressCancellation = BranchesAndTagsQuickPick.showProgress(placeHolder);
60+
progressCancellation = BranchesAndTagsQuickPick.showProgress(placeHolder);
2861

29-
const [branches, tags] = await Promise.all([
30-
Container.git.getBranches(repoPath),
31-
Container.git.getTags(repoPath)
32-
]);
62+
const [branches, tags] = await Promise.all([
63+
Container.git.getBranches(repoPath),
64+
Container.git.getTags(repoPath)
65+
]);
3366

34-
if (progressCancellation.token.isCancellationRequested) return undefined;
67+
if (progressCancellation.token.isCancellationRequested) return undefined;
3568

36-
const pick = await BranchesAndTagsQuickPick.show(branches, tags, placeHolder, { progressCancellation: progressCancellation });
37-
if (pick === undefined) return undefined;
69+
const pick = await BranchesAndTagsQuickPick.show(branches, tags, placeHolder, { progressCancellation: progressCancellation });
70+
if (pick === undefined) return undefined;
3871

39-
if (pick instanceof CommandQuickPickItem) return pick.execute();
72+
if (pick instanceof CommandQuickPickItem) return pick.execute();
4073

41-
const compareWith = pick.name;
42-
if (compareWith === undefined) return undefined;
74+
args.ref1 = pick.name;
75+
if (args.ref1 === undefined) return undefined;
76+
}
4377

44-
Container.resultsExplorer.showComparisonInResults(repoPath, compareWith, 'HEAD');
78+
Container.resultsExplorer.showComparisonInResults(repoPath, args.ref1, args.ref2);
4579

4680
return undefined;
4781
}

0 commit comments

Comments
 (0)