mirror of
https://github.com/ckaczor/vscode-gitlens.git
synced 2026-02-17 02:51:47 -05:00
Attempted fix for bad filename to diff w/ working
Tried to find the most recent filename given a commit, but git doesn't seem to want to cooperate
This commit is contained in:
@@ -60,8 +60,10 @@ export default class ShowQuickCommitDetailsCommand extends EditorCommand {
|
|||||||
} as QuickPickOptions);
|
} as QuickPickOptions);
|
||||||
|
|
||||||
if (filePick) {
|
if (filePick) {
|
||||||
// TODO need to make log for file -- go from commit to HEAD so we can get the current filename
|
// Get the most recent commit -- so that we can find the real working filename if there was a rename
|
||||||
const log = await this.git.getLogForFile(filePick.uri.fsPath, filePick.sha);
|
const workingCommit = await this.git.findMostRecentCommitForFile(filePick.uri.fsPath, filePick.sha);
|
||||||
|
|
||||||
|
const log = await this.git.getLogForFile(filePick.uri.fsPath, filePick.sha, undefined, undefined, 2);
|
||||||
if (!log) return window.showWarningMessage(`Unable to open diff`);
|
if (!log) return window.showWarningMessage(`Unable to open diff`);
|
||||||
|
|
||||||
const commit = Iterables.find(log.commits.values(), c => c.sha === commitPick.commit.sha);
|
const commit = Iterables.find(log.commits.values(), c => c.sha === commitPick.commit.sha);
|
||||||
@@ -70,7 +72,7 @@ export default class ShowQuickCommitDetailsCommand extends EditorCommand {
|
|||||||
const items: CompareQuickPickItem[] = [
|
const items: CompareQuickPickItem[] = [
|
||||||
{
|
{
|
||||||
label: `Compare with Working Tree`,
|
label: `Compare with Working Tree`,
|
||||||
description: `\u2022 ${commit.sha} $(git-compare) ${commit.fileName}`,
|
description: `\u2022 ${commit.sha} $(git-compare) ${(workingCommit || commit).fileName}`,
|
||||||
command: Commands.DiffWithWorking
|
command: Commands.DiffWithWorking
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -93,8 +93,10 @@ export default class ShowQuickRepoHistoryCommand extends Command {
|
|||||||
|
|
||||||
const filePick = pick as FileQuickPickItem;
|
const filePick = pick as FileQuickPickItem;
|
||||||
if (filePick) {
|
if (filePick) {
|
||||||
// TODO need to make log for file -- go from commit to HEAD so we can get the current filename
|
// Get the most recent commit -- so that we can find the real working filename if there was a rename
|
||||||
const log = await this.git.getLogForFile(filePick.uri.fsPath, filePick.sha);
|
const workingCommit = await this.git.findMostRecentCommitForFile(filePick.uri.fsPath, filePick.sha);
|
||||||
|
|
||||||
|
const log = await this.git.getLogForFile(filePick.uri.fsPath, filePick.sha, undefined, undefined, 2);
|
||||||
if (!log) return window.showWarningMessage(`Unable to open diff`);
|
if (!log) return window.showWarningMessage(`Unable to open diff`);
|
||||||
|
|
||||||
const commit = Iterables.find(log.commits.values(), c => c.sha === commitPick.commit.sha);
|
const commit = Iterables.find(log.commits.values(), c => c.sha === commitPick.commit.sha);
|
||||||
@@ -103,7 +105,7 @@ export default class ShowQuickRepoHistoryCommand extends Command {
|
|||||||
const items: CompareQuickPickItem[] = [
|
const items: CompareQuickPickItem[] = [
|
||||||
{
|
{
|
||||||
label: `Compare with Working Tree`,
|
label: `Compare with Working Tree`,
|
||||||
description: `\u2022 ${commit.sha} $(git-compare) ${commit.fileName}`,
|
description: `\u2022 ${commit.sha} $(git-compare) ${(workingCommit || commit).fileName}`,
|
||||||
command: Commands.DiffWithWorking
|
command: Commands.DiffWithWorking
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -109,7 +109,7 @@ export class GitLogParserEnricher implements IGitEnricher<IGitLog> {
|
|||||||
return entries;
|
return entries;
|
||||||
}
|
}
|
||||||
|
|
||||||
enrich(data: string, fileNameOrRepoPath: string, isRepoPath: boolean = false): IGitLog {
|
enrich(data: string, type: 'file' | 'repo', fileNameOrRepoPath: string, isRepoPath: boolean = false): IGitLog {
|
||||||
const entries = this._parseEntries(data, isRepoPath);
|
const entries = this._parseEntries(data, isRepoPath);
|
||||||
if (!entries) return undefined;
|
if (!entries) return undefined;
|
||||||
|
|
||||||
@@ -160,7 +160,10 @@ export class GitLogParserEnricher implements IGitEnricher<IGitLog> {
|
|||||||
|
|
||||||
if (recentCommit) {
|
if (recentCommit) {
|
||||||
recentCommit.previousSha = commit.sha;
|
recentCommit.previousSha = commit.sha;
|
||||||
recentCommit.previousFileName = commit.originalFileName || commit.fileName;
|
// Only add a filename if this is a file log
|
||||||
|
if (type === 'file') {
|
||||||
|
recentCommit.previousFileName = commit.originalFileName || commit.fileName;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
recentCommit = commit;
|
recentCommit = commit;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ export default class Git {
|
|||||||
return gitCommand(root, ...params, `--`, file);
|
return gitCommand(root, ...params, `--`, file);
|
||||||
}
|
}
|
||||||
|
|
||||||
static log(fileName: string, sha?: string, repoPath?: string, maxCount?: number) {
|
static log(fileName: string, sha?: string, repoPath?: string, maxCount?: number, reverse: boolean = false) {
|
||||||
const [file, root]: [string, string] = Git.splitPath(Git.normalizePath(fileName), repoPath);
|
const [file, root]: [string, string] = Git.splitPath(Git.normalizePath(fileName), repoPath);
|
||||||
|
|
||||||
const params = [...DefaultLogParams, `--follow`];
|
const params = [...DefaultLogParams, `--follow`];
|
||||||
@@ -95,7 +95,12 @@ export default class Git {
|
|||||||
params.push(`-n${maxCount}`);
|
params.push(`-n${maxCount}`);
|
||||||
}
|
}
|
||||||
if (sha) {
|
if (sha) {
|
||||||
params.push(sha);
|
if (reverse) {
|
||||||
|
params.push(`${sha}..HEAD`);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
params.push(sha);
|
||||||
|
}
|
||||||
params.push(`--`);
|
params.push(`--`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -229,6 +229,30 @@ export default class GitProvider extends Disposable {
|
|||||||
return this._uriCache.has(cacheKey);
|
return this._uriCache.has(cacheKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async findMostRecentCommitForFile(fileName: string, sha?: string): Promise<GitCommit> {
|
||||||
|
const exists = await new Promise<boolean>((resolve, reject) => fs.exists(fileName, e => resolve(e)));
|
||||||
|
if (exists) return null;
|
||||||
|
|
||||||
|
return undefined;
|
||||||
|
|
||||||
|
// TODO: Get this to work -- for some reason a reverse log won't return the renamed file
|
||||||
|
// Not sure how else to figure this out
|
||||||
|
|
||||||
|
// let log: IGitLog;
|
||||||
|
// let commit: GitCommit;
|
||||||
|
// while (true) {
|
||||||
|
// // Go backward from the current commit to head to find the latest filename
|
||||||
|
// log = await this.getLogForFile(fileName, sha, undefined, undefined, undefined, true);
|
||||||
|
// if (!log) break;
|
||||||
|
|
||||||
|
// commit = Iterables.first(log.commits.values());
|
||||||
|
// sha = commit.sha;
|
||||||
|
// fileName = commit.fileName;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// return commit;
|
||||||
|
}
|
||||||
|
|
||||||
getGitUriForFile(fileName: string) {
|
getGitUriForFile(fileName: string) {
|
||||||
if (!this.UseUriCaching) return undefined;
|
if (!this.UseUriCaching) return undefined;
|
||||||
|
|
||||||
@@ -430,14 +454,14 @@ export default class GitProvider extends Disposable {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const data = await Git.logRepo(repoPath, sha, maxCount);
|
const data = await Git.logRepo(repoPath, sha, maxCount);
|
||||||
return new GitLogParserEnricher().enrich(data, repoPath, true);
|
return new GitLogParserEnricher().enrich(data, 'repo', repoPath, true);
|
||||||
}
|
}
|
||||||
catch (ex) {
|
catch (ex) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getLogForFile(fileName: string, sha?: string, repoPath?: string, range?: Range, maxCount?: number): Promise<IGitLog | undefined> {
|
getLogForFile(fileName: string, sha?: string, repoPath?: string, range?: Range, maxCount?: number, reverse: boolean = false): Promise<IGitLog | undefined> {
|
||||||
Logger.log(`getLogForFile('${fileName}', ${sha}, ${repoPath}, ${range && `[${range.start.line}, ${range.end.line}]`}, ${maxCount})`);
|
Logger.log(`getLogForFile('${fileName}', ${sha}, ${repoPath}, ${range && `[${range.start.line}, ${range.end.line}]`}, ${maxCount})`);
|
||||||
fileName = Git.normalizePath(fileName);
|
fileName = Git.normalizePath(fileName);
|
||||||
|
|
||||||
@@ -463,8 +487,8 @@ export default class GitProvider extends Disposable {
|
|||||||
|
|
||||||
return (range
|
return (range
|
||||||
? Git.logRange(fileName, range.start.line + 1, range.end.line + 1, sha, repoPath, maxCount)
|
? Git.logRange(fileName, range.start.line + 1, range.end.line + 1, sha, repoPath, maxCount)
|
||||||
: Git.log(fileName, sha, repoPath, maxCount))
|
: Git.log(fileName, sha, repoPath, maxCount, reverse))
|
||||||
.then(data => new GitLogParserEnricher().enrich(data, repoPath || fileName, !!repoPath))
|
.then(data => new GitLogParserEnricher().enrich(data, 'file', repoPath || fileName, !!repoPath))
|
||||||
.catch(ex => {
|
.catch(ex => {
|
||||||
// Trap and cache expected log errors
|
// Trap and cache expected log errors
|
||||||
if (useCaching) {
|
if (useCaching) {
|
||||||
|
|||||||
Reference in New Issue
Block a user