mirror of
https://github.com/kahole/edamagit.git
synced 2024-09-11 07:15:31 +03:00
adds resetting shortcuts and adds proper prompts to resetting
This commit is contained in:
parent
f2ce05e2bf
commit
7968df1eb4
10
package.json
10
package.json
@ -348,6 +348,16 @@
|
||||
"key": "shift+x",
|
||||
"when": "editorTextFocus && editorLangId == magit"
|
||||
},
|
||||
{
|
||||
"command": "magit.reset-mixed",
|
||||
"key": "x",
|
||||
"when": "editorTextFocus && editorLangId == magit"
|
||||
},
|
||||
{
|
||||
"command": "magit.reset-hard",
|
||||
"key": "ctrl+u x",
|
||||
"when": "editorTextFocus && editorLangId == magit"
|
||||
},
|
||||
{
|
||||
"command": "magit.remoting",
|
||||
"key": "shift+m",
|
||||
|
@ -2,14 +2,15 @@ import { MenuState, MenuUtil } from '../menu/menu';
|
||||
import { MagitRepository } from '../models/magitRepository';
|
||||
import { gitRun } from '../utils/gitRawRunner';
|
||||
import MagitUtils from '../utils/magitUtils';
|
||||
import { window } from 'vscode';
|
||||
|
||||
const resettingMenu = {
|
||||
title: 'Resetting',
|
||||
commands: [
|
||||
{ label: 'm', description: 'reset mixed (HEAD and index)', action: ({ repository }: MenuState) => _reset(repository, ['--mixed']) },
|
||||
{ label: 's', description: 'reset soft (HEAD only)', action: ({ repository }: MenuState) => _reset(repository, ['--soft']) },
|
||||
{ label: 'h', description: 'reset hard (HEAD, index and files)', action: ({ repository }: MenuState) => _reset(repository, ['--hard']) },
|
||||
{ label: 'i', description: 'reset index (only)', action: ({ repository }: MenuState) => _reset(repository, []) },
|
||||
{ label: 'm', description: 'reset mixed (HEAD and index)', action: ({ repository }: MenuState) => resetMixed(repository) },
|
||||
{ label: 's', description: 'reset soft (HEAD only)', action: ({ repository }: MenuState) => _reset(repository, ['--soft'], `Soft reset ${repository.magitState?.HEAD?.name} to`) },
|
||||
{ label: 'h', description: 'reset hard (HEAD, index and files)', action: ({ repository }: MenuState) => resetHard(repository) },
|
||||
{ label: 'i', description: 'reset index (only)', action: ({ repository }: MenuState) => _reset(repository, [], `Reset index to`) },
|
||||
{ label: 'w', description: 'reset worktree (only)', action: resetWorktree }
|
||||
// { label: 'f', description: 'reset a file', action: resetFile }
|
||||
]
|
||||
@ -19,15 +20,27 @@ export async function resetting(repository: MagitRepository) {
|
||||
return MenuUtil.showMenu(resettingMenu, { repository });
|
||||
}
|
||||
|
||||
async function resetWorktree({ repository }: MenuState) {
|
||||
|
||||
const args = ['checkout-index', '--all', '--force'];
|
||||
return await gitRun(repository, args);
|
||||
export async function resetMixed(repository: MagitRepository) {
|
||||
return _reset(repository, ['--mixed'], `Reset ${repository.magitState?.HEAD?.name} to`);
|
||||
}
|
||||
|
||||
async function _reset(repository: MagitRepository, switches: string[]) {
|
||||
export async function resetHard(repository: MagitRepository) {
|
||||
return _reset(repository, ['--hard'], `Hard reset ${repository.magitState?.HEAD?.name} to`);
|
||||
}
|
||||
|
||||
const ref = await MagitUtils.chooseRef(repository, 'Reset to', true, true);
|
||||
async function resetWorktree({ repository }: MenuState) {
|
||||
|
||||
const ref = await window.showQuickPick([`${repository.magitState?.HEAD?.name}`, 'HEAD'], { placeHolder: 'Reset worktree to' });
|
||||
|
||||
if (ref) {
|
||||
const args = ['checkout-index', '--all', '--force'];
|
||||
return await gitRun(repository, args);
|
||||
}
|
||||
}
|
||||
|
||||
async function _reset(repository: MagitRepository, switches: string[], prompt: string) {
|
||||
|
||||
const ref = await MagitUtils.chooseRef(repository, prompt, true, true);
|
||||
|
||||
if (ref) {
|
||||
|
||||
|
@ -28,7 +28,7 @@ import { remoting } from './commands/remotingCommands';
|
||||
import { logging } from './commands/loggingCommands';
|
||||
import { MagitProcessLogEntry } from './models/magitProcessLogEntry';
|
||||
import { processView } from './commands/processCommands';
|
||||
import { resetting } from './commands/resettingCommands';
|
||||
import { resetting, resetMixed, resetHard } from './commands/resettingCommands';
|
||||
import { tagging } from './commands/taggingCommands';
|
||||
import { worktree } from './commands/worktreeCommands';
|
||||
import { diffing } from './commands/diffingCommands';
|
||||
@ -83,6 +83,8 @@ export function activate(context: ExtensionContext) {
|
||||
context.subscriptions.push(commands.registerTextEditorCommand('magit.merging', Command.primeRepo(merging)));
|
||||
context.subscriptions.push(commands.registerTextEditorCommand('magit.rebasing', Command.primeRepo(rebasing)));
|
||||
context.subscriptions.push(commands.registerTextEditorCommand('magit.resetting', Command.primeRepo(resetting)));
|
||||
context.subscriptions.push(commands.registerTextEditorCommand('magit.reset-mixed', Command.primeRepo(resetMixed)));
|
||||
context.subscriptions.push(commands.registerTextEditorCommand('magit.reset-hard', Command.primeRepo(resetHard)));
|
||||
context.subscriptions.push(commands.registerTextEditorCommand('magit.remoting', Command.primeRepo(remoting)));
|
||||
context.subscriptions.push(commands.registerTextEditorCommand('magit.logging', Command.primeRepo(logging)));
|
||||
context.subscriptions.push(commands.registerTextEditorCommand('magit.show-refs', Command.primeRepo(showRefs)));
|
||||
|
Loading…
Reference in New Issue
Block a user