From 154822599bd5259b0834a8dc9eb92cd0129aa2ef Mon Sep 17 00:00:00 2001 From: bzy-debug Date: Sat, 25 Nov 2023 17:36:37 +0800 Subject: [PATCH] add commit hash under curosr in chooseRef --- src/utils/magitUtils.ts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/utils/magitUtils.ts b/src/utils/magitUtils.ts index 1830cdc..77cf061 100644 --- a/src/utils/magitUtils.ts +++ b/src/utils/magitUtils.ts @@ -150,8 +150,29 @@ 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 activeEditor = vscode.window.activeTextEditor; + if (activeEditor === undefined) { + return; + } + const document = activeEditor.document; + const selection = activeEditor.selection; + const hashWordRange = document.getWordRangeAtPosition(selection.active, /[0-9a-z]{7}/); + if (hashWordRange === undefined) { + return; + } + const hash = document.getText(hashWordRange); + return { label: hash, meta: hash }; + }; + const refs: PickMenuItem[] = []; + const cursorCommitHash = getCursorCommitHash(); + + if (cursorCommitHash) { + refs.push(cursorCommitHash); + } + if (showCurrent && repository.HEAD?.name) { refs.push({ label: repository.HEAD.name,