From 3f66cd1cb5496d066cf9c585ae0f10257ee24da3 Mon Sep 17 00:00:00 2001 From: Kristian Andersen Hole Date: Thu, 18 Jan 2024 22:22:18 +0100 Subject: [PATCH] check cursor-word chooseRef is actually a commit, otherwise throw away --- src/utils/magitUtils.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/utils/magitUtils.ts b/src/utils/magitUtils.ts index 77cf061..0f5cd02 100644 --- a/src/utils/magitUtils.ts +++ b/src/utils/magitUtils.ts @@ -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 { - const getCursorCommitHash: () => PickMenuItem | undefined = () => { + const getCursorCommitHash: () => Promise | 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[] = []; - const cursorCommitHash = getCursorCommitHash(); + const cursorCommitHash = await getCursorCommitHash(); if (cursorCommitHash) { refs.push(cursorCommitHash);