Skip to content

Commit b17732f

Browse files
authored
Git - add terminal shell execution listener (microsoft#221895)
1 parent 8fe01b3 commit b17732f

File tree

4 files changed

+48
-6
lines changed

4 files changed

+48
-6
lines changed

extensions/git/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"diffCommand",
2626
"editSessionIdentityProvider",
2727
"quickDiffProvider",
28+
"quickInputButtonLocation",
2829
"quickPickSortByLabel",
2930
"scmActionButton",
3031
"scmHistoryProvider",
@@ -34,8 +35,8 @@
3435
"scmValidation",
3536
"tabInputMultiDiff",
3637
"tabInputTextMerge",
37-
"timeline",
38-
"quickInputButtonLocation"
38+
"terminalShellIntegration",
39+
"timeline"
3940
],
4041
"categories": [
4142
"Other"

extensions/git/src/main.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import * as fs from 'fs';
2020
import * as os from 'os';
2121
import { GitTimelineProvider } from './timelineProvider';
2222
import { registerAPICommands } from './api/api1';
23-
import { TerminalEnvironmentManager } from './terminal';
23+
import { TerminalEnvironmentManager, TerminalShellExecutionManager } from './terminal';
2424
import { createIPCServer, IPCServer } from './ipc/ipcServer';
2525
import { GitEditor } from './gitEditor';
2626
import { GitPostCommitCommandsProvider } from './postCommitCommands';
@@ -113,7 +113,8 @@ async function createModel(context: ExtensionContext, logger: LogOutputChannel,
113113
new GitFileSystemProvider(model),
114114
new GitDecorations(model),
115115
new GitTimelineProvider(model, cc),
116-
new GitEditSessionIdentityProvider(model)
116+
new GitEditSessionIdentityProvider(model),
117+
new TerminalShellExecutionManager(model, logger)
117118
);
118119

119120
const postCommitCommandsProvider = new GitPostCommitCommandsProvider();

extensions/git/src/terminal.ts

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

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';
89

910
export interface ITerminalEnvironmentProvider {
1011
featureDescription?: string;
@@ -50,3 +51,41 @@ export class TerminalEnvironmentManager {
5051
this.disposable.dispose();
5152
}
5253
}
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+
}

extensions/git/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"../../src/vscode-dts/vscode.proposed.scmTextDocument.d.ts",
2121
"../../src/vscode-dts/vscode.proposed.tabInputMultiDiff.d.ts",
2222
"../../src/vscode-dts/vscode.proposed.tabInputTextMerge.d.ts",
23+
"../../src/vscode-dts/vscode.proposed.terminalShellIntegration.d.ts",
2324
"../../src/vscode-dts/vscode.proposed.timeline.d.ts",
2425
"../../src/vscode-dts/vscode.proposed.quickInputButtonLocation.d.ts",
2526
"../types/lib.textEncoder.d.ts"

0 commit comments

Comments
 (0)