From e4cce8c6e8c29a0cd31f822a9f0b96d372ff2084 Mon Sep 17 00:00:00 2001 From: Ladislau Szomoru <3372902+lszomoru@users.noreply.github.com> Date: Fri, 4 Feb 2022 15:30:55 +0100 Subject: [PATCH] Add setting for git commands to be logged in the git output --- extensions/git/package.json | 9 +++++++++ extensions/git/package.nls.json | 1 + extensions/git/src/git.ts | 22 +++++++++++++++++++++- 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/extensions/git/package.json b/extensions/git/package.json index ab6a045ed97..1ba9c1de4a2 100644 --- a/extensions/git/package.json +++ b/extensions/git/package.json @@ -2245,6 +2245,15 @@ "scope": "resource", "default": 1, "markdownDescription": "%config.repositoryScanMaxDepth%" + }, + "git.commandsToLog": { + "type": "array", + "items": { + "type": "string" + }, + "default": [], + "scope": "resource", + "markdownDescription": "%config.commandsToLog%" } } }, diff --git a/extensions/git/package.nls.json b/extensions/git/package.nls.json index 72215388350..9fd574a721d 100644 --- a/extensions/git/package.nls.json +++ b/extensions/git/package.nls.json @@ -162,6 +162,7 @@ "config.ignoreSubmodules": "Ignore modifications to submodules in the file tree.", "config.ignoredRepositories": "List of git repositories to ignore.", "config.scanRepositories": "List of paths to search for git repositories in.", + "config.commandsToLog": "List of git commands (ex: commit, push) that would have their `stdout` logged to the [git output](command:git.showOutput). If the git command has a client-side hook configured, the client-side hook's `stdout` will also be logged to the [git output](command:git.showOutput).", "config.showProgress": "Controls whether git actions should show progress.", "config.rebaseWhenSync": "Force git to use rebase when running the sync command.", "config.confirmEmptyCommits": "Always confirm the creation of empty commits for the 'Git: Commit Empty' command.", diff --git a/extensions/git/src/git.ts b/extensions/git/src/git.ts index 3d29790f58f..c7b4e4f1b97 100644 --- a/extensions/git/src/git.ts +++ b/extensions/git/src/git.ts @@ -12,7 +12,7 @@ import { EventEmitter } from 'events'; import * as iconv from '@vscode/iconv-lite-umd'; import * as filetype from 'file-type'; import { assign, groupBy, IDisposable, toDisposable, dispose, mkdirp, readBytes, detectUnicodeEncoding, Encoding, onceEvent, splitInChunks, Limiter, Versions, isWindows } from './util'; -import { CancellationToken, Progress, Uri } from 'vscode'; +import { CancellationToken, ConfigurationChangeEvent, Progress, Uri, workspace } from 'vscode'; import { detectEncoding } from './encoding'; import { Ref, RefType, Branch, Remote, ForcePushMode, GitErrorCodes, LogOptions, Change, Status, CommitOptions, BranchQuery } from './api/git'; import * as byline from 'byline'; @@ -367,6 +367,7 @@ export class Git { readonly userAgent: string; readonly version: string; private env: any; + private commandsToLog: string[] = []; private _onOutput = new EventEmitter(); get onOutput(): EventEmitter { return this._onOutput; } @@ -376,6 +377,18 @@ export class Git { this.version = options.version; this.userAgent = options.userAgent; this.env = options.env || {}; + + const onConfigurationChanged = (e?: ConfigurationChangeEvent) => { + if (e !== undefined && !e.affectsConfiguration('git.commandsToLog')) { + return; + } + + const config = workspace.getConfiguration('git'); + this.commandsToLog = config.get('commandsToLog', []); + }; + + workspace.onDidChangeConfiguration(onConfigurationChanged, this); + onConfigurationChanged(); } compareGitVersionTo(version: string): -1 | 0 | 1 { @@ -534,8 +547,15 @@ export class Git { const bufferResult = await exec(child, options.cancellationToken); if (options.log !== false) { + // command this.log(`> git ${args.join(' ')} [${Date.now() - startTime}ms]\n`); + // stdout + if (args.length > 0 && this.commandsToLog.includes(args[0]) && bufferResult.stdout.length > 0) { + this.log(`${bufferResult.stdout}\n`); + } + + // stderr if (bufferResult.stderr.length > 0) { this.log(`${bufferResult.stderr}\n`); }