Skip to content

Commit 2288e7c

Browse files
committed
improve git logging
1 parent 8e746bb commit 2288e7c

3 files changed

Lines changed: 16 additions & 5 deletions

File tree

extensions/git/src/git.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ export class Git {
461461
});
462462

463463
if (options.log !== false) {
464-
this.log(`git ${args.join(' ')}\n`);
464+
this.log(`> git ${args.join(' ')}\n`);
465465
}
466466

467467
return cp.spawn(this.gitPath, args, options);

extensions/git/src/main.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ async function init(context: ExtensionContext, outputChannel: OutputChannel, dis
2626
const askpass = new Askpass();
2727
const env = await askpass.getEnv();
2828
const git = new Git({ gitPath: info.path, version: info.version, env });
29-
const model = new Model(git, context.globalState);
29+
const model = new Model(git, context.globalState, outputChannel);
3030
disposables.push(model);
3131

3232
const onRepository = () => commands.executeCommand('setContext', 'gitOpenRepositoryCount', `${model.repositories.length}`);
@@ -36,7 +36,15 @@ async function init(context: ExtensionContext, outputChannel: OutputChannel, dis
3636

3737
outputChannel.appendLine(localize('using git', "Using git {0} from {1}", info.version, info.path));
3838

39-
const onOutput = (str: string) => outputChannel.append(str);
39+
const onOutput = (str: string) => {
40+
const lines = str.split(/\r?\n/mg);
41+
42+
while (/^\s*$/.test(lines[lines.length - 1])) {
43+
lines.pop();
44+
}
45+
46+
outputChannel.appendLine(lines.join('\n'));
47+
};
4048
git.onOutput.addListener('log', onOutput);
4149
disposables.push(toDisposable(() => git.onOutput.removeListener('log', onOutput)));
4250

extensions/git/src/model.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
'use strict';
77

8-
import { workspace, WorkspaceFoldersChangeEvent, Uri, window, Event, EventEmitter, QuickPickItem, Disposable, SourceControl, SourceControlResourceGroup, TextEditor, Memento } from 'vscode';
8+
import { workspace, WorkspaceFoldersChangeEvent, Uri, window, Event, EventEmitter, QuickPickItem, Disposable, SourceControl, SourceControlResourceGroup, TextEditor, Memento, OutputChannel } from 'vscode';
99
import { Repository, RepositoryState } from './repository';
1010
import { memoize, sequentialize, debounce } from './decorators';
1111
import { dispose, anyEvent, filterEvent, isDescendant, firstIndex } from './util';
@@ -66,7 +66,7 @@ export class Model {
6666

6767
private disposables: Disposable[] = [];
6868

69-
constructor(private git: Git, private globalState: Memento) {
69+
constructor(private git: Git, private globalState: Memento, private outputChannel: OutputChannel) {
7070
workspace.onDidChangeWorkspaceFolders(this.onDidChangeWorkspaceFolders, this, this.disposables);
7171
this.onDidChangeWorkspaceFolders({ added: workspace.workspaceFolders || [], removed: [] });
7272

@@ -215,6 +215,8 @@ export class Model {
215215
}
216216

217217
private open(repository: Repository): void {
218+
this.outputChannel.appendLine(`Open repository: ${repository.root}`);
219+
218220
const onDidDisappearRepository = filterEvent(repository.onDidChangeState, state => state === RepositoryState.Disposed);
219221
const disappearListener = onDidDisappearRepository(() => dispose());
220222
const changeListener = repository.onDidChangeRepository(uri => this._onDidChangeRepository.fire({ repository, uri }));
@@ -260,6 +262,7 @@ export class Model {
260262
return;
261263
}
262264

265+
this.outputChannel.appendLine(`Close repository: ${repository.root}`);
263266
openRepository.dispose();
264267
}
265268

0 commit comments

Comments
 (0)