mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-26 03:29:00 +01:00
Git - add terminal shell execution listener (#221895)
This commit is contained in:
@@ -20,7 +20,7 @@ import * as fs from 'fs';
|
||||
import * as os from 'os';
|
||||
import { GitTimelineProvider } from './timelineProvider';
|
||||
import { registerAPICommands } from './api/api1';
|
||||
import { TerminalEnvironmentManager } from './terminal';
|
||||
import { TerminalEnvironmentManager, TerminalShellExecutionManager } from './terminal';
|
||||
import { createIPCServer, IPCServer } from './ipc/ipcServer';
|
||||
import { GitEditor } from './gitEditor';
|
||||
import { GitPostCommitCommandsProvider } from './postCommitCommands';
|
||||
@@ -113,7 +113,8 @@ async function createModel(context: ExtensionContext, logger: LogOutputChannel,
|
||||
new GitFileSystemProvider(model),
|
||||
new GitDecorations(model),
|
||||
new GitTimelineProvider(model, cc),
|
||||
new GitEditSessionIdentityProvider(model)
|
||||
new GitEditSessionIdentityProvider(model),
|
||||
new TerminalShellExecutionManager(model, logger)
|
||||
);
|
||||
|
||||
const postCommitCommandsProvider = new GitPostCommitCommandsProvider();
|
||||
|
||||
@@ -3,8 +3,9 @@
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { ExtensionContext, l10n, workspace } from 'vscode';
|
||||
import { filterEvent, IDisposable } from './util';
|
||||
import { ExtensionContext, l10n, LogOutputChannel, TerminalShellExecutionEndEvent, window, workspace } from 'vscode';
|
||||
import { dispose, filterEvent, IDisposable } from './util';
|
||||
import { Model } from './model';
|
||||
|
||||
export interface ITerminalEnvironmentProvider {
|
||||
featureDescription?: string;
|
||||
@@ -50,3 +51,41 @@ export class TerminalEnvironmentManager {
|
||||
this.disposable.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
export class TerminalShellExecutionManager {
|
||||
private readonly subcommands = new Set<string>([
|
||||
'add', 'branch', 'checkout', 'clean', 'commit',
|
||||
'fetch', 'reset', 'revert', 'pull', 'push', 'switch']);
|
||||
|
||||
private readonly disposables: IDisposable[] = [];
|
||||
|
||||
constructor(
|
||||
private readonly model: Model,
|
||||
private readonly logger: LogOutputChannel
|
||||
) {
|
||||
window.onDidEndTerminalShellExecution(this.onDidEndTerminalShellExecution, this, this.disposables);
|
||||
}
|
||||
|
||||
private onDidEndTerminalShellExecution(e: TerminalShellExecutionEndEvent): void {
|
||||
const { execution, exitCode, shellIntegration } = e;
|
||||
const [executable, subcommand] = execution.commandLine.value.split(/\s+/);
|
||||
|
||||
if (executable.toLowerCase() !== 'git' || !this.subcommands.has(subcommand.toLowerCase()) || !shellIntegration.cwd || exitCode !== 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.logger.trace(`[TerminalShellExecutionManager][onDidEndTerminalShellExecution] Matched git subcommand: ${subcommand}`);
|
||||
|
||||
const repository = this.model.getRepository(shellIntegration.cwd);
|
||||
if (!repository) {
|
||||
this.logger.trace(`[TerminalShellExecutionManager][onDidEndTerminalShellExecution] Unable to find repository for current working directory: ${shellIntegration.cwd}`);
|
||||
return;
|
||||
}
|
||||
|
||||
repository.status();
|
||||
}
|
||||
|
||||
dispose(): void {
|
||||
dispose(this.disposables);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user