Skip to content

Commit 6016402

Browse files
committed
Splits out quick commit revision command
1 parent f8b4299 commit 6016402

File tree

1 file changed

+35
-12
lines changed

1 file changed

+35
-12
lines changed

src/commands/showQuickCommitFile.ts

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { GitUri } from '../git/gitUri';
77
import type { GitCommit, GitStashCommit } from '../git/models/commit';
88
import { isCommit } from '../git/models/commit';
99
import type { GitLog } from '../git/models/log';
10+
import { createReference } from '../git/models/reference';
1011
import {
1112
showCommitNotFoundWarningMessage,
1213
showFileNotUnderSourceControlWarningMessage,
@@ -33,25 +34,14 @@ export class ShowQuickCommitFileCommand extends ActiveEditorCachedCommand {
3334
}
3435

3536
constructor(private readonly container: Container) {
36-
super([
37-
Commands.ShowQuickCommitFile,
38-
Commands.ShowQuickCommitRevision,
39-
Commands.ShowQuickCommitRevisionInDiffLeft,
40-
Commands.ShowQuickCommitRevisionInDiffRight,
41-
]);
37+
super(Commands.ShowQuickCommitFile);
4238
}
4339

4440
protected override async preExecute(context: CommandContext, args?: ShowQuickCommitFileCommandArgs) {
4541
if (context.type === 'editorLine') {
4642
args = { ...args, line: context.line };
4743
}
4844

49-
if (context.editor != null && context.command.startsWith(Commands.ShowQuickCommitRevision)) {
50-
const gitUri = await GitUri.fromUri(context.editor.document.uri);
51-
52-
args = { ...args, sha: gitUri.sha };
53-
}
54-
5545
if (context.type === 'viewItem') {
5646
args = { ...args, sha: context.node.uri.sha };
5747

@@ -157,3 +147,36 @@ export class ShowQuickCommitFileCommand extends ActiveEditorCachedCommand {
157147
}
158148
}
159149
}
150+
151+
@command()
152+
export class ShowQuickCommitRevisionCommand extends ActiveEditorCachedCommand {
153+
constructor(private readonly container: Container) {
154+
super([
155+
Commands.ShowQuickCommitRevision,
156+
Commands.ShowQuickCommitRevisionInDiffLeft,
157+
Commands.ShowQuickCommitRevisionInDiffRight,
158+
]);
159+
}
160+
161+
async execute(editor?: TextEditor, uri?: Uri) {
162+
uri = getCommandUri(uri, editor);
163+
if (uri == null) return;
164+
165+
try {
166+
const gitUri = await GitUri.fromUri(uri);
167+
if (gitUri?.sha == null) return;
168+
169+
await executeGitCommand({
170+
command: 'show',
171+
state: {
172+
repo: gitUri.repoPath,
173+
reference: createReference(gitUri.sha, gitUri.repoPath!, { refType: 'revision' }),
174+
fileName: gitUri.fsPath,
175+
},
176+
});
177+
} catch (ex) {
178+
Logger.error(ex, 'ShowQuickCommitRevisionCommand');
179+
void showGenericErrorMessage('Unable to show commit details');
180+
}
181+
}
182+
}

0 commit comments

Comments
 (0)