1
1
mirror of https://github.com/kahole/edamagit.git synced 2024-08-15 18:20:30 +03:00

check cursor-word chooseRef is actually a commit, otherwise throw away

This commit is contained in:
Kristian Andersen Hole 2024-01-18 22:22:18 +01:00
parent 153b0d6751
commit 3f66cd1cb5

View File

@ -9,6 +9,7 @@ import { RefType, Repository } from '../typings/git';
import { PickMenuItem, PickMenuUtil } from '../menu/pickMenu';
import GitTextUtils from '../utils/gitTextUtils';
import * as Constants from '../common/constants';
import { getCommit } from './commitCache';
export interface Selection {
key: string;
@ -150,24 +151,31 @@ export default class MagitUtils {
public static async chooseRef(repository: MagitRepository, prompt: string, showCurrent = false, showHEAD = false, allowFreeform = true, remoteOnly = false): Promise<string> {
const getCursorCommitHash: () => PickMenuItem<string> | undefined = () => {
const getCursorCommitHash: () => Promise<PickMenuItem<string> | undefined> = async () => {
const activeEditor = vscode.window.activeTextEditor;
if (activeEditor === undefined) {
return;
return undefined;
}
const document = activeEditor.document;
const selection = activeEditor.selection;
const hashWordRange = document.getWordRangeAtPosition(selection.active, /[0-9a-z]{7}/);
if (hashWordRange === undefined) {
return;
return undefined;
}
const hash = document.getText(hashWordRange);
try {
await getCommit(repository.gitRepository, hash);
} catch (error) {
return undefined;
}
return { label: hash, meta: hash };
};
const refs: PickMenuItem<string>[] = [];
const cursorCommitHash = getCursorCommitHash();
const cursorCommitHash = await getCursorCommitHash();
if (cursorCommitHash) {
refs.push(cursorCommitHash);