mirror of
https://github.com/kahole/edamagit.git
synced 2024-10-26 09:00:54 +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 { PickMenuItem, PickMenuUtil } from '../menu/pickMenu';
|
||||||
import GitTextUtils from '../utils/gitTextUtils';
|
import GitTextUtils from '../utils/gitTextUtils';
|
||||||
import * as Constants from '../common/constants';
|
import * as Constants from '../common/constants';
|
||||||
|
import { getCommit } from './commitCache';
|
||||||
|
|
||||||
export interface Selection {
|
export interface Selection {
|
||||||
key: string;
|
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> {
|
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;
|
const activeEditor = vscode.window.activeTextEditor;
|
||||||
if (activeEditor === undefined) {
|
if (activeEditor === undefined) {
|
||||||
return;
|
return undefined;
|
||||||
}
|
}
|
||||||
const document = activeEditor.document;
|
const document = activeEditor.document;
|
||||||
const selection = activeEditor.selection;
|
const selection = activeEditor.selection;
|
||||||
const hashWordRange = document.getWordRangeAtPosition(selection.active, /[0-9a-z]{7}/);
|
const hashWordRange = document.getWordRangeAtPosition(selection.active, /[0-9a-z]{7}/);
|
||||||
if (hashWordRange === undefined) {
|
if (hashWordRange === undefined) {
|
||||||
return;
|
return undefined;
|
||||||
}
|
}
|
||||||
const hash = document.getText(hashWordRange);
|
const hash = document.getText(hashWordRange);
|
||||||
|
|
||||||
|
try {
|
||||||
|
await getCommit(repository.gitRepository, hash);
|
||||||
|
} catch (error) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
return { label: hash, meta: hash };
|
return { label: hash, meta: hash };
|
||||||
};
|
};
|
||||||
|
|
||||||
const refs: PickMenuItem<string>[] = [];
|
const refs: PickMenuItem<string>[] = [];
|
||||||
|
|
||||||
const cursorCommitHash = getCursorCommitHash();
|
const cursorCommitHash = await getCursorCommitHash();
|
||||||
|
|
||||||
if (cursorCommitHash) {
|
if (cursorCommitHash) {
|
||||||
refs.push(cursorCommitHash);
|
refs.push(cursorCommitHash);
|
||||||
|
Loading…
Reference in New Issue
Block a user