mirror of
https://github.com/ckaczor/vscode-gitlens.git
synced 2026-01-20 09:45:36 -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;
|
||||
}
|
||||
|
||||
const progressCancellation = FileHistoryQuickPick.showProgress(maxCount);
|
||||
const progressCancellation = FileHistoryQuickPick.showProgress(gitUri);
|
||||
try {
|
||||
if (!log) {
|
||||
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;
|
||||
}
|
||||
|
||||
const gitUri = await GitUri.fromUri(uri, this.git);
|
||||
Logger.log(`ShowQuickRepoHistoryCommand.execute`, gitUri.shortSha);
|
||||
const gitUri = uri && await GitUri.fromUri(uri, this.git);
|
||||
|
||||
if (maxCount == null) {
|
||||
maxCount = this.git.config.advanced.maxQuickHistory;
|
||||
}
|
||||
|
||||
const progressCancellation = RepoHistoryQuickPick.showProgress(maxCount);
|
||||
const progressCancellation = RepoHistoryQuickPick.showProgress();
|
||||
try {
|
||||
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 (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`);
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,9 @@ export class GitUri extends Uri {
|
||||
repoPath?: 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();
|
||||
if (!uri) return;
|
||||
|
||||
@@ -33,12 +35,18 @@ export class GitUri extends Uri {
|
||||
this.repoPath = data.repoPath;
|
||||
}
|
||||
}
|
||||
else if (commit) {
|
||||
base._fsPath = path.resolve(commit.repoPath, commit.originalFileName || commit.fileName);
|
||||
else if (commitOrRepoPath) {
|
||||
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)) {
|
||||
this.sha = commit.sha;
|
||||
this.repoPath = commit.repoPath;
|
||||
if (!Git.isUncommitted(commit.sha)) {
|
||||
this.sha = commit.sha;
|
||||
this.repoPath = commit.repoPath;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -51,6 +59,16 @@ export class GitUri extends Uri {
|
||||
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) {
|
||||
if (uri instanceof GitUri) return uri;
|
||||
|
||||
@@ -64,7 +82,7 @@ export class GitUri extends Uri {
|
||||
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;
|
||||
}
|
||||
|
||||
public repoPath: string;
|
||||
|
||||
private _gitCache: Map<string, GitCacheEntry> | undefined;
|
||||
private _cacheDisposable: Disposable | undefined;
|
||||
private _repoPath: string;
|
||||
private _uriCache: Map<string, UriCacheEntry> | undefined;
|
||||
|
||||
config: IConfig;
|
||||
@@ -76,7 +77,7 @@ export class GitProvider extends Disposable {
|
||||
constructor(private context: ExtensionContext) {
|
||||
super(() => this.dispose());
|
||||
|
||||
this._repoPath = context.workspaceState.get(WorkspaceState.RepoPath) as string;
|
||||
this.repoPath = context.workspaceState.get(WorkspaceState.RepoPath) as string;
|
||||
|
||||
this._onConfigurationChanged();
|
||||
|
||||
@@ -185,7 +186,7 @@ export class GitProvider extends Disposable {
|
||||
return;
|
||||
}
|
||||
|
||||
const gitignorePath = path.join(this._repoPath, '.gitignore');
|
||||
const gitignorePath = path.join(this.repoPath, '.gitignore');
|
||||
fs.exists(gitignorePath, e => {
|
||||
if (e) {
|
||||
fs.readFile(gitignorePath, 'utf8', (err, data) => {
|
||||
|
||||
@@ -9,8 +9,8 @@ import * as path from 'path';
|
||||
|
||||
export class FileHistoryQuickPick {
|
||||
|
||||
static showProgress(maxCount?: number) {
|
||||
return showQuickPickProgress(`Loading file history \u2014 ${maxCount ? ` limited to ${maxCount} commits` : ` this may take a while`}\u2026`,
|
||||
static showProgress(uri: GitUri) {
|
||||
return showQuickPickProgress(`${uri.getFormattedPath()}${uri.sha ? ` \u00a0\u2022\u00a0 ${uri.sha.substring(0, 8)}` : ''}`,
|
||||
{
|
||||
left: KeyNoopCommand,
|
||||
',': KeyNoopCommand,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
'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 { IAdvancedConfig } from '../configuration';
|
||||
// import { Logger } from '../logger';
|
||||
@@ -8,9 +8,21 @@ export function getQuickPickIgnoreFocusOut() {
|
||||
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();
|
||||
_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;
|
||||
}
|
||||
|
||||
|
||||
@@ -8,8 +8,8 @@ import { CommandQuickPickItem, getQuickPickIgnoreFocusOut, showQuickPickProgress
|
||||
|
||||
export class RepoHistoryQuickPick {
|
||||
|
||||
static showProgress(maxCount?: number) {
|
||||
return showQuickPickProgress(`Loading repository history \u2014 ${maxCount ? ` limited to ${maxCount} commits` : ` this may take a while`}\u2026`,
|
||||
static showProgress() {
|
||||
return showQuickPickProgress('Repository history \u2014 search by commit message, filename, or sha',
|
||||
{
|
||||
left: KeyNoopCommand,
|
||||
',': KeyNoopCommand,
|
||||
@@ -22,11 +22,11 @@ export class RepoHistoryQuickPick {
|
||||
|
||||
let previousPageCommand: CommandQuickPickItem;
|
||||
|
||||
if (log.truncated || uri.sha) {
|
||||
if (log.truncated || (uri && uri.sha)) {
|
||||
items.splice(0, 0, new CommandQuickPickItem({
|
||||
label: `$(sync) Show All Commits`,
|
||||
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) {
|
||||
items.splice(0, 0, nextPageCommand);
|
||||
@@ -43,7 +43,7 @@ export class RepoHistoryQuickPick {
|
||||
previousPageCommand = new CommandQuickPickItem({
|
||||
label: `$(arrow-left) Show Previous 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);
|
||||
}
|
||||
@@ -66,7 +66,7 @@ export class RepoHistoryQuickPick {
|
||||
const pick = await window.showQuickPick(items, {
|
||||
matchOnDescription: true,
|
||||
matchOnDetail: true,
|
||||
placeHolder: 'Search by commit message, filename, or sha',
|
||||
placeHolder: 'Repository history \u2014 search by commit message, filename, or sha',
|
||||
ignoreFocusOut: getQuickPickIgnoreFocusOut()
|
||||
// onDidSelectItem: (item: QuickPickItem) => {
|
||||
// scope.setKeyCommand('right', item);
|
||||
|
||||
Reference in New Issue
Block a user