diff --git a/CHANGELOG.md b/CHANGELOG.md index 2119a19..447595d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -65,6 +65,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p ### Fixed +- Fixes [1438](https://github.com/eamodio/vscode-gitlens/issues/1438) - Messages in hovers wrong encoding using non UTF-8 - Fixes [1372](https://github.com/eamodio/vscode-gitlens/issues/1372) - Unexpected repository detection on editor startup after recent updates - Fixes [1394](https://github.com/eamodio/vscode-gitlens/issues/1394) - Repository view settings appear disabled - Fixes [1391](https://github.com/eamodio/vscode-gitlens/issues/1391) - Branch names are not properly escaped in git commands diff --git a/src/git/git.ts b/src/git/git.ts index 762fc7d..befc840 100644 --- a/src/git/git.ts +++ b/src/git/git.ts @@ -63,7 +63,7 @@ export enum GitErrorHandling { Throw = 'throw', } -export interface GitCommandOptions extends RunOptions { +export interface GitCommandOptions extends RunOptions { configs?: string[]; readonly correlationKey?: string; errors?: GitErrorHandling; @@ -89,12 +89,11 @@ export async function git(options: GitCommandOptio const start = process.hrtime(); - const { configs, correlationKey, errors: errorHandling, ...opts } = options; + const { configs, correlationKey, errors: errorHandling, encoding, ...opts } = options; - const encoding = options.encoding ?? 'utf8'; const runOpts: RunOptions = { ...opts, - encoding: encoding === 'utf8' ? 'utf8' : encoding === 'buffer' ? 'buffer' : 'binary', + encoding: (encoding ?? 'utf8') === 'utf8' ? 'utf8' : 'buffer', // Adds GCM environment variables to avoid any possible credential issues -- from https://github.com/Microsoft/vscode/issues/26573#issuecomment-338686581 // Shouldn't *really* be needed but better safe than sorry env: { @@ -131,7 +130,7 @@ export async function git(options: GitCommandOptio args.splice(0, 0, '-c', 'core.longpaths=true'); } - promise = run(gitInfo.path, args, encoding, runOpts); + promise = run(gitInfo.path, args, encoding ?? 'utf8', runOpts); pendingCommands.set(command, promise); } else { @@ -525,7 +524,7 @@ export namespace Git { { cwd: repoPath, configs: ['-c', 'color.diff=false'], - encoding: options.encoding === 'utf8' ? 'utf8' : 'binary', + encoding: options.encoding, }, ...params, '--', @@ -578,7 +577,7 @@ export namespace Git { { cwd: repoPath, configs: ['-c', 'color.diff=false'], - encoding: options.encoding === 'utf8' ? 'utf8' : 'binary', + encoding: options.encoding, stdin: contents, }, ...params, diff --git a/src/git/shell.ts b/src/git/shell.ts index 39a272a..522250e 100644 --- a/src/git/shell.ts +++ b/src/git/shell.ts @@ -114,10 +114,10 @@ export function findExecutable(exe: string, args: string[]): { cmd: string; args return { cmd: exe, args: args }; } -export interface RunOptions { +export interface RunOptions { cwd?: string; readonly env?: Record; - readonly encoding?: BufferEncoding | 'buffer'; + readonly encoding?: TEncoding; /** * The size the output buffer to allocate to the spawned process. Set this * if you are anticipating a large amount of output. @@ -174,7 +174,7 @@ export class RunError extends Error { export function run( command: string, args: any[], - encoding: BufferEncoding | 'buffer', + encoding: BufferEncoding | 'buffer' | string, options: RunOptions = {}, ): Promise { const { stdin, stdinEncoding, ...opts }: RunOptions = { maxBuffer: 100 * 1024 * 1024, ...options };