|
3 | 3 | * Licensed under the MIT License. See License.txt in the project root for license information.
|
4 | 4 | *--------------------------------------------------------------------------------------------*/
|
5 | 5 |
|
6 |
| -import { ExtensionContext, l10n, workspace } from 'vscode'; |
7 |
| -import { filterEvent, IDisposable } from './util'; |
| 6 | +import { ExtensionContext, l10n, LogOutputChannel, TerminalShellExecutionEndEvent, window, workspace } from 'vscode'; |
| 7 | +import { dispose, filterEvent, IDisposable } from './util'; |
| 8 | +import { Model } from './model'; |
8 | 9 |
|
9 | 10 | export interface ITerminalEnvironmentProvider {
|
10 | 11 | featureDescription?: string;
|
@@ -50,3 +51,41 @@ export class TerminalEnvironmentManager {
|
50 | 51 | this.disposable.dispose();
|
51 | 52 | }
|
52 | 53 | }
|
| 54 | + |
| 55 | +export class TerminalShellExecutionManager { |
| 56 | + private readonly subcommands = new Set<string>([ |
| 57 | + 'add', 'branch', 'checkout', 'clean', 'commit', |
| 58 | + 'fetch', 'reset', 'revert', 'pull', 'push', 'switch']); |
| 59 | + |
| 60 | + private readonly disposables: IDisposable[] = []; |
| 61 | + |
| 62 | + constructor( |
| 63 | + private readonly model: Model, |
| 64 | + private readonly logger: LogOutputChannel |
| 65 | + ) { |
| 66 | + window.onDidEndTerminalShellExecution(this.onDidEndTerminalShellExecution, this, this.disposables); |
| 67 | + } |
| 68 | + |
| 69 | + private onDidEndTerminalShellExecution(e: TerminalShellExecutionEndEvent): void { |
| 70 | + const { execution, exitCode, shellIntegration } = e; |
| 71 | + const [executable, subcommand] = execution.commandLine.value.split(/\s+/); |
| 72 | + |
| 73 | + if (executable.toLowerCase() !== 'git' || !this.subcommands.has(subcommand.toLowerCase()) || !shellIntegration.cwd || exitCode !== 0) { |
| 74 | + return; |
| 75 | + } |
| 76 | + |
| 77 | + this.logger.trace(`[TerminalShellExecutionManager][onDidEndTerminalShellExecution] Matched git subcommand: ${subcommand}`); |
| 78 | + |
| 79 | + const repository = this.model.getRepository(shellIntegration.cwd); |
| 80 | + if (!repository) { |
| 81 | + this.logger.trace(`[TerminalShellExecutionManager][onDidEndTerminalShellExecution] Unable to find repository for current working directory: ${shellIntegration.cwd}`); |
| 82 | + return; |
| 83 | + } |
| 84 | + |
| 85 | + repository.status(); |
| 86 | + } |
| 87 | + |
| 88 | + dispose(): void { |
| 89 | + dispose(this.disposables); |
| 90 | + } |
| 91 | +} |
0 commit comments