diff --git a/extensions/git/package.json b/extensions/git/package.json index 124648c8748..696286c2c9f 100644 --- a/extensions/git/package.json +++ b/extensions/git/package.json @@ -25,6 +25,7 @@ "diffCommand", "editSessionIdentityProvider", "quickDiffProvider", + "quickInputButtonLocation", "quickPickSortByLabel", "scmActionButton", "scmHistoryProvider", @@ -34,8 +35,8 @@ "scmValidation", "tabInputMultiDiff", "tabInputTextMerge", - "timeline", - "quickInputButtonLocation" + "terminalShellIntegration", + "timeline" ], "categories": [ "Other" diff --git a/extensions/git/src/main.ts b/extensions/git/src/main.ts index b3f6b6466fe..aa4d98adc8b 100644 --- a/extensions/git/src/main.ts +++ b/extensions/git/src/main.ts @@ -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(); diff --git a/extensions/git/src/terminal.ts b/extensions/git/src/terminal.ts index 4f6d95488bb..0990e5c909e 100644 --- a/extensions/git/src/terminal.ts +++ b/extensions/git/src/terminal.ts @@ -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([ + '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); + } +} diff --git a/extensions/git/tsconfig.json b/extensions/git/tsconfig.json index 75fb8217df7..54d58aac432 100644 --- a/extensions/git/tsconfig.json +++ b/extensions/git/tsconfig.json @@ -20,6 +20,7 @@ "../../src/vscode-dts/vscode.proposed.scmTextDocument.d.ts", "../../src/vscode-dts/vscode.proposed.tabInputMultiDiff.d.ts", "../../src/vscode-dts/vscode.proposed.tabInputTextMerge.d.ts", + "../../src/vscode-dts/vscode.proposed.terminalShellIntegration.d.ts", "../../src/vscode-dts/vscode.proposed.timeline.d.ts", "../../src/vscode-dts/vscode.proposed.quickInputButtonLocation.d.ts", "../types/lib.textEncoder.d.ts"