diff --git a/src/git-command-manager.ts b/src/git-command-manager.ts index b5cc5721..47e3937f 100644 --- a/src/git-command-manager.ts +++ b/src/git-command-manager.ts @@ -22,7 +22,8 @@ export type Commit = { } export type ExecOpts = { - allowAllExitCodes?: boolean, + allowAllExitCodes?: boolean + encoding?: 'utf8' | 'base64' } export class GitCommandManager { @@ -282,9 +283,9 @@ export class GitCommandManager { return output.stdout.trim() } - async showFileAtRef(ref: string, path: string): Promise { + async showFileAtRefBase64(ref: string, path: string): Promise { const args = ['show', `${ref}:${path}`] - const output = await this.exec(args) + const output = await this.exec(args, {encoding: 'base64'}) return output.stdout.trim() } @@ -376,10 +377,10 @@ export class GitCommandManager { ignoreReturnCode: opts.allowAllExitCodes ?? false, listeners: { stdout: (data: Buffer) => { - stdout.push(data.toString()) + stdout.push(data.toString(opts.encoding ?? 'utf8')) }, stderr: (data: Buffer) => { - stderr.push(data.toString()) + stderr.push(data.toString(opts.encoding ?? 'utf8')) } } } diff --git a/src/github-helper.ts b/src/github-helper.ts index 0aeb4e9e..fb541b40 100644 --- a/src/github-helper.ts +++ b/src/github-helper.ts @@ -275,7 +275,7 @@ export class GitHubHelper { const {data: blob} = await blobCreationLimit(() => this.octokit.rest.git.createBlob({ ...repository, - content: git.showFileAtRef(commit.sha, path), + content: await git.showFileAtRefBase64(commit.sha, path), encoding: 'base64' }) ) diff --git a/src/utils.ts b/src/utils.ts index ced3cbdf..b501dd48 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -126,16 +126,6 @@ export function readFile(path: string): string { return fs.readFileSync(path, 'utf-8') } -export function readFileBase64(pathParts: string[]): string { - const resolvedPath = path.resolve(...pathParts) - if (fs.lstatSync(resolvedPath).isSymbolicLink()) { - return fs - .readlinkSync(resolvedPath, {encoding: 'buffer'}) - .toString('base64') - } - return fs.readFileSync(resolvedPath).toString('base64') -} - /* eslint-disable @typescript-eslint/no-explicit-any */ function hasErrorCode(error: any): error is {code: string} { return typeof (error && error.code) === 'string'