Browse Source

Closes #316 - Show file history from another branch or tag

Renames Show Branches and Tags -> Choose from Branch or Tag History...
Changes it to show the revision history rather than immediate executing
main
Eric Amodio 6 years ago
parent
commit
a911aca471
6 changed files with 128 additions and 68 deletions
  1. +3
    -0
      CHANGELOG.md
  2. +36
    -21
      src/commands/diffWithRevision.ts
  3. +38
    -20
      src/commands/openFileRevision.ts
  4. +47
    -21
      src/commands/showQuickFileHistory.ts
  5. +2
    -2
      src/quickPicks/commonQuickPicks.ts
  6. +2
    -4
      src/quickPicks/fileHistoryQuickPick.ts

+ 3
- 0
CHANGELOG.md View File

@ -10,10 +10,13 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
- Adds tag annotations to the tag tooltips in the *GitLens* explorer — closes [#431](https://github.com/eamodio/vscode-gitlens/issues/431) - Adds tag annotations to the tag tooltips in the *GitLens* explorer — closes [#431](https://github.com/eamodio/vscode-gitlens/issues/431)
- Adds `gitlens.hovers.avatars` setting to specify whether to show avatar images in hovers — closes [#432](https://github.com/eamodio/vscode-gitlens/issues/432) thanks to [PR #441](https://github.com/eamodio/vscode-gitlens/pull/441) by Segev Finer ([@segevfiner](https://github.com/segevfiner)) - Adds `gitlens.hovers.avatars` setting to specify whether to show avatar images in hovers — closes [#432](https://github.com/eamodio/vscode-gitlens/issues/432) thanks to [PR #441](https://github.com/eamodio/vscode-gitlens/pull/441) by Segev Finer ([@segevfiner](https://github.com/segevfiner))
- Adds `gitlens.hovers.avatars` setting to the interactive settings editor to specify whether to show avatar images in hovers - Adds `gitlens.hovers.avatars` setting to the interactive settings editor to specify whether to show avatar images in hovers
- Adds *Choose from Branch or Tag History...* to the quick pick menu shown by the *Show File History...* command (`gitlens.showQuickFileHistory`) — closes [#316](https://github.com/eamodio/vscode-gitlens/issues/316)
### Changed ### Changed
- Renames the *GitLens History* explorer to *GitLens File History* explorer for better clarity - Renames the *GitLens History* explorer to *GitLens File History* explorer for better clarity
- Changes the *GitLens File History* explorer to always show the full file history even when reviewing revisions - Changes the *GitLens File History* explorer to always show the full file history even when reviewing revisions
- Changes the behavior of and renames the *Show Branches and Tags* command and on the quick pick menu shown by the *Compare File with Revision...* command (`gitlens.diffWithRevision`) to *Choose from Branch or Tag History...*
- Changes the behavior of and renames the *Show Branches and Tags* command on the quick pick menu shown by the *Open Revision...* command (`gitlens.openFileRevision`) to *Choose from Branch or Tag History...*
### Removed ### Removed
- Removes `gitlens:activeIsTracked`, `gitlens:activeIsBlameable`, `gitlens:activeIsRevision`, and `gitlens:activeHasRemotes` contexts and consolidates them into `gitlens:activeFileStatus` for better performance and UX - Removes `gitlens:activeIsTracked`, `gitlens:activeIsBlameable`, `gitlens:activeIsRevision`, and `gitlens:activeHasRemotes` contexts and consolidates them into `gitlens:activeFileStatus` for better performance and UX

+ 36
- 21
src/commands/diffWithRevision.ts View File

@ -5,12 +5,13 @@ import { ActiveEditorCommand, Commands, getCommandUri } from './common';
import { GlyphChars } from '../constants'; import { GlyphChars } from '../constants';
import { Container } from '../container'; import { Container } from '../container';
import { DiffWithCommandArgs } from './diffWith'; import { DiffWithCommandArgs } from './diffWith';
import { GitUri } from '../gitService';
import { GitBranch, GitTag, GitUri } from '../gitService';
import { Logger } from '../logger'; import { Logger } from '../logger';
import { Messages } from '../messages'; import { Messages } from '../messages';
import { CommandQuickPickItem, FileHistoryQuickPick, ShowBranchesAndTagsQuickPickItem } from '../quickPicks/quickPicks'; import { CommandQuickPickItem, FileHistoryQuickPick, ShowBranchesAndTagsQuickPickItem } from '../quickPicks/quickPicks';
export interface DiffWithRevisionCommandArgs { export interface DiffWithRevisionCommandArgs {
branchOrTag?: GitBranch | GitTag;
maxCount?: number; maxCount?: number;
line?: number; line?: number;
@ -34,17 +35,20 @@ export class DiffWithRevisionCommand extends ActiveEditorCommand {
const gitUri = await GitUri.fromUri(uri); const gitUri = await GitUri.fromUri(uri);
const placeHolder = `Compare ${gitUri.getFormattedPath()}${
gitUri.sha ? ` ${Strings.pad(GlyphChars.Dot, 1, 1)} ${gitUri.shortSha}` : ''
} with ${GlyphChars.Ellipsis}`;
const progressCancellation = FileHistoryQuickPick.showProgress(placeHolder);
const placeHolder = `Compare ${gitUri.getFormattedPath(
args.branchOrTag ? ` (${args.branchOrTag.name})${Strings.pad(GlyphChars.Dot, 2, 2)}` : undefined
)}${gitUri.sha ? ` ${Strings.pad(GlyphChars.Dot, 1, 1)} ${gitUri.shortSha}` : ''} with${GlyphChars.Ellipsis}`;
const progressCancellation = FileHistoryQuickPick.showProgress(placeHolder);
try { try {
const log = await Container.git.getLogForFile(gitUri.repoPath, gitUri.fsPath, { const log = await Container.git.getLogForFile(gitUri.repoPath, gitUri.fsPath, {
maxCount: args.maxCount, maxCount: args.maxCount,
ref: gitUri.sha
ref: (args.branchOrTag && args.branchOrTag.name) || gitUri.sha
}); });
if (log === undefined) { if (log === undefined) {
if (args.branchOrTag) {
return window.showWarningMessage(`The file could not be found in ${args.branchOrTag.name}`);
}
return Messages.showFileNotUnderSourceControlWarningMessage('Unable to open history compare'); return Messages.showFileNotUnderSourceControlWarningMessage('Unable to open history compare');
} }
@ -75,21 +79,29 @@ export class DiffWithRevisionCommand extends ActiveEditorCommand {
} }
} }
const currentCommand = new CommandQuickPickItem(
{
label: `go back ${GlyphChars.ArrowBack}`,
description: `${Strings.pad(GlyphChars.Dash, 2, 3)} to history of ${
GlyphChars.Space
}$(file-text) ${gitUri.getFormattedPath()}${
args.branchOrTag
? ` from ${GlyphChars.Space}${
args.branchOrTag instanceof GitTag ? '$(tag)' : '$(git-branch)'
} ${args.branchOrTag.name}`
: gitUri.sha
? ` from ${GlyphChars.Space}$(git-commit) ${gitUri.shortSha}`
: ''
}`
},
Commands.DiffWithRevision,
[uri, { ...args }]
);
const pick = await FileHistoryQuickPick.show(log, gitUri, placeHolder, { const pick = await FileHistoryQuickPick.show(log, gitUri, placeHolder, {
pickerOnly: true, pickerOnly: true,
progressCancellation: progressCancellation, progressCancellation: progressCancellation,
currentCommand: new CommandQuickPickItem(
{
label: `go back ${GlyphChars.ArrowBack}`,
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}` : ''
}`
},
Commands.DiffWithRevision,
[uri, { ...args }]
),
currentCommand: currentCommand,
nextPageCommand: args.nextPageCommand, nextPageCommand: args.nextPageCommand,
previousPageCommand: previousPageCommand, previousPageCommand: previousPageCommand,
showAllCommand: showAllCommand:
@ -100,7 +112,7 @@ export class DiffWithRevisionCommand extends ActiveEditorCommand {
description: `${Strings.pad(GlyphChars.Dash, 2, 3)} this may take a while` description: `${Strings.pad(GlyphChars.Dash, 2, 3)} this may take a while`
}, },
Commands.DiffWithRevision, Commands.DiffWithRevision,
[uri, { ...args, maxCount: 0 }]
[uri, { ...args, maxCount: 0 } as DiffWithRevisionCommandArgs]
) )
: undefined : undefined
}); });
@ -111,10 +123,13 @@ export class DiffWithRevisionCommand extends ActiveEditorCommand {
if (pick instanceof ShowBranchesAndTagsQuickPickItem) { if (pick instanceof ShowBranchesAndTagsQuickPickItem) {
const branchOrTag = await pick.execute(); const branchOrTag = await pick.execute();
if (branchOrTag === undefined) return undefined; if (branchOrTag === undefined) return undefined;
if (branchOrTag instanceof CommandQuickPickItem) return branchOrTag.execute(); if (branchOrTag instanceof CommandQuickPickItem) return branchOrTag.execute();
ref = branchOrTag.name;
return commands.executeCommand(Commands.DiffWithRevision, gitUri, {
...args,
branchOrTag: branchOrTag.branchOrTag,
goBackCommand: currentCommand
} as DiffWithRevisionCommandArgs);
} }
else { else {
if (pick instanceof CommandQuickPickItem) return pick.execute(); if (pick instanceof CommandQuickPickItem) return pick.execute();

+ 38
- 20
src/commands/openFileRevision.ts View File

@ -1,16 +1,17 @@
'use strict'; 'use strict';
import { Iterables, Strings } from '../system'; import { Iterables, Strings } from '../system';
import { CancellationTokenSource, Range, TextDocumentShowOptions, TextEditor, Uri, window } from 'vscode';
import { CancellationTokenSource, commands, Range, TextDocumentShowOptions, TextEditor, Uri, window } from 'vscode';
import { ActiveEditorCommand, Commands, getCommandUri, openEditor } from './common'; import { ActiveEditorCommand, Commands, getCommandUri, openEditor } from './common';
import { FileAnnotationType } from '../configuration'; import { FileAnnotationType } from '../configuration';
import { GlyphChars } from '../constants'; import { GlyphChars } from '../constants';
import { Container } from '../container'; import { Container } from '../container';
import { GitUri } from '../gitService';
import { GitBranch, GitTag, GitUri } from '../gitService';
import { Logger } from '../logger'; import { Logger } from '../logger';
import { Messages } from '../messages'; import { Messages } from '../messages';
import { CommandQuickPickItem, FileHistoryQuickPick, ShowBranchesAndTagsQuickPickItem } from '../quickPicks/quickPicks'; import { CommandQuickPickItem, FileHistoryQuickPick, ShowBranchesAndTagsQuickPickItem } from '../quickPicks/quickPicks';
export interface OpenFileRevisionCommandArgs { export interface OpenFileRevisionCommandArgs {
branchOrTag?: GitBranch | GitTag;
uri?: Uri; uri?: Uri;
maxCount?: number; maxCount?: number;
@ -64,16 +65,22 @@ export class OpenFileRevisionCommand extends ActiveEditorCommand {
const gitUri = await GitUri.fromUri(uri); const gitUri = await GitUri.fromUri(uri);
const placeHolder = `Open ${gitUri.getFormattedPath()}${
gitUri.sha ? ` ${Strings.pad(GlyphChars.Dot, 1, 1)} ${gitUri.shortSha}` : ''
} in revision ${GlyphChars.Ellipsis}`;
const placeHolder = `Open revision of ${gitUri.getFormattedPath(
args.branchOrTag ? ` (${args.branchOrTag.name})${Strings.pad(GlyphChars.Dot, 2, 2)}` : undefined
)}${gitUri.sha ? ` ${Strings.pad(GlyphChars.Dot, 1, 1)} ${gitUri.shortSha}` : ''}${
GlyphChars.Ellipsis
}`;
progressCancellation = FileHistoryQuickPick.showProgress(placeHolder); progressCancellation = FileHistoryQuickPick.showProgress(placeHolder);
const log = await Container.git.getLogForFile(gitUri.repoPath, gitUri.fsPath, { const log = await Container.git.getLogForFile(gitUri.repoPath, gitUri.fsPath, {
maxCount: args.maxCount, maxCount: args.maxCount,
ref: gitUri.sha
ref: (args.branchOrTag && args.branchOrTag.name) || gitUri.sha
}); });
if (log === undefined) { if (log === undefined) {
if (args.branchOrTag) {
return window.showWarningMessage(`The file could not be found in ${args.branchOrTag.name}`);
}
return Messages.showFileNotUnderSourceControlWarningMessage('Unable to open history compare'); return Messages.showFileNotUnderSourceControlWarningMessage('Unable to open history compare');
} }
@ -104,21 +111,29 @@ export class OpenFileRevisionCommand extends ActiveEditorCommand {
} }
} }
const currentCommand = new CommandQuickPickItem(
{
label: `go back ${GlyphChars.ArrowBack}`,
description: `${Strings.pad(GlyphChars.Dash, 2, 3)} to history of ${
GlyphChars.Space
}$(file-text) ${gitUri.getFormattedPath()}${
args.branchOrTag
? ` from ${GlyphChars.Space}${
args.branchOrTag instanceof GitTag ? '$(tag)' : '$(git-branch)'
} ${args.branchOrTag.name}`
: gitUri.sha
? ` from ${GlyphChars.Space}$(git-commit) ${gitUri.shortSha}`
: ''
}`
},
Commands.OpenFileRevision,
[uri, { ...args }]
);
const pick = await FileHistoryQuickPick.show(log, gitUri, placeHolder, { const pick = await FileHistoryQuickPick.show(log, gitUri, placeHolder, {
pickerOnly: true, pickerOnly: true,
progressCancellation: progressCancellation, progressCancellation: progressCancellation,
currentCommand: new CommandQuickPickItem(
{
label: `go back ${GlyphChars.ArrowBack}`,
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}` : ''
}`
},
Commands.OpenFileRevision,
[uri, { ...args }]
),
currentCommand: currentCommand,
nextPageCommand: args.nextPageCommand, nextPageCommand: args.nextPageCommand,
previousPageCommand: previousPageCommand, previousPageCommand: previousPageCommand,
showAllCommand: showAllCommand:
@ -138,10 +153,13 @@ export class OpenFileRevisionCommand extends ActiveEditorCommand {
if (pick instanceof ShowBranchesAndTagsQuickPickItem) { if (pick instanceof ShowBranchesAndTagsQuickPickItem) {
const branchOrTag = await pick.execute(); const branchOrTag = await pick.execute();
if (branchOrTag === undefined) return undefined; if (branchOrTag === undefined) return undefined;
if (branchOrTag instanceof CommandQuickPickItem) return branchOrTag.execute(); if (branchOrTag instanceof CommandQuickPickItem) return branchOrTag.execute();
args.uri = GitUri.toRevisionUri(branchOrTag.name, gitUri.fsPath, gitUri.repoPath!);
return commands.executeCommand(Commands.OpenFileRevision, gitUri, {
...args,
branchOrTag: branchOrTag.branchOrTag,
goBackCommand: currentCommand
} as OpenFileRevisionCommandArgs);
} }
else { else {
if (pick instanceof CommandQuickPickItem) return pick.execute(); if (pick instanceof CommandQuickPickItem) return pick.execute();

+ 47
- 21
src/commands/showQuickFileHistory.ts View File

@ -1,14 +1,15 @@
'use strict'; 'use strict';
import { Iterables, Strings } from '../system';
import { commands, Range, TextEditor, Uri, window } from 'vscode'; import { commands, Range, TextEditor, Uri, window } from 'vscode';
import { Iterables, Strings } from '../system';
import { ActiveEditorCachedCommand, Commands, getCommandUri } from './common'; import { ActiveEditorCachedCommand, Commands, getCommandUri } from './common';
import { GlyphChars } from '../constants'; import { GlyphChars } from '../constants';
import { Container } from '../container'; import { Container } from '../container';
import { GitLog, GitUri } from '../gitService';
import { GitBranch, GitLog, GitTag, GitUri } from '../gitService';
import { Logger } from '../logger'; import { Logger } from '../logger';
import { import {
CommandQuickPickItem, CommandQuickPickItem,
FileHistoryQuickPick, FileHistoryQuickPick,
ShowBranchesAndTagsQuickPickItem,
ShowCommitsInResultsQuickPickItem ShowCommitsInResultsQuickPickItem
} from '../quickPicks/quickPicks'; } from '../quickPicks/quickPicks';
import { ShowQuickCommitFileDetailsCommandArgs } from './showQuickCommitFileDetails'; import { ShowQuickCommitFileDetailsCommandArgs } from './showQuickCommitFileDetails';
@ -16,6 +17,7 @@ import { Messages } from '../messages';
import * as path from 'path'; import * as path from 'path';
export interface ShowQuickFileHistoryCommandArgs { export interface ShowQuickFileHistoryCommandArgs {
branchOrTag?: GitBranch | GitTag;
log?: GitLog; log?: GitLog;
maxCount?: number; maxCount?: number;
range?: Range; range?: Range;
@ -37,9 +39,9 @@ export class ShowQuickFileHistoryCommand extends ActiveEditorCachedCommand {
args = { ...args }; args = { ...args };
const placeHolder = `${gitUri.getFormattedPath()}${
gitUri.sha ? ` ${Strings.pad(GlyphChars.Dot, 1, 1)} ${gitUri.shortSha}` : ''
}`;
const placeHolder = `${gitUri.getFormattedPath(
args.branchOrTag ? ` (${args.branchOrTag.name})${Strings.pad(GlyphChars.Dot, 2, 2)}` : undefined
)}${gitUri.sha ? ` ${Strings.pad(GlyphChars.Dot, 1, 1)} ${gitUri.shortSha}` : ''}`;
const progressCancellation = FileHistoryQuickPick.showProgress(placeHolder); const progressCancellation = FileHistoryQuickPick.showProgress(placeHolder);
try { try {
@ -47,9 +49,12 @@ export class ShowQuickFileHistoryCommand extends ActiveEditorCachedCommand {
args.log = await Container.git.getLogForFile(gitUri.repoPath, gitUri.fsPath, { args.log = await Container.git.getLogForFile(gitUri.repoPath, gitUri.fsPath, {
maxCount: args.maxCount, maxCount: args.maxCount,
range: args.range, range: args.range,
ref: gitUri.sha
ref: (args.branchOrTag && args.branchOrTag.name) || gitUri.sha
}); });
if (args.log === undefined) { if (args.log === undefined) {
if (args.branchOrTag) {
return window.showWarningMessage(`The file could not be found in ${args.branchOrTag.name}`);
}
return Messages.showFileNotUnderSourceControlWarningMessage('Unable to show file history'); return Messages.showFileNotUnderSourceControlWarningMessage('Unable to show file history');
} }
} }
@ -86,8 +91,29 @@ export class ShowQuickFileHistoryCommand extends ActiveEditorCachedCommand {
} }
} }
// Create a command to get back to where we are right now
const currentCommand = new CommandQuickPickItem(
{
label: `go back ${GlyphChars.ArrowBack}`,
description: `${Strings.pad(GlyphChars.Dash, 2, 3)} to history of ${
GlyphChars.Space
}$(file-text) ${path.basename(gitUri.fsPath)}${
args.branchOrTag
? ` from ${GlyphChars.Space}${
args.branchOrTag instanceof GitTag ? '$(tag)' : '$(git-branch)'
} ${args.branchOrTag.name}`
: gitUri.sha
? ` from ${GlyphChars.Space}$(git-commit) ${gitUri.shortSha}`
: ''
}`
},
Commands.ShowQuickFileHistory,
[uri, args]
);
const pick = await FileHistoryQuickPick.show(args.log, gitUri, placeHolder, { const pick = await FileHistoryQuickPick.show(args.log, gitUri, placeHolder, {
progressCancellation: progressCancellation, progressCancellation: progressCancellation,
currentCommand: currentCommand,
goBackCommand: args.goBackCommand, goBackCommand: args.goBackCommand,
nextPageCommand: args.nextPageCommand, nextPageCommand: args.nextPageCommand,
previousPageCommand: previousPageCommand, previousPageCommand: previousPageCommand,
@ -112,21 +138,21 @@ export class ShowQuickFileHistoryCommand extends ActiveEditorCachedCommand {
}); });
if (pick === undefined) return undefined; if (pick === undefined) return undefined;
if (pick instanceof CommandQuickPickItem) return pick.execute();
// Create a command to get back to where we are right now
const currentCommand = new CommandQuickPickItem(
{
label: `go back ${GlyphChars.ArrowBack}`,
description: `${Strings.pad(GlyphChars.Dash, 2, 3)} to history of ${
GlyphChars.Space
}$(file-text) ${path.basename(pick.commit.fileName)}${
gitUri.sha ? ` from ${GlyphChars.Space}$(git-commit) ${gitUri.shortSha}` : ''
}`
},
Commands.ShowQuickFileHistory,
[uri, args]
);
if (pick instanceof ShowBranchesAndTagsQuickPickItem) {
const branchOrTag = await pick.execute();
if (branchOrTag === undefined) return undefined;
if (branchOrTag instanceof CommandQuickPickItem) return branchOrTag.execute();
return commands.executeCommand(Commands.ShowQuickFileHistory, gitUri, {
...args,
log: undefined,
branchOrTag: branchOrTag.branchOrTag,
goBackCommand: currentCommand
} as ShowQuickFileHistoryCommandArgs);
}
else {
if (pick instanceof CommandQuickPickItem) return pick.execute();
}
return commands.executeCommand(Commands.ShowQuickCommitFileDetails, pick.commit.toGitUri(), { return commands.executeCommand(Commands.ShowQuickCommitFileDetails, pick.commit.toGitUri(), {
commit: pick.commit, commit: pick.commit,

+ 2
- 2
src/quickPicks/commonQuickPicks.ts View File

@ -250,8 +250,8 @@ export class ShowBranchesAndTagsQuickPickItem extends CommandQuickPickItem {
private readonly placeHolder: string, private readonly placeHolder: string,
private readonly goBackCommand?: CommandQuickPickItem, private readonly goBackCommand?: CommandQuickPickItem,
item: QuickPickItem = { item: QuickPickItem = {
label: 'Show Branches and Tags',
description: `${Strings.pad(GlyphChars.Dash, 2, 2)} displays branches and tags`
label: 'Choose from Branch or Tag History...',
description: `${Strings.pad(GlyphChars.Dash, 2, 2)} shows list of branches and tags`
} }
) { ) {
super(item, undefined, undefined); super(item, undefined, undefined);

+ 2
- 4
src/quickPicks/fileHistoryQuickPick.ts View File

@ -48,10 +48,8 @@ export class FileHistoryQuickPick {
let index = 0; let index = 0;
if (options.pickerOnly) {
index++;
items.splice(0, 0, new ShowBranchesAndTagsQuickPickItem(log.repoPath, placeHolder, options.currentCommand));
}
index++;
items.splice(0, 0, new ShowBranchesAndTagsQuickPickItem(log.repoPath, placeHolder, options.currentCommand));
if (options.showInResultsExplorerCommand !== undefined) { if (options.showInResultsExplorerCommand !== undefined) {
index++; index++;

Loading…
Cancel
Save