mirror of
https://github.com/kahole/edamagit.git
synced 2024-09-11 07:15:31 +03:00
check cursor-word chooseRef is actually a commit, otherwise throw away
This commit is contained in:
parent
153b0d6751
commit
3f66cd1cb5
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user