Skip to content

Commit f38eba1

Browse files
committed
Adds GitLens (Git) logger channel when debugging
1 parent db5c6f0 commit f38eba1

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

src/git/git.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,6 @@ const pendingCommands: Map<string, Promise<string>> = new Map();
5353
async function gitCommandCore(options: CommandOptions & { readonly correlationKey?: string }, ...args: any[]): Promise<string> {
5454
const start = process.hrtime();
5555

56-
// Fixes https://github.com/eamodio/vscode-gitlens/issues/73 & https://github.com/eamodio/vscode-gitlens/issues/161
57-
// See https://stackoverflow.com/questions/4144417/how-to-handle-asian-characters-in-file-names-in-git-on-os-x
58-
args.splice(0, 0, '-c', 'core.quotepath=false', '-c', 'color.ui=false');
59-
6056
const { correlationKey, ...opts } = options;
6157

6258
const encoding = options.encoding || 'utf8';
@@ -68,11 +64,16 @@ async function gitCommandCore(options: CommandOptions & { readonly correlationKe
6864
env: { ...(options.env || process.env), GCM_INTERACTIVE: 'NEVER', GCM_PRESERVE_CREDS: 'TRUE' }
6965
} as CommandOptions;
7066

71-
const command = `(${runOpts.cwd}${correlationKey !== undefined ? correlationKey : ''}): git ${args.join(' ')}`;
67+
const gitCommand = `git ${args.join(' ')}`;
68+
const command = `(${runOpts.cwd}${correlationKey !== undefined ? correlationKey : ''}): ${gitCommand}`;
7269

7370
let promise = pendingCommands.get(command);
7471
if (promise === undefined) {
7572
Logger.log(`Running${command}`);
73+
// Fixes https://github.com/eamodio/vscode-gitlens/issues/73 & https://github.com/eamodio/vscode-gitlens/issues/161
74+
// See https://stackoverflow.com/questions/4144417/how-to-handle-asian-characters-in-file-names-in-git-on-os-x
75+
args.splice(0, 0, '-c', 'core.quotepath=false', '-c', 'color.ui=false');
76+
7677
promise = runCommand(git.path, args, runOpts);
7778

7879
pendingCommands.set(command, promise);
@@ -89,7 +90,10 @@ async function gitCommandCore(options: CommandOptions & { readonly correlationKe
8990
pendingCommands.delete(command);
9091

9192
const duration = process.hrtime(start);
92-
Logger.log(`Completed${command} in ${(duration[0] * 1000) + Math.floor(duration[1] / 1000000)} ms`);
93+
const completedIn = `in ${(duration[0] * 1000) + Math.floor(duration[1] / 1000000)} ms`;
94+
95+
Logger.log(`Completed${command} ${completedIn}`);
96+
Logger.logGitCommand(`${gitCommand} ${completedIn}`, runOpts.cwd!);
9397
}
9498

9599
if (encoding === 'utf8' || encoding === 'binary') return data;

src/logger.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,15 @@ export class Logger {
7777
const now = new Date();
7878
return `[${now.toISOString().replace(/T/, ' ').replace(/\..+/, '')}:${('00' + now.getUTCMilliseconds()).slice(-3)}]`;
7979
}
80+
81+
static gitOutput: OutputChannel | undefined;
82+
83+
static logGitCommand(command: string, cwd: string): void {
84+
if (!this.debug) return;
85+
86+
if (this.gitOutput === undefined) {
87+
this.gitOutput = window.createOutputChannel(`${ExtensionOutputChannelName} (Git)`);
88+
}
89+
this.gitOutput.appendLine(`${this.timestamp} ${command} (${cwd})`);
90+
}
8091
}

0 commit comments

Comments
 (0)