mirror of
https://github.com/ckaczor/vscode-gitlens.git
synced 2026-02-13 03:28:35 -05:00
Changes previous diff to working diff if uncommit
This commit is contained in:
@@ -42,7 +42,7 @@ export default class DiffLineWithPreviousCommand extends EditorCommand {
|
|||||||
if (commit.isUncommitted) {
|
if (commit.isUncommitted) {
|
||||||
uri = commit.uri;
|
uri = commit.uri;
|
||||||
commit = new GitCommit(commit.repoPath, commit.previousSha, commit.previousFileName, commit.author, commit.date, commit.message);
|
commit = new GitCommit(commit.repoPath, commit.previousSha, commit.previousFileName, commit.author, commit.date, commit.message);
|
||||||
line = blame.line.line + 1 + gitUri.offset;
|
line = (blame.line.line + 1) + gitUri.offset;
|
||||||
return commands.executeCommand(Commands.DiffWithWorking, uri, commit, line);
|
return commands.executeCommand(Commands.DiffWithWorking, uri, commit, line);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,6 +34,13 @@ export default class DiffWithPreviousCommand extends EditorCommand {
|
|||||||
const gitUri = GitUri.fromUri(uri, this.git);
|
const gitUri = GitUri.fromUri(uri, this.git);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
if (!gitUri.sha) {
|
||||||
|
// If the file is uncommitted, treat it as a DiffWithWorking
|
||||||
|
if (await this.git.isFileUncommitted(gitUri.fsPath, gitUri.repoPath)) {
|
||||||
|
return commands.executeCommand(Commands.DiffWithWorking, uri);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const log = await this.git.getLogForFile(gitUri.fsPath, undefined, gitUri.repoPath, rangeOrLine as Range);
|
const log = await this.git.getLogForFile(gitUri.fsPath, undefined, gitUri.repoPath, rangeOrLine as Range);
|
||||||
if (!log) return window.showWarningMessage(`Unable to open diff. File is probably not under source control`);
|
if (!log) return window.showWarningMessage(`Unable to open diff. File is probably not under source control`);
|
||||||
|
|
||||||
|
|||||||
@@ -167,6 +167,13 @@ export default class Git {
|
|||||||
return gitCommand(root, 'show', `${sha}:./${file}`);
|
return gitCommand(root, 'show', `${sha}:./${file}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static statusForFile(fileName: string, repoPath: string): Promise<string> {
|
||||||
|
const [file, root]: [string, string] = Git.splitPath(Git.normalizePath(fileName), repoPath);
|
||||||
|
|
||||||
|
const params = ['status', file, '--short'];
|
||||||
|
return gitCommand(root, ...params);
|
||||||
|
}
|
||||||
|
|
||||||
static isUncommitted(sha: string) {
|
static isUncommitted(sha: string) {
|
||||||
return UncommittedRegex.test(sha);
|
return UncommittedRegex.test(sha);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -545,6 +545,17 @@ export default class GitProvider extends Disposable {
|
|||||||
return locations;
|
return locations;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getStatusForFile(fileName: string, repoPath: string) {
|
||||||
|
Logger.log(`getStatusForFile('${fileName}', ${repoPath})`);
|
||||||
|
return (await Git.statusForFile(fileName, repoPath)).trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
async isFileUncommitted(fileName: string, repoPath: string) {
|
||||||
|
Logger.log(`isFileUncommitted('${fileName}', ${repoPath})`);
|
||||||
|
const status = await this.getStatusForFile(fileName, repoPath);
|
||||||
|
return status && status.length;
|
||||||
|
}
|
||||||
|
|
||||||
async getVersionedFile(fileName: string, repoPath: string, sha: string) {
|
async getVersionedFile(fileName: string, repoPath: string, sha: string) {
|
||||||
Logger.log(`getVersionedFile('${fileName}', ${repoPath}, ${sha})`);
|
Logger.log(`getVersionedFile('${fileName}', ${repoPath}, ${sha})`);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user