mirror of
https://github.com/kahole/edamagit.git
synced 2024-09-11 07:15:31 +03:00
adds merging commands
This commit is contained in:
parent
f6c6b90f23
commit
4e1d6a1937
13
package.json
13
package.json
@ -40,6 +40,10 @@
|
||||
"command": "extension.magit-branching",
|
||||
"title": "Magit Branching"
|
||||
},
|
||||
{
|
||||
"command": "extension.magit-merging",
|
||||
"title": "Magit Merging"
|
||||
},
|
||||
{
|
||||
"command": "extension.magit-pushing",
|
||||
"title": "Magit Pushing"
|
||||
@ -75,6 +79,10 @@
|
||||
"command": "extension.magit-branching",
|
||||
"when": "editorLangId == magit"
|
||||
},
|
||||
{
|
||||
"command": "extension.magit-merging",
|
||||
"when": "editorLangId == magit"
|
||||
},
|
||||
{
|
||||
"command": "extension.magit-visit-at-point",
|
||||
"when": "editorLangId == magit"
|
||||
@ -182,6 +190,11 @@
|
||||
"key": "b",
|
||||
"when": "editorTextFocus && editorLangId == magit"
|
||||
},
|
||||
{
|
||||
"command": "extension.magit-merging",
|
||||
"key": "m",
|
||||
"when": "editorTextFocus && editorLangId == magit"
|
||||
},
|
||||
{
|
||||
"command": "extension.magit-pushing",
|
||||
"key": "shift+p",
|
||||
|
@ -61,6 +61,7 @@ async function createNewBranch(menuState: MenuState) {
|
||||
|
||||
async function configureBranch(menuState: MenuState) {
|
||||
|
||||
// MINOR
|
||||
// 1. Select branch? or take current?
|
||||
// 2. Read all configs: menuState.repository.getConfigs
|
||||
// maybe they are already read in the repo state?
|
||||
@ -114,7 +115,7 @@ async function resetBranch({ repository, currentView }: MenuState) {
|
||||
|
||||
if (MagitUtils.magitAnythingModified(repository)) {
|
||||
|
||||
if(await MagitUtils.confirmAction(`Uncommitted changes will be lost. Proceed?`)) {
|
||||
if (await MagitUtils.confirmAction(`Uncommitted changes will be lost. Proceed?`)) {
|
||||
return repository._repository.reset(resetToRef, true);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,87 @@
|
||||
import { window, commands } from 'vscode';
|
||||
import { Menu, MenuState, MenuUtil } from '../menu/menu';
|
||||
import { MagitRepository } from '../models/magitRepository';
|
||||
import { DocumentView } from '../views/general/documentView';
|
||||
import { gitRun } from '../utils/gitRawRunner';
|
||||
|
||||
const mergingMenu = {
|
||||
title: 'Merging',
|
||||
commands: [
|
||||
{ label: 'm', description: 'Merge', action: merge },
|
||||
{ label: 'e', description: 'Merge and edit message', action: merge },
|
||||
{ label: 'n', description: 'Merge, don\'t commit', action: merge },
|
||||
{ label: 'a', description: 'Absorb', action: absorb },
|
||||
{ label: 'p', description: 'Preview Merge', action: mergePreview },
|
||||
{ label: 's', description: 'Squash Merge', action: merge },
|
||||
{ label: 's', description: 'Merge into', action: merge },
|
||||
]
|
||||
};
|
||||
|
||||
const whileMergingMenu = {
|
||||
title: 'Merging',
|
||||
commands: [
|
||||
{ label: 'm', description: 'Commit merge', action: commitMerge },
|
||||
{ label: 'a', description: 'Abort merge', action: abortMerge }
|
||||
]
|
||||
};
|
||||
|
||||
export async function merging(repository: MagitRepository, currentView: DocumentView) {
|
||||
|
||||
if (repository.magitState?.mergingState) {
|
||||
return MenuUtil.showMenu(whileMergingMenu, { repository, currentView });
|
||||
} else {
|
||||
return MenuUtil.showMenu(mergingMenu, { repository, currentView });
|
||||
}
|
||||
}
|
||||
|
||||
async function merge({ repository }: MenuState) {
|
||||
const ref = await window.showQuickPick(repository.state.refs.map(r => r.name!), { placeHolder: 'Merge' });
|
||||
|
||||
if (ref) {
|
||||
return _merge(repository, ref);
|
||||
}
|
||||
}
|
||||
|
||||
async function absorb({ repository }: MenuState) {
|
||||
const ref = await window.showQuickPick(repository.state.refs.map(r => r.name!), { placeHolder: 'Merge' });
|
||||
|
||||
if (ref) {
|
||||
await _merge(repository, ref);
|
||||
return await repository.deleteBranch(ref, false);
|
||||
}
|
||||
}
|
||||
|
||||
async function mergePreview() {
|
||||
// Maybe so different from the rest?
|
||||
}
|
||||
|
||||
async function _merge(repository: MagitRepository, ref: string, noCommit = false, squashMerge = false, editMessage = false) {
|
||||
|
||||
const args = ['merge', ref];
|
||||
|
||||
if (noCommit) {
|
||||
args.push(...['--no-commit', '--no-ff']);
|
||||
}
|
||||
|
||||
if (squashMerge) {
|
||||
args.push('--squash');
|
||||
}
|
||||
|
||||
if (editMessage) {
|
||||
// TODO: This might need a separate handler, because of message editing??
|
||||
args.push(...['--edit', '--no-ff']);
|
||||
} else {
|
||||
args.push('--no-edit');
|
||||
}
|
||||
|
||||
return gitRun(repository, args);
|
||||
}
|
||||
|
||||
async function commitMerge({ repository }: MenuState) {
|
||||
|
||||
}
|
||||
|
||||
async function abortMerge({ repository }: MenuState) {
|
||||
const args = ['merge', '--abort'];
|
||||
return gitRun(repository, args);
|
||||
}
|
@ -20,6 +20,7 @@ import { stashing } from './commands/stashingCommands';
|
||||
import { DocumentView } from './views/general/documentView';
|
||||
import { magitApplyEntityAtPoint } from './commands/applyCommands';
|
||||
import { magitDiscardAtPoint } from './commands/discardCommands';
|
||||
import { merging } from './commands/mergingCommands';
|
||||
|
||||
export const magitRepositories: Map<string, MagitRepository> = new Map<string, MagitRepository>();
|
||||
export const views: Map<string, DocumentView> = new Map<string, DocumentView>();
|
||||
@ -68,6 +69,7 @@ export function activate(context: ExtensionContext) {
|
||||
|
||||
context.subscriptions.push(commands.registerCommand('extension.magit-fetching', fetching));
|
||||
context.subscriptions.push(commands.registerTextEditorCommand('extension.magit-branching', CommandPrimer.primeRepoAndView(branching)));
|
||||
context.subscriptions.push(commands.registerTextEditorCommand('extension.magit-merging', CommandPrimer.primeRepoAndView(merging)));
|
||||
context.subscriptions.push(commands.registerTextEditorCommand('extension.magit-stage', CommandPrimer.primeRepoAndView(magitStage)));
|
||||
context.subscriptions.push(commands.registerTextEditorCommand('extension.magit-stage-all', CommandPrimer.primeRepoAndView(magitStageAll)));
|
||||
context.subscriptions.push(commands.registerTextEditorCommand('extension.magit-unstage', CommandPrimer.primeRepoAndView(magitUnstage)));
|
||||
|
Loading…
Reference in New Issue
Block a user