mirror of
https://github.com/kahole/edamagit.git
synced 2024-09-11 07:15:31 +03:00
adds raw command running feature (!)
This commit is contained in:
parent
bd7c96c9ce
commit
0d1ae69ad8
@ -1,7 +1,9 @@
|
||||
# Change Log
|
||||
|
||||
### 0.1.0
|
||||
### next version
|
||||
- Git command running (raw commands)
|
||||
- Git ignoring
|
||||
- Bug fixes
|
||||
|
||||
### 0.0.12
|
||||
- Fixup commits (@zachdaniel Zach Daniel)
|
||||
|
@ -34,7 +34,7 @@ Popup commands
|
||||
m Merging M Remoting t Tagging
|
||||
P Pushing r Rebasing X Resetting
|
||||
y Show Refs z Stashing % Worktree
|
||||
i Ignoring
|
||||
i Ignoring ! Running
|
||||
|
||||
Applying changes
|
||||
a Apply s Stage u Unstage
|
||||
|
13
package.json
13
package.json
@ -122,6 +122,10 @@
|
||||
"command": "magit.ignoring",
|
||||
"title": "Magit Ignore"
|
||||
},
|
||||
{
|
||||
"command": "magit.running",
|
||||
"title": "Magit Running"
|
||||
},
|
||||
{
|
||||
"command": "magit.worktree",
|
||||
"title": "Magit Worktree"
|
||||
@ -205,6 +209,10 @@
|
||||
"command": "magit.ignoring",
|
||||
"when": "editorLangId == magit"
|
||||
},
|
||||
{
|
||||
"command": "magit.running",
|
||||
"when": "editorLangId == magit"
|
||||
},
|
||||
{
|
||||
"command": "magit.worktree",
|
||||
"when": "editorLangId == magit"
|
||||
@ -401,6 +409,11 @@
|
||||
"key": "shift+i",
|
||||
"when": "editorTextFocus && editorLangId == magit"
|
||||
},
|
||||
{
|
||||
"command": "magit.running",
|
||||
"key": "shift+1",
|
||||
"when": "editorTextFocus && editorLangId == magit"
|
||||
},
|
||||
{
|
||||
"command": "magit.worktree",
|
||||
"key": "shift+5",
|
||||
|
@ -7,7 +7,13 @@ import { MagitRepository } from '../models/magitRepository';
|
||||
export async function processView(repository: MagitRepository) {
|
||||
const uri = ProcessView.encodeLocation(repository);
|
||||
|
||||
views.set(uri.toString(), new ProcessView(uri));
|
||||
const existingView = views.get(uri.toString());
|
||||
|
||||
workspace.openTextDocument(uri).then(doc => window.showTextDocument(doc, { viewColumn: MagitUtils.oppositeActiveViewColumn(), preview: false }));
|
||||
if (existingView) {
|
||||
existingView.update(repository.magitState!);
|
||||
} else {
|
||||
views.set(uri.toString(), new ProcessView(uri));
|
||||
}
|
||||
|
||||
return workspace.openTextDocument(uri).then(doc => window.showTextDocument(doc, { viewColumn: MagitUtils.oppositeActiveViewColumn(), preview: false }));
|
||||
}
|
||||
|
38
src/commands/runningCommands.ts
Normal file
38
src/commands/runningCommands.ts
Normal file
@ -0,0 +1,38 @@
|
||||
import { MagitRepository } from '../models/magitRepository';
|
||||
import { MenuUtil, MenuState } from '../menu/menu';
|
||||
import { window, workspace, Uri } from 'vscode';
|
||||
import { gitRun, LogLevel } from '../utils/gitRawRunner';
|
||||
import { processView } from './processCommands';
|
||||
import { SpawnOptions } from 'child_process';
|
||||
|
||||
const runningMenu = {
|
||||
title: 'Ignoring',
|
||||
commands: [
|
||||
{ label: '!', description: 'Git subcommand (in topdir)', action: ({ repository }: MenuState) => run(repository) },
|
||||
{ label: 'p', description: 'Git subcommand (in pwd)', action: ({ repository }: MenuState) => run(repository, workspace.getWorkspaceFolder(repository.rootUri)?.uri) }
|
||||
]
|
||||
};
|
||||
|
||||
export async function running(repository: MagitRepository) {
|
||||
return MenuUtil.showMenu(runningMenu, { repository });
|
||||
}
|
||||
|
||||
async function run(repository: MagitRepository, directory?: Uri) {
|
||||
|
||||
const userCommand = await window.showInputBox({ value: 'git ' });
|
||||
|
||||
let spawnOptions: SpawnOptions = {};
|
||||
|
||||
if (directory) {
|
||||
spawnOptions.cwd = directory.fsPath;
|
||||
}
|
||||
|
||||
if (userCommand) {
|
||||
const args = userCommand.replace('git ', '').split(' ');
|
||||
await gitRun(repository, args, spawnOptions, LogLevel.Detailed);
|
||||
|
||||
await processView(repository);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
@ -9,7 +9,7 @@ import MagitStatusView from '../views/magitStatusView';
|
||||
import { Status, Commit, RefType } from '../typings/git';
|
||||
import { MagitBranch } from '../models/magitBranch';
|
||||
import { Section } from '../views/general/sectionHeader';
|
||||
import { gitRun } from '../utils/gitRawRunner';
|
||||
import { gitRun, LogLevel } from '../utils/gitRawRunner';
|
||||
import * as Constants from '../common/constants';
|
||||
import { getCommit } from '../utils/commitCache';
|
||||
import { MagitRemote } from '../models/magitRemote';
|
||||
@ -59,7 +59,7 @@ export async function internalMagitStatus(repository: MagitRepository): Promise<
|
||||
if (repository.state.HEAD?.ahead || repository.state.HEAD?.behind) {
|
||||
const ref = repository.state.HEAD.name;
|
||||
const args = ['rev-list', '--left-right', `${ref}...${ref}@{u}`];
|
||||
const res = (await gitRun(repository, args)).stdout;
|
||||
const res = (await gitRun(repository, args, {}, LogLevel.None)).stdout;
|
||||
[commitsAhead, commitsBehind] = GitTextUtils.parseRevListLeftRight(res);
|
||||
interestingCommits.push(...[...commitsAhead, ...commitsBehind]);
|
||||
}
|
||||
|
@ -33,6 +33,7 @@ import { tagging } from './commands/taggingCommands';
|
||||
import { worktree } from './commands/worktreeCommands';
|
||||
import { diffing } from './commands/diffingCommands';
|
||||
import { ignoring } from './commands/ignoringCommands';
|
||||
import { running } from './commands/runningCommands';
|
||||
|
||||
export const magitRepositories: Map<string, MagitRepository> = new Map<string, MagitRepository>();
|
||||
export const views: Map<string, DocumentView> = new Map<string, DocumentView>();
|
||||
@ -92,6 +93,7 @@ export function activate(context: ExtensionContext) {
|
||||
context.subscriptions.push(commands.registerTextEditorCommand('magit.diffing', Command.primeRepo(diffing)));
|
||||
context.subscriptions.push(commands.registerTextEditorCommand('magit.tagging', Command.primeRepo(tagging)));
|
||||
context.subscriptions.push(commands.registerTextEditorCommand('magit.ignoring', Command.primeRepo(ignoring)));
|
||||
context.subscriptions.push(commands.registerTextEditorCommand('magit.running', Command.primeRepo(running)));
|
||||
context.subscriptions.push(commands.registerTextEditorCommand('magit.worktree', Command.primeRepo(worktree)));
|
||||
context.subscriptions.push(commands.registerTextEditorCommand('magit.process-log', Command.primeRepo(processView, false)));
|
||||
|
||||
|
@ -2,20 +2,37 @@ import { MagitRepository } from '../models/magitRepository';
|
||||
import { SpawnOptions } from '../common/gitApiExtensions';
|
||||
import MagitLogger from './logger';
|
||||
|
||||
export async function gitRun(repository: MagitRepository, args: string[], spawnOptions?: SpawnOptions) {
|
||||
export enum LogLevel {
|
||||
None,
|
||||
Error,
|
||||
Detailed
|
||||
}
|
||||
|
||||
const logEntry = MagitLogger.logGitCommand(args);
|
||||
export async function gitRun(repository: MagitRepository, args: string[], spawnOptions?: SpawnOptions, logLevel = LogLevel.Error) {
|
||||
|
||||
let logEntry;
|
||||
if (logLevel > LogLevel.None) {
|
||||
logEntry = MagitLogger.logGitCommand(args);
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
let result;
|
||||
// Protects against projected change in internal api in vscode git extension
|
||||
if (repository._repository.repository.run) {
|
||||
return await repository._repository.repository.run(args, spawnOptions);
|
||||
result = await repository._repository.repository.run(args, spawnOptions);
|
||||
} else {
|
||||
return await repository._repository.repository.exec!(args, spawnOptions);
|
||||
result = await repository._repository.repository.exec!(args, spawnOptions);
|
||||
}
|
||||
|
||||
if (logLevel === LogLevel.Detailed && logEntry) {
|
||||
MagitLogger.logGitResult(result, logEntry);
|
||||
}
|
||||
|
||||
return result;
|
||||
} catch (error) {
|
||||
MagitLogger.logGitError(error, logEntry);
|
||||
if (logLevel > LogLevel.None && logEntry) {
|
||||
MagitLogger.logGitError(error, logEntry);
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
import GitTextUtils from './gitTextUtils';
|
||||
import { processLog } from '../extension';
|
||||
import { MagitProcessLogEntry } from '../models/magitProcessLogEntry';
|
||||
import { IExecutionResult } from '../common/gitApiExtensions';
|
||||
|
||||
export default class MagitLogger {
|
||||
|
||||
@ -10,6 +10,10 @@ export default class MagitLogger {
|
||||
return logEntry;
|
||||
}
|
||||
|
||||
public static logGitResult(result: IExecutionResult<string>, entry: MagitProcessLogEntry) {
|
||||
entry.output = result.stdout;
|
||||
}
|
||||
|
||||
public static logGitError(error: any, entry: MagitProcessLogEntry) {
|
||||
const errorMsg = error.stderr ?? error.message;
|
||||
entry.output = errorMsg;
|
||||
|
@ -19,7 +19,7 @@ export class DispatchView extends DocumentView {
|
||||
m Merging M Remoting t Tagging
|
||||
P Pushing r Rebasing X Resetting
|
||||
y Show Refs z Stashing % Worktree
|
||||
i Ignoring`));
|
||||
i Ignoring ! Running`));
|
||||
}
|
||||
|
||||
public update(state: MagitState): void { }
|
||||
|
@ -37,7 +37,7 @@ export class HelpView extends DocumentView {
|
||||
m Merging M Remoting t Tagging
|
||||
P Pushing r Rebasing X Resetting
|
||||
y Show Refs z Stashing % Worktree
|
||||
i Ignoring
|
||||
i Ignoring ! Running
|
||||
|
||||
Applying changes
|
||||
a Apply s Stage u Unstage
|
||||
|
Loading…
Reference in New Issue
Block a user