Просмотр исходного кода

Adds GitLens (Git) logger channel when debugging

main
Eric Amodio 6 лет назад
Родитель
Сommit
f38eba1813
2 измененных файлов: 21 добавлений и 6 удалений
  1. +10
    -6
      src/git/git.ts
  2. +11
    -0
      src/logger.ts

+ 10
- 6
src/git/git.ts Просмотреть файл

@ -53,10 +53,6 @@ const pendingCommands: Map> = new Map();
async function gitCommandCore(options: CommandOptions & { readonly correlationKey?: string }, ...args: any[]): Promise<string> {
const start = process.hrtime();
// Fixes https://github.com/eamodio/vscode-gitlens/issues/73 & https://github.com/eamodio/vscode-gitlens/issues/161
// See https://stackoverflow.com/questions/4144417/how-to-handle-asian-characters-in-file-names-in-git-on-os-x
args.splice(0, 0, '-c', 'core.quotepath=false', '-c', 'color.ui=false');
const { correlationKey, ...opts } = options;
const encoding = options.encoding || 'utf8';
@ -68,11 +64,16 @@ async function gitCommandCore(options: CommandOptions & { readonly correlationKe
env: { ...(options.env || process.env), GCM_INTERACTIVE: 'NEVER', GCM_PRESERVE_CREDS: 'TRUE' }
} as CommandOptions;
const command = `(${runOpts.cwd}${correlationKey !== undefined ? correlationKey : ''}): git ${args.join(' ')}`;
const gitCommand = `git ${args.join(' ')}`;
const command = `(${runOpts.cwd}${correlationKey !== undefined ? correlationKey : ''}): ${gitCommand}`;
let promise = pendingCommands.get(command);
if (promise === undefined) {
Logger.log(`Running${command}`);
// Fixes https://github.com/eamodio/vscode-gitlens/issues/73 & https://github.com/eamodio/vscode-gitlens/issues/161
// See https://stackoverflow.com/questions/4144417/how-to-handle-asian-characters-in-file-names-in-git-on-os-x
args.splice(0, 0, '-c', 'core.quotepath=false', '-c', 'color.ui=false');
promise = runCommand(git.path, args, runOpts);
pendingCommands.set(command, promise);
@ -89,7 +90,10 @@ async function gitCommandCore(options: CommandOptions & { readonly correlationKe
pendingCommands.delete(command);
const duration = process.hrtime(start);
Logger.log(`Completed${command} in ${(duration[0] * 1000) + Math.floor(duration[1] / 1000000)} ms`);
const completedIn = `in ${(duration[0] * 1000) + Math.floor(duration[1] / 1000000)} ms`;
Logger.log(`Completed${command} ${completedIn}`);
Logger.logGitCommand(`${gitCommand} ${completedIn}`, runOpts.cwd!);
}
if (encoding === 'utf8' || encoding === 'binary') return data;

+ 11
- 0
src/logger.ts Просмотреть файл

@ -77,4 +77,15 @@ export class Logger {
const now = new Date();
return `[${now.toISOString().replace(/T/, ' ').replace(/\..+/, '')}:${('00' + now.getUTCMilliseconds()).slice(-3)}]`;
}
static gitOutput: OutputChannel | undefined;
static logGitCommand(command: string, cwd: string): void {
if (!this.debug) return;
if (this.gitOutput === undefined) {
this.gitOutput = window.createOutputChannel(`${ExtensionOutputChannelName} (Git)`);
}
this.gitOutput.appendLine(`${this.timestamp} ${command} (${cwd})`);
}
}

Загрузка…
Отмена
Сохранить