mirror of
https://github.com/ckaczor/vscode-gitlens.git
synced 2026-02-16 10:58:34 -05:00
Fixes issue showing repo history w/ no active editor
This commit is contained in:
@@ -25,7 +25,7 @@ export class ShowQuickFileHistoryCommand extends ActiveEditorCommand {
|
|||||||
maxCount = this.git.config.advanced.maxQuickHistory;
|
maxCount = this.git.config.advanced.maxQuickHistory;
|
||||||
}
|
}
|
||||||
|
|
||||||
const progressCancellation = FileHistoryQuickPick.showProgress(maxCount);
|
const progressCancellation = FileHistoryQuickPick.showProgress(gitUri);
|
||||||
try {
|
try {
|
||||||
if (!log) {
|
if (!log) {
|
||||||
log = await this.git.getLogForFile(gitUri.fsPath, gitUri.sha, gitUri.repoPath, undefined, maxCount);
|
log = await this.git.getLogForFile(gitUri.fsPath, gitUri.sha, gitUri.repoPath, undefined, maxCount);
|
||||||
|
|||||||
@@ -16,22 +16,21 @@ export class ShowQuickRepoHistoryCommand extends ActiveEditorCommand {
|
|||||||
uri = editor && editor.document && editor.document.uri;
|
uri = editor && editor.document && editor.document.uri;
|
||||||
}
|
}
|
||||||
|
|
||||||
const gitUri = await GitUri.fromUri(uri, this.git);
|
const gitUri = uri && await GitUri.fromUri(uri, this.git);
|
||||||
Logger.log(`ShowQuickRepoHistoryCommand.execute`, gitUri.shortSha);
|
|
||||||
|
|
||||||
if (maxCount == null) {
|
if (maxCount == null) {
|
||||||
maxCount = this.git.config.advanced.maxQuickHistory;
|
maxCount = this.git.config.advanced.maxQuickHistory;
|
||||||
}
|
}
|
||||||
|
|
||||||
const progressCancellation = RepoHistoryQuickPick.showProgress(maxCount);
|
const progressCancellation = RepoHistoryQuickPick.showProgress();
|
||||||
try {
|
try {
|
||||||
if (!log) {
|
if (!log) {
|
||||||
const repoPath = gitUri.repoPath || await this.git.getRepoPathFromUri(uri, this.repoPath);
|
const repoPath = (gitUri && gitUri.repoPath) || await this.git.getRepoPathFromUri(uri, this.repoPath);
|
||||||
if (!repoPath) return window.showWarningMessage(`Unable to show repository history`);
|
if (!repoPath) return window.showWarningMessage(`Unable to show repository history`);
|
||||||
|
|
||||||
if (progressCancellation.token.isCancellationRequested) return undefined;
|
if (progressCancellation.token.isCancellationRequested) return undefined;
|
||||||
|
|
||||||
log = await this.git.getLogForRepo(repoPath, gitUri.sha, maxCount);
|
log = await this.git.getLogForRepo(repoPath, (gitUri && gitUri.sha), maxCount);
|
||||||
if (!log) return window.showWarningMessage(`Unable to show repository history`);
|
if (!log) return window.showWarningMessage(`Unable to show repository history`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,9 @@ export class GitUri extends Uri {
|
|||||||
repoPath?: string | undefined;
|
repoPath?: string | undefined;
|
||||||
sha?: string | undefined;
|
sha?: string | undefined;
|
||||||
|
|
||||||
constructor(uri?: Uri, commit?: IGitCommitInfo) {
|
constructor(uri?: Uri, commit?: IGitCommitInfo);
|
||||||
|
constructor(uri?: Uri, repoPath?: string);
|
||||||
|
constructor(uri?: Uri, commitOrRepoPath?: IGitCommitInfo | string) {
|
||||||
super();
|
super();
|
||||||
if (!uri) return;
|
if (!uri) return;
|
||||||
|
|
||||||
@@ -33,12 +35,18 @@ export class GitUri extends Uri {
|
|||||||
this.repoPath = data.repoPath;
|
this.repoPath = data.repoPath;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (commit) {
|
else if (commitOrRepoPath) {
|
||||||
base._fsPath = path.resolve(commit.repoPath, commit.originalFileName || commit.fileName);
|
if (typeof commitOrRepoPath === 'string') {
|
||||||
|
this.repoPath = commitOrRepoPath;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
const commit = commitOrRepoPath;
|
||||||
|
base._fsPath = path.resolve(commit.repoPath, commit.originalFileName || commit.fileName);
|
||||||
|
|
||||||
if (!Git.isUncommitted(commit.sha)) {
|
if (!Git.isUncommitted(commit.sha)) {
|
||||||
this.sha = commit.sha;
|
this.sha = commit.sha;
|
||||||
this.repoPath = commit.repoPath;
|
this.repoPath = commit.repoPath;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -51,6 +59,16 @@ export class GitUri extends Uri {
|
|||||||
return Uri.file(this.sha ? this.path : this.fsPath);
|
return Uri.file(this.sha ? this.path : this.fsPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getFormattedPath(separator: string = ' \u00a0\u2022\u00a0 '): string {
|
||||||
|
let directory = path.dirname(this.fsPath);
|
||||||
|
if (this.repoPath) {
|
||||||
|
directory = path.relative(this.repoPath, directory);
|
||||||
|
}
|
||||||
|
return (!directory || directory === '.')
|
||||||
|
? path.basename(this.fsPath)
|
||||||
|
: `${path.basename(this.fsPath)}${separator}${directory}`;
|
||||||
|
}
|
||||||
|
|
||||||
static async fromUri(uri: Uri, git: GitProvider) {
|
static async fromUri(uri: Uri, git: GitProvider) {
|
||||||
if (uri instanceof GitUri) return uri;
|
if (uri instanceof GitUri) return uri;
|
||||||
|
|
||||||
@@ -64,7 +82,7 @@ export class GitUri extends Uri {
|
|||||||
if (commit) return new GitUri(uri, commit);
|
if (commit) return new GitUri(uri, commit);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new GitUri(uri);
|
return new GitUri(uri, git && git.repoPath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -58,9 +58,10 @@ export class GitProvider extends Disposable {
|
|||||||
return this._onDidBlameFailEmitter.event;
|
return this._onDidBlameFailEmitter.event;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public repoPath: string;
|
||||||
|
|
||||||
private _gitCache: Map<string, GitCacheEntry> | undefined;
|
private _gitCache: Map<string, GitCacheEntry> | undefined;
|
||||||
private _cacheDisposable: Disposable | undefined;
|
private _cacheDisposable: Disposable | undefined;
|
||||||
private _repoPath: string;
|
|
||||||
private _uriCache: Map<string, UriCacheEntry> | undefined;
|
private _uriCache: Map<string, UriCacheEntry> | undefined;
|
||||||
|
|
||||||
config: IConfig;
|
config: IConfig;
|
||||||
@@ -76,7 +77,7 @@ export class GitProvider extends Disposable {
|
|||||||
constructor(private context: ExtensionContext) {
|
constructor(private context: ExtensionContext) {
|
||||||
super(() => this.dispose());
|
super(() => this.dispose());
|
||||||
|
|
||||||
this._repoPath = context.workspaceState.get(WorkspaceState.RepoPath) as string;
|
this.repoPath = context.workspaceState.get(WorkspaceState.RepoPath) as string;
|
||||||
|
|
||||||
this._onConfigurationChanged();
|
this._onConfigurationChanged();
|
||||||
|
|
||||||
@@ -185,7 +186,7 @@ export class GitProvider extends Disposable {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const gitignorePath = path.join(this._repoPath, '.gitignore');
|
const gitignorePath = path.join(this.repoPath, '.gitignore');
|
||||||
fs.exists(gitignorePath, e => {
|
fs.exists(gitignorePath, e => {
|
||||||
if (e) {
|
if (e) {
|
||||||
fs.readFile(gitignorePath, 'utf8', (err, data) => {
|
fs.readFile(gitignorePath, 'utf8', (err, data) => {
|
||||||
|
|||||||
@@ -9,8 +9,8 @@ import * as path from 'path';
|
|||||||
|
|
||||||
export class FileHistoryQuickPick {
|
export class FileHistoryQuickPick {
|
||||||
|
|
||||||
static showProgress(maxCount?: number) {
|
static showProgress(uri: GitUri) {
|
||||||
return showQuickPickProgress(`Loading file history \u2014 ${maxCount ? ` limited to ${maxCount} commits` : ` this may take a while`}\u2026`,
|
return showQuickPickProgress(`${uri.getFormattedPath()}${uri.sha ? ` \u00a0\u2022\u00a0 ${uri.sha.substring(0, 8)}` : ''}`,
|
||||||
{
|
{
|
||||||
left: KeyNoopCommand,
|
left: KeyNoopCommand,
|
||||||
',': KeyNoopCommand,
|
',': KeyNoopCommand,
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
import { CancellationTokenSource, commands, QuickPickItem, QuickPickOptions, TextEditor, Uri, window, workspace } from 'vscode';
|
import { CancellationTokenSource, commands, Disposable, QuickPickItem, QuickPickOptions, TextEditor, Uri, window, workspace } from 'vscode';
|
||||||
import { Commands, Keyboard, KeyboardScope, KeyMapping, openEditor } from '../commands';
|
import { Commands, Keyboard, KeyboardScope, KeyMapping, openEditor } from '../commands';
|
||||||
import { IAdvancedConfig } from '../configuration';
|
import { IAdvancedConfig } from '../configuration';
|
||||||
// import { Logger } from '../logger';
|
// import { Logger } from '../logger';
|
||||||
@@ -8,9 +8,21 @@ export function getQuickPickIgnoreFocusOut() {
|
|||||||
return !workspace.getConfiguration('gitlens').get<IAdvancedConfig>('advanced').quickPick.closeOnFocusOut;
|
return !workspace.getConfiguration('gitlens').get<IAdvancedConfig>('advanced').quickPick.closeOnFocusOut;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function showQuickPickProgress(message: string, mapping?: KeyMapping): CancellationTokenSource {
|
export function showQuickPickProgress(message: string, mapping?: KeyMapping, delay: boolean = false): CancellationTokenSource {
|
||||||
const cancellation = new CancellationTokenSource();
|
const cancellation = new CancellationTokenSource();
|
||||||
_showQuickPickProgress(message, cancellation, mapping);
|
|
||||||
|
if (delay) {
|
||||||
|
let disposable: Disposable;
|
||||||
|
const timer = setTimeout(() => {
|
||||||
|
disposable && disposable.dispose();
|
||||||
|
_showQuickPickProgress(message, cancellation, mapping);
|
||||||
|
}, 250);
|
||||||
|
disposable = cancellation.token.onCancellationRequested(() => clearTimeout(timer));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
_showQuickPickProgress(message, cancellation, mapping);
|
||||||
|
}
|
||||||
|
|
||||||
return cancellation;
|
return cancellation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,8 +8,8 @@ import { CommandQuickPickItem, getQuickPickIgnoreFocusOut, showQuickPickProgress
|
|||||||
|
|
||||||
export class RepoHistoryQuickPick {
|
export class RepoHistoryQuickPick {
|
||||||
|
|
||||||
static showProgress(maxCount?: number) {
|
static showProgress() {
|
||||||
return showQuickPickProgress(`Loading repository history \u2014 ${maxCount ? ` limited to ${maxCount} commits` : ` this may take a while`}\u2026`,
|
return showQuickPickProgress('Repository history \u2014 search by commit message, filename, or sha',
|
||||||
{
|
{
|
||||||
left: KeyNoopCommand,
|
left: KeyNoopCommand,
|
||||||
',': KeyNoopCommand,
|
',': KeyNoopCommand,
|
||||||
@@ -22,11 +22,11 @@ export class RepoHistoryQuickPick {
|
|||||||
|
|
||||||
let previousPageCommand: CommandQuickPickItem;
|
let previousPageCommand: CommandQuickPickItem;
|
||||||
|
|
||||||
if (log.truncated || uri.sha) {
|
if (log.truncated || (uri && uri.sha)) {
|
||||||
items.splice(0, 0, new CommandQuickPickItem({
|
items.splice(0, 0, new CommandQuickPickItem({
|
||||||
label: `$(sync) Show All Commits`,
|
label: `$(sync) Show All Commits`,
|
||||||
description: `\u00a0 \u2014 \u00a0\u00a0 this may take a while`
|
description: `\u00a0 \u2014 \u00a0\u00a0 this may take a while`
|
||||||
}, Commands.ShowQuickRepoHistory, [Uri.file(uri.fsPath), 0, goBackCommand]));
|
}, Commands.ShowQuickRepoHistory, [uri && Uri.file(uri.fsPath), 0, goBackCommand]));
|
||||||
|
|
||||||
if (nextPageCommand) {
|
if (nextPageCommand) {
|
||||||
items.splice(0, 0, nextPageCommand);
|
items.splice(0, 0, nextPageCommand);
|
||||||
@@ -43,7 +43,7 @@ export class RepoHistoryQuickPick {
|
|||||||
previousPageCommand = new CommandQuickPickItem({
|
previousPageCommand = new CommandQuickPickItem({
|
||||||
label: `$(arrow-left) Show Previous Commits`,
|
label: `$(arrow-left) Show Previous Commits`,
|
||||||
description: `\u00a0 \u2014 \u00a0\u00a0 shows ${log.maxCount} older commits`
|
description: `\u00a0 \u2014 \u00a0\u00a0 shows ${log.maxCount} older commits`
|
||||||
}, Commands.ShowQuickRepoHistory, [new GitUri(uri, last), log.maxCount, goBackCommand, undefined, npc]);
|
}, Commands.ShowQuickRepoHistory, [new GitUri(uri ? uri : last.uri, last), log.maxCount, goBackCommand, undefined, npc]);
|
||||||
|
|
||||||
items.splice(0, 0, previousPageCommand);
|
items.splice(0, 0, previousPageCommand);
|
||||||
}
|
}
|
||||||
@@ -66,7 +66,7 @@ export class RepoHistoryQuickPick {
|
|||||||
const pick = await window.showQuickPick(items, {
|
const pick = await window.showQuickPick(items, {
|
||||||
matchOnDescription: true,
|
matchOnDescription: true,
|
||||||
matchOnDetail: true,
|
matchOnDetail: true,
|
||||||
placeHolder: 'Search by commit message, filename, or sha',
|
placeHolder: 'Repository history \u2014 search by commit message, filename, or sha',
|
||||||
ignoreFocusOut: getQuickPickIgnoreFocusOut()
|
ignoreFocusOut: getQuickPickIgnoreFocusOut()
|
||||||
// onDidSelectItem: (item: QuickPickItem) => {
|
// onDidSelectItem: (item: QuickPickItem) => {
|
||||||
// scope.setKeyCommand('right', item);
|
// scope.setKeyCommand('right', item);
|
||||||
|
|||||||
Reference in New Issue
Block a user