Skip to content

Commit aa55304

Browse files
committed
Closes #204 - Adds tag support to commands
1 parent 29b455d commit aa55304

17 files changed

+282
-84
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
88
### Added
99
- Adds `Open Working File` command (`gitlens.openWorkingFile`) - opens the working file for the active file revision -- closes [#236](https://github.com/eamodio/vscode-gitlens/issues/236)
1010
- Adds `Open Revision...` command (`gitlens.openFileRevision`) - opens the selected revision for the active file
11+
- Adds tags to the `Compare File with Branch...` command (`gitlens.diffWithBranch`) -- closes [#204](https://github.com/eamodio/vscode-gitlens/issues/204)
12+
- Adds tags to the `Directory Compare Working Tree with...` command (`gitlens.diffDirectory`) -- closes [#204](https://github.com/eamodio/vscode-gitlens/issues/204)
13+
- Adds `Show Branches and Tags` to quick pick menu shown by the `Compare File with Revision...` command (`gitlens.diffWithRevision`) -- closes [#204](https://github.com/eamodio/vscode-gitlens/issues/204)
14+
- Adds `Show Branches and Tags` to quick pick menu shown by the `Open Revision...` command (`gitlens.openFileRevision`) -- closes [#204](https://github.com/eamodio/vscode-gitlens/issues/204)
15+
16+
### Changed
17+
- Renames `Compare File with Branch...` command (`gitlens.diffWithBranch`) to `Compare File with Branch or Tag...`
1118

1219
### Fixed
1320
- Fixes issues with commit paging in certain quick pick menus

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,9 +308,9 @@ While GitLens is highly customizable and provides many [configuration settings](
308308

309309
- Provides easy access to the following comparison commands via the `Command Palette` as well as in context via the many provided quick pick menus
310310

311-
- 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
311+
- 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
312312

313-
- Adds a `Compare File with Branch...` command (`gitlens.diffWithBranch`) to compare the active file with the same file on the selected branch
313+
- 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
314314

315315
- 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
316316

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1144,7 +1144,7 @@
11441144
},
11451145
{
11461146
"command": "gitlens.diffWithBranch",
1147-
"title": "Compare File with Branch...",
1147+
"title": "Compare File with Branch or Tag...",
11481148
"category": "GitLens"
11491149
},
11501150
{

src/commands/common.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -290,22 +290,24 @@ export abstract class EditorCommand extends Disposable {
290290
abstract execute(editor: TextEditor, edit: TextEditorEdit, ...args: any[]): any;
291291
}
292292

293-
export async function openEditor(uri: Uri, options?: TextDocumentShowOptions): Promise<TextEditor | undefined> {
293+
export async function openEditor(uri: Uri, options: TextDocumentShowOptions & { rethrow?: boolean } = {}): Promise<TextEditor | undefined> {
294+
const { rethrow, ...opts } = options;
294295
try {
295-
const defaults: TextDocumentShowOptions = {
296-
preserveFocus: false,
297-
preview: true,
298-
viewColumn: (window.activeTextEditor && window.activeTextEditor.viewColumn) || 1
299-
};
300-
301296
if (uri instanceof GitUri) {
302297
uri = uri.fileUri(false);
303298
}
304299

305300
const document = await workspace.openTextDocument(uri);
306-
return window.showTextDocument(document, { ...defaults, ...(options || {}) });
301+
return window.showTextDocument(document, {
302+
preserveFocus: false,
303+
preview: true,
304+
viewColumn: (window.activeTextEditor && window.activeTextEditor.viewColumn) || 1,
305+
...opts
306+
});
307307
}
308308
catch (ex) {
309+
if (rethrow) throw ex;
310+
309311
Logger.error(ex, 'openEditor');
310312
return undefined;
311313
}

src/commands/diffDirectory.ts

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
'use strict';
2-
import { commands, TextEditor, Uri, window } from 'vscode';
2+
import { CancellationTokenSource, commands, TextEditor, Uri, window } from 'vscode';
33
import { ActiveEditorCommand, Commands, getCommandUri } from './common';
44
import { CommandContext, isCommandViewContextWithRef } from '../commands';
55
import { BuiltInCommands, GlyphChars } from '../constants';
66
import { ComparisionResultsNode } from '../views/explorerNodes';
77
import { GitService } from '../gitService';
88
import { Logger } from '../logger';
99
import { Messages } from '../messages';
10-
import { BranchesQuickPick, CommandQuickPickItem } from '../quickPicks';
10+
import { BranchesAndTagsQuickPick, CommandQuickPickItem } from '../quickPicks';
1111

1212
export interface DiffDirectoryCommandCommandArgs {
1313
ref1?: string;
@@ -50,20 +50,32 @@ export class DiffDirectoryCommand extends ActiveEditorCommand {
5050
async execute(editor?: TextEditor, uri?: Uri, args: DiffDirectoryCommandCommandArgs = {}): Promise<any> {
5151
uri = getCommandUri(uri, editor);
5252

53+
let progressCancellation: CancellationTokenSource | undefined;
54+
5355
try {
5456
const repoPath = await this.git.getRepoPath(uri);
5557
if (!repoPath) return Messages.showNoRepositoryWarningMessage(`Unable to open directory compare`);
5658

5759
if (!args.ref1) {
5860
args = { ...args };
5961

60-
const branches = await this.git.getBranches(repoPath);
61-
const pick = await BranchesQuickPick.show(branches, `Compare Working Tree to ${GlyphChars.Ellipsis}`);
62+
const placeHolder = `Compare Working Tree to ${GlyphChars.Ellipsis}`;
63+
64+
progressCancellation = BranchesAndTagsQuickPick.showProgress(placeHolder);
65+
66+
const [branches, tags] = await Promise.all([
67+
this.git.getBranches(repoPath),
68+
this.git.getTags(repoPath)
69+
]);
70+
71+
if (progressCancellation.token.isCancellationRequested) return undefined;
72+
73+
const pick = await BranchesAndTagsQuickPick.show(branches, tags, placeHolder, { progressCancellation: progressCancellation });
6274
if (pick === undefined) return undefined;
6375

6476
if (pick instanceof CommandQuickPickItem) return pick.execute();
6577

66-
args.ref1 = pick.branch.name;
78+
args.ref1 = pick.name;
6779
if (args.ref1 === undefined) return undefined;
6880
}
6981

@@ -82,5 +94,8 @@ export class DiffDirectoryCommand extends ActiveEditorCommand {
8294
Logger.error(ex, 'DiffDirectoryCommand');
8395
return window.showErrorMessage(`Unable to open directory compare. See output channel for more details`);
8496
}
97+
finally {
98+
progressCancellation && progressCancellation.dispose();
99+
}
85100
}
86101
}

src/commands/diffWith.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,13 @@ export class DiffWithCommand extends ActiveEditorCommand {
123123

124124
let lhsPrefix = '';
125125
if (lhs === undefined && args.rhs.sha === '') {
126-
lhsPrefix = 'deleted in ';
126+
if (rhs !== undefined) {
127+
lhsPrefix = 'not in ';
128+
rhsPrefix = '';
129+
}
130+
else {
131+
lhsPrefix = 'deleted in ';
132+
}
127133
}
128134

129135
if (args.lhs.title === undefined && args.lhs.sha !== GitService.deletedSha && (lhs !== undefined || lhsPrefix !== '')) {

src/commands/diffWithBranch.ts

Lines changed: 47 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { GlyphChars } from '../constants';
55
import { DiffWithCommandArgs } from './diffWith';
66
import { GitService, GitUri } from '../gitService';
77
import { Messages } from '../messages';
8-
import { BranchesQuickPick, CommandQuickPickItem } from '../quickPicks';
8+
import { BranchesAndTagsQuickPick, CommandQuickPickItem } from '../quickPicks';
99
import * as path from 'path';
1010

1111
export interface DiffWithBranchCommandArgs {
@@ -35,43 +35,57 @@ export class DiffWithBranchCommand extends ActiveEditorCommand {
3535
const gitUri = await GitUri.fromUri(uri, this.git);
3636
if (!gitUri.repoPath) return Messages.showNoRepositoryWarningMessage(`Unable to open branch compare`);
3737

38-
const branches = await this.git.getBranches(gitUri.repoPath);
39-
const pick = await BranchesQuickPick.show(branches, `Compare ${path.basename(gitUri.fsPath)} to ${GlyphChars.Ellipsis}`, args.goBackCommand);
40-
if (pick === undefined) return undefined;
38+
const placeHolder = `Compare ${path.basename(gitUri.fsPath)} with ${GlyphChars.Ellipsis}`;
39+
const progressCancellation = BranchesAndTagsQuickPick.showProgress(placeHolder);
4140

42-
if (pick instanceof CommandQuickPickItem) return pick.execute();
41+
try {
42+
const [branches, tags] = await Promise.all([
43+
this.git.getBranches(gitUri.repoPath),
44+
this.git.getTags(gitUri.repoPath)
45+
]);
4346

44-
const branch = pick.branch.name;
45-
if (branch === undefined) return undefined;
47+
if (progressCancellation.token.isCancellationRequested) return undefined;
4648

47-
let renamedUri: Uri | undefined;
48-
let renamedTitle: string | undefined;
49+
const pick = await BranchesAndTagsQuickPick.show(branches, tags, placeHolder, { progressCancellation: progressCancellation, goBackCommand: args.goBackCommand });
50+
if (pick === undefined) return undefined;
4951

50-
// Check to see if this file has been renamed
51-
const statuses = await this.git.getDiffStatus(gitUri.repoPath, 'HEAD', branch, { filter: 'R' });
52-
if (statuses !== undefined) {
53-
const fileName = GitService.normalizePath(path.relative(gitUri.repoPath, gitUri.fsPath));
54-
const rename = statuses.find(s => s.fileName === fileName);
55-
if (rename !== undefined && rename.originalFileName !== undefined) {
56-
renamedUri = Uri.file(path.join(gitUri.repoPath, rename.originalFileName));
57-
renamedTitle = `${path.basename(rename.originalFileName)} (${branch})`;
52+
if (pick instanceof CommandQuickPickItem) return pick.execute();
53+
54+
const ref = pick.name;
55+
if (ref === undefined) return undefined;
56+
57+
let renamedUri: Uri | undefined;
58+
let renamedTitle: string | undefined;
59+
60+
// Check to see if this file has been renamed
61+
const statuses = await this.git.getDiffStatus(gitUri.repoPath, 'HEAD', ref, { filter: 'R' });
62+
if (statuses !== undefined) {
63+
const fileName = GitService.normalizePath(path.relative(gitUri.repoPath, gitUri.fsPath));
64+
const rename = statuses.find(s => s.fileName === fileName);
65+
if (rename !== undefined && rename.originalFileName !== undefined) {
66+
renamedUri = Uri.file(path.join(gitUri.repoPath, rename.originalFileName));
67+
renamedTitle = `${path.basename(rename.originalFileName)} (${ref})`;
68+
}
5869
}
59-
}
6070

61-
const diffArgs: DiffWithCommandArgs = {
62-
repoPath: gitUri.repoPath,
63-
lhs: {
64-
sha: pick.branch.remote ? `remotes/${branch}` : branch,
65-
uri: renamedUri || gitUri as Uri,
66-
title: renamedTitle || `${path.basename(gitUri.fsPath)} (${branch})`
67-
},
68-
rhs: {
69-
sha: '',
70-
uri: gitUri as Uri
71-
},
72-
line: args.line,
73-
showOptions: args.showOptions
74-
};
75-
return commands.executeCommand(Commands.DiffWith, diffArgs);
71+
const diffArgs: DiffWithCommandArgs = {
72+
repoPath: gitUri.repoPath,
73+
lhs: {
74+
sha: pick.remote ? `remotes/${ref}` : ref,
75+
uri: renamedUri || gitUri as Uri,
76+
title: renamedTitle || `${path.basename(gitUri.fsPath)} (${ref})`
77+
},
78+
rhs: {
79+
sha: '',
80+
uri: gitUri as Uri
81+
},
82+
line: args.line,
83+
showOptions: args.showOptions
84+
};
85+
return commands.executeCommand(Commands.DiffWith, diffArgs);
86+
}
87+
finally {
88+
progressCancellation.dispose();
89+
}
7690
}
7791
}

src/commands/diffWithRevision.ts

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { DiffWithCommandArgs } from './diffWith';
77
import { GitService, GitUri } from '../gitService';
88
import { Logger } from '../logger';
99
import { Messages } from '../messages';
10-
import { CommandQuickPickItem, FileHistoryQuickPick } from '../quickPicks';
10+
import { CommandQuickPickItem, FileHistoryQuickPick, ShowBranchesAndTagsQuickPickItem } from '../quickPicks';
1111

1212
export interface DiffWithRevisionCommandArgs {
1313
maxCount?: number;
@@ -36,7 +36,9 @@ export class DiffWithRevisionCommand extends ActiveEditorCommand {
3636

3737
const gitUri = await GitUri.fromUri(uri, this.git);
3838

39-
const progressCancellation = FileHistoryQuickPick.showProgress(gitUri);
39+
const placeHolder = `Compare ${gitUri.getFormattedPath()}${gitUri.sha ? ` ${Strings.pad(GlyphChars.Dot, 1, 1)} ${gitUri.shortSha}` : ''} with ${GlyphChars.Ellipsis}`;
40+
const progressCancellation = FileHistoryQuickPick.showProgress(placeHolder);
41+
4042
try {
4143
const log = await this.git.getLogForFile(gitUri.repoPath, gitUri.fsPath, { maxCount: args.maxCount, ref: gitUri.sha });
4244
if (log === undefined) return Messages.showFileNotUnderSourceControlWarningMessage('Unable to open history compare');
@@ -60,9 +62,13 @@ export class DiffWithRevisionCommand extends ActiveEditorCommand {
6062
}
6163
}
6264

63-
const label = `${gitUri.getFormattedPath()}${gitUri.sha ? ` ${Strings.pad(GlyphChars.Dot, 1, 1)} ${gitUri.shortSha}` : ''}`;
64-
const pick = await FileHistoryQuickPick.show(this.git, log, gitUri, label, progressCancellation, {
65+
const pick = await FileHistoryQuickPick.show(this.git, log, gitUri, placeHolder, {
6566
pickerOnly: true,
67+
progressCancellation: progressCancellation,
68+
currentCommand: new CommandQuickPickItem({
69+
label: `go back ${GlyphChars.ArrowBack}`,
70+
description: `${Strings.pad(GlyphChars.Dash, 2, 3)} to history of ${GlyphChars.Space}$(file-text) ${gitUri.getFormattedPath()}${gitUri.sha ? ` from ${GlyphChars.Space}$(git-commit) ${gitUri.shortSha}` : ''}`
71+
}, Commands.DiffWithRevision, [uri, { ...args }]),
6672
nextPageCommand: args.nextPageCommand,
6773
previousPageCommand: previousPageCommand,
6874
showAllCommand: log !== undefined && log.truncated
@@ -74,12 +80,26 @@ export class DiffWithRevisionCommand extends ActiveEditorCommand {
7480
});
7581
if (pick === undefined) return undefined;
7682

77-
if (pick instanceof CommandQuickPickItem) return pick.execute();
83+
let ref: string;
84+
85+
if (pick instanceof ShowBranchesAndTagsQuickPickItem) {
86+
const branchOrTag = await pick.execute();
87+
if (branchOrTag === undefined) return undefined;
88+
89+
if (branchOrTag instanceof CommandQuickPickItem) return branchOrTag.execute();
90+
91+
ref = branchOrTag.name;
92+
}
93+
else {
94+
if (pick instanceof CommandQuickPickItem) return pick.execute();
95+
96+
ref = pick.commit.sha;
97+
}
7898

7999
const diffArgs: DiffWithCommandArgs = {
80100
repoPath: gitUri.repoPath,
81101
lhs: {
82-
sha: pick.commit.sha,
102+
sha: ref,
83103
uri: gitUri as Uri
84104
},
85105
rhs: {

0 commit comments

Comments
 (0)