mirror of
https://github.com/ckaczor/vscode-gitlens.git
synced 2026-02-05 17:25:44 -05:00
Adds working filename detection method
Adds get current branch method Fixes diff with working tree when file was renamed Fixes various quick pick commands when file was renamed Adds branch support to ShowQuickRepoHistory Adds branch info to repo quick pick placeholder Adds Show Branch History to commit limited branch history quick pick Adds Show File History to commit limited file history quick pick Removes conditional display of commit details on commit file details quick pick Removes conditional display of show file history on commit file details quick pick Fixed #30 - Diff with Working Tree fails from repo/commit quickpick list if file was renamed (and the commit was before the rename)
This commit is contained in:
@@ -40,9 +40,11 @@ export class DiffWithWorkingCommand extends ActiveEditorCommand {
|
||||
|
||||
const gitUri = await GitUri.fromUri(uri, this.git);
|
||||
|
||||
const workingFileName = await this.git.findWorkingFileName(gitUri.repoPath, gitUri.fsPath);
|
||||
|
||||
try {
|
||||
const compare = await this.git.getVersionedFile(commit.repoPath, commit.uri.fsPath, commit.sha);
|
||||
await commands.executeCommand(BuiltInCommands.Diff, Uri.file(compare), gitUri.fileUri(), `${path.basename(commit.uri.fsPath)} (${commit.shortSha}) ↔ ${path.basename(gitUri.fsPath)}`);
|
||||
await commands.executeCommand(BuiltInCommands.Diff, Uri.file(compare), Uri.file(path.resolve(gitUri.repoPath, workingFileName)), `${path.basename(commit.uri.fsPath)} (${commit.shortSha}) ↔ ${path.basename(workingFileName)}`);
|
||||
return await commands.executeCommand(BuiltInCommands.RevealLine, { lineNumber: line, at: 'center' });
|
||||
}
|
||||
catch (ex) {
|
||||
|
||||
@@ -4,6 +4,7 @@ import { ActiveEditorCommand, Commands } from './commands';
|
||||
import { GitCommit, GitLogCommit, GitService, GitUri, IGitLog } from '../gitService';
|
||||
import { Logger } from '../logger';
|
||||
import { CommandQuickPickItem, CommitDetailsQuickPick, CommitWithFileStatusQuickPickItem } from '../quickPicks';
|
||||
import * as path from 'path';
|
||||
|
||||
export class ShowQuickCommitDetailsCommand extends ActiveEditorCommand {
|
||||
|
||||
@@ -20,6 +21,7 @@ export class ShowQuickCommitDetailsCommand extends ActiveEditorCommand {
|
||||
const gitUri = await GitUri.fromUri(uri, this.git);
|
||||
|
||||
let repoPath = gitUri.repoPath;
|
||||
let workingFileName = path.relative(repoPath, gitUri.fsPath);
|
||||
|
||||
if (!sha) {
|
||||
if (!editor) return undefined;
|
||||
@@ -33,6 +35,7 @@ export class ShowQuickCommitDetailsCommand extends ActiveEditorCommand {
|
||||
|
||||
sha = blame.commit.isUncommitted ? blame.commit.previousSha : blame.commit.sha;
|
||||
repoPath = blame.commit.repoPath;
|
||||
workingFileName = blame.commit.fileName;
|
||||
|
||||
commit = blame.commit;
|
||||
}
|
||||
@@ -60,6 +63,10 @@ export class ShowQuickCommitDetailsCommand extends ActiveEditorCommand {
|
||||
}
|
||||
}
|
||||
|
||||
if (!commit.workingFileName) {
|
||||
commit.workingFileName = workingFileName;
|
||||
}
|
||||
|
||||
if (!goBackCommand) {
|
||||
// Create a command to get back to the branch history
|
||||
goBackCommand = new CommandQuickPickItem({
|
||||
|
||||
@@ -12,12 +12,14 @@ export class ShowQuickCommitFileDetailsCommand extends ActiveEditorCommand {
|
||||
super(Commands.ShowQuickCommitFileDetails);
|
||||
}
|
||||
|
||||
async execute(editor: TextEditor, uri?: Uri, sha?: string, commit?: GitCommit | GitLogCommit, goBackCommand?: CommandQuickPickItem, options: { showFileHistory?: boolean } = { showFileHistory: true }, fileLog?: IGitLog) {
|
||||
async execute(editor: TextEditor, uri?: Uri, sha?: string, commit?: GitCommit | GitLogCommit, goBackCommand?: CommandQuickPickItem, fileLog?: IGitLog) {
|
||||
if (!(uri instanceof Uri)) {
|
||||
if (!editor || !editor.document) return undefined;
|
||||
uri = editor.document.uri;
|
||||
}
|
||||
|
||||
let workingFileName = commit && commit.workingFileName;
|
||||
|
||||
if (!sha) {
|
||||
if (!editor) return undefined;
|
||||
|
||||
@@ -33,6 +35,7 @@ export class ShowQuickCommitFileDetailsCommand extends ActiveEditorCommand {
|
||||
sha = blame.commit.isUncommitted ? blame.commit.previousSha : blame.commit.sha;
|
||||
|
||||
commit = blame.commit;
|
||||
workingFileName = path.relative(commit.repoPath, gitUri.fsPath);
|
||||
}
|
||||
catch (ex) {
|
||||
Logger.error('[GitLens.ShowQuickCommitFileDetailsCommand]', `getBlameForLine(${blameline})`, ex);
|
||||
@@ -51,7 +54,7 @@ export class ShowQuickCommitFileDetailsCommand extends ActiveEditorCommand {
|
||||
}
|
||||
|
||||
if (!fileLog) {
|
||||
const log = await this.git.getLogForFile(undefined, uri.fsPath, sha, undefined, 2);
|
||||
const log = await this.git.getLogForFile(undefined, commit ? commit.uri.fsPath : uri.fsPath, sha, undefined, 2);
|
||||
if (!log) return window.showWarningMessage(`Unable to show commit file details`);
|
||||
|
||||
commit = log.commits.get(sha);
|
||||
@@ -59,9 +62,8 @@ export class ShowQuickCommitFileDetailsCommand extends ActiveEditorCommand {
|
||||
}
|
||||
|
||||
// Attempt to the most recent commit -- so that we can find the real working filename if there was a rename
|
||||
const workingCommit = await this.git.findMostRecentCommitForFile(commit.uri.fsPath, commit.sha);
|
||||
// TODO: Leave this at undefined until findMostRecentCommitForFile actually works
|
||||
const workingFileName = !workingCommit ? commit.fileName : undefined;
|
||||
commit.workingFileName = workingFileName;
|
||||
commit.workingFileName = await this.git.findWorkingFileName(commit);
|
||||
|
||||
const shortSha = sha.substring(0, 8);
|
||||
|
||||
@@ -73,13 +75,13 @@ export class ShowQuickCommitFileDetailsCommand extends ActiveEditorCommand {
|
||||
}, Commands.ShowQuickCommitDetails, [new GitUri(commit.uri, commit), sha, commit]);
|
||||
}
|
||||
|
||||
const pick = await CommitFileDetailsQuickPick.show(this.git, commit as GitLogCommit, workingFileName, uri, goBackCommand,
|
||||
const pick = await CommitFileDetailsQuickPick.show(this.git, commit as GitLogCommit, uri, goBackCommand,
|
||||
// Create a command to get back to where we are right now
|
||||
new CommandQuickPickItem({
|
||||
label: `go back \u21A9`,
|
||||
description: `\u00a0 \u2014 \u00a0\u00a0 to details of \u00a0$(file-text) ${path.basename(commit.fileName)} in \u00a0$(git-commit) ${shortSha}`
|
||||
}, Commands.ShowQuickCommitFileDetails, [new GitUri(commit.uri, commit), sha, commit, goBackCommand, options]),
|
||||
{ showFileHistory: options.showFileHistory }, fileLog);
|
||||
}, Commands.ShowQuickCommitFileDetails, [new GitUri(commit.uri, commit), sha, commit, goBackCommand]),
|
||||
fileLog);
|
||||
|
||||
if (!pick) return undefined;
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ export class ShowQuickFileHistoryCommand extends ActiveEditorCommand {
|
||||
|
||||
if (progressCancellation.token.isCancellationRequested) return undefined;
|
||||
|
||||
const pick = await FileHistoryQuickPick.show(log, gitUri, progressCancellation, goBackCommand, nextPageCommand);
|
||||
const pick = await FileHistoryQuickPick.show(this.git, log, gitUri, progressCancellation, goBackCommand, nextPageCommand);
|
||||
if (!pick) return undefined;
|
||||
|
||||
if (pick instanceof CommandQuickPickItem) {
|
||||
@@ -44,9 +44,8 @@ export class ShowQuickFileHistoryCommand extends ActiveEditorCommand {
|
||||
return commands.executeCommand(Commands.ShowQuickCommitFileDetails, new GitUri(pick.commit.uri, pick.commit), pick.commit.sha, pick.commit,
|
||||
new CommandQuickPickItem({
|
||||
label: `go back \u21A9`,
|
||||
description: `\u00a0 \u2014 \u00a0\u00a0 to history of \u00a0$(file-text) ${path.basename(pick.commit.fileName)}`
|
||||
}, Commands.ShowQuickFileHistory, [uri, undefined, maxCount, goBackCommand, log]),
|
||||
{ showFileHistory: false },
|
||||
description: `\u00a0 \u2014 \u00a0\u00a0 to history of \u00a0$(file-text) ${path.basename(pick.commit.fileName)}${gitUri.sha ? ` from \u00a0$(git-commit) ${gitUri.shortSha}` : ''}`
|
||||
}, Commands.ShowQuickFileHistory, [uri, range, maxCount, goBackCommand, log]),
|
||||
log);
|
||||
}
|
||||
catch (ex) {
|
||||
|
||||
@@ -11,7 +11,7 @@ export class ShowQuickRepoHistoryCommand extends ActiveEditorCommand {
|
||||
super(Commands.ShowQuickRepoHistory);
|
||||
}
|
||||
|
||||
async execute(editor: TextEditor, uri?: Uri, maxCount?: number, goBackCommand?: CommandQuickPickItem, log?: IGitLog, nextPageCommand?: CommandQuickPickItem) {
|
||||
async execute(editor: TextEditor, uri?: Uri, branch?: string, maxCount?: number, goBackCommand?: CommandQuickPickItem, log?: IGitLog, nextPageCommand?: CommandQuickPickItem) {
|
||||
if (!(uri instanceof Uri)) {
|
||||
uri = editor && editor.document && editor.document.uri;
|
||||
}
|
||||
@@ -22,21 +22,23 @@ export class ShowQuickRepoHistoryCommand extends ActiveEditorCommand {
|
||||
maxCount = this.git.config.advanced.maxQuickHistory;
|
||||
}
|
||||
|
||||
const progressCancellation = RepoHistoryQuickPick.showProgress();
|
||||
branch = branch || (await this.git.getBranch(this.git.repoPath)).name;
|
||||
|
||||
const progressCancellation = RepoHistoryQuickPick.showProgress(branch);
|
||||
try {
|
||||
const repoPath = (gitUri && gitUri.repoPath) || await this.git.getRepoPathFromUri(uri, this.repoPath);
|
||||
if (!repoPath) return window.showWarningMessage(`Unable to show history`);
|
||||
|
||||
if (progressCancellation.token.isCancellationRequested) return undefined;
|
||||
|
||||
if (!log) {
|
||||
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 && gitUri.sha), maxCount);
|
||||
if (!log) return window.showWarningMessage(`Unable to show repository history`);
|
||||
log = await this.git.getLogForRepo(repoPath, (gitUri && gitUri.sha) || branch, maxCount);
|
||||
if (!log) return window.showWarningMessage(`Unable to show history`);
|
||||
}
|
||||
|
||||
if (progressCancellation.token.isCancellationRequested) return undefined;
|
||||
|
||||
const pick = await RepoHistoryQuickPick.show(log, gitUri, progressCancellation, goBackCommand, nextPageCommand);
|
||||
const pick = await RepoHistoryQuickPick.show(log, gitUri, branch, progressCancellation, goBackCommand, nextPageCommand);
|
||||
if (!pick) return undefined;
|
||||
|
||||
if (pick instanceof CommandQuickPickItem) {
|
||||
@@ -46,8 +48,8 @@ export class ShowQuickRepoHistoryCommand extends ActiveEditorCommand {
|
||||
return commands.executeCommand(Commands.ShowQuickCommitDetails, new GitUri(pick.commit.uri, pick.commit), pick.commit.sha, pick.commit,
|
||||
new CommandQuickPickItem({
|
||||
label: `go back \u21A9`,
|
||||
description: `\u00a0 \u2014 \u00a0\u00a0 to branch history`
|
||||
}, Commands.ShowQuickRepoHistory, [uri, maxCount, goBackCommand, log]),
|
||||
description: `\u00a0 \u2014 \u00a0\u00a0 to \u00a0$(git-branch) ${branch} history`
|
||||
}, Commands.ShowQuickRepoHistory, [uri, branch, maxCount, goBackCommand, log]),
|
||||
log);
|
||||
}
|
||||
catch (ex) {
|
||||
|
||||
Reference in New Issue
Block a user