Skip to content

Commit

Permalink
add commit hash under curosr in chooseRef
Browse files Browse the repository at this point in the history
  • Loading branch information
bzy-debug committed Dec 1, 2023
1 parent 64cd537 commit 1548225
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/utils/magitUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> {

const getCursorCommitHash: () => PickMenuItem<string> | 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<string>[] = [];

const cursorCommitHash = getCursorCommitHash();

if (cursorCommitHash) {
refs.push(cursorCommitHash);
}

if (showCurrent && repository.HEAD?.name) {
refs.push({
label: repository.HEAD.name,
Expand Down

0 comments on commit 1548225

Please sign in to comment.