Skip to content

Commit

Permalink
Ensure english locale (#387)
Browse files Browse the repository at this point in the history
  • Loading branch information
sorenlouv authored Jun 3, 2022
1 parent 0f530e9 commit 2f8c1cc
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
16 changes: 14 additions & 2 deletions src/lib/child-process-promisified.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ export async function exec(
const res = await execPromisified(cmd, {
maxBuffer: 100 * 1024 * 1024,
...options,

// ensure that git commands return english error messages
env: { ...process.env, LANG: 'en_US' },
});

return res;
Expand All @@ -29,7 +32,12 @@ export async function spawnPromise(
logger.info(`Running command: "${fullCmd}"`);

return new Promise(function (resolve, reject) {
const subprocess = childProcess.spawn(cmd, cmdArgs, { cwd });
const subprocess = childProcess.spawn(cmd, cmdArgs, {
cwd,

// ensure that git commands return english error messages
env: { ...process.env, LANG: 'en_US' },
});
let stderr = '';
let stdout = '';

Expand Down Expand Up @@ -57,7 +65,11 @@ export async function spawnPromise(
});
}

export const spawnOriginal = childProcess.spawn;
export const spawnStream = (cmd: string, cmdArgs: ReadonlyArray<string>) => {
return childProcess.spawn(cmd, cmdArgs, {
env: { ...process.env, LANG: 'en_US' },
});
};

export type SpawnErrorContext = {
cmdArgs: string[];
Expand Down
4 changes: 2 additions & 2 deletions src/lib/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { CommitAuthor } from './author';
import {
spawnPromise,
SpawnError,
spawnOriginal,
spawnStream,
} from './child-process-promisified';
import { getRepoPath } from './env';
import { getShortSha } from './github/commitFormatters';
Expand All @@ -30,7 +30,7 @@ export async function cloneRepo(
logger.info(`Cloning repo from ${sourcePath} to ${targetPath}`);

return new Promise<void>((resolve, reject) => {
const subprocess = spawnOriginal('git', [
const subprocess = spawnStream('git', [
'clone',
sourcePath,
targetPath,
Expand Down
10 changes: 5 additions & 5 deletions src/lib/setupRepo.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('setupRepo', () => {
expect.assertions(2);

jest
.spyOn(childProcess, 'spawnOriginal')
.spyOn(childProcess, 'spawnStream')
.mockImplementation((cmd, cmdArgs) => {
if (cmdArgs.includes('clone')) {
throw new Error('Simulated git clone failure');
Expand Down Expand Up @@ -66,7 +66,7 @@ describe('setupRepo', () => {
.mockResolvedValue(undefined);

jest
.spyOn(childProcess, 'spawnOriginal')
.spyOn(childProcess, 'spawnStream')
//@ts-expect-error
.mockImplementation(() => {
return {
Expand Down Expand Up @@ -206,7 +206,7 @@ describe('setupRepo', () => {

function mockGitClone() {
jest
.spyOn(childProcess, 'spawnOriginal')
.spyOn(childProcess, 'spawnStream')
//@ts-expect-error
.mockImplementation((cmd, cmdArgs) => {
if (cmdArgs.includes('clone')) {
Expand Down Expand Up @@ -246,7 +246,7 @@ describe('setupRepo', () => {
'100% Cloning repository from github.com (one-time operation)'
);

expect(childProcess.spawnOriginal).toHaveBeenCalledWith('git', [
expect(childProcess.spawnStream).toHaveBeenCalledWith('git', [
'clone',
'https://x-access-token:myAccessToken@github.com/elastic/kibana.git',
'/myHomeDir/.backport/repositories/elastic/kibana',
Expand Down Expand Up @@ -284,7 +284,7 @@ describe('setupRepo', () => {
'100% Cloning repository from /path/to/source/repo (one-time operation)'
);

expect(childProcess.spawnOriginal).toHaveBeenCalledWith('git', [
expect(childProcess.spawnStream).toHaveBeenCalledWith('git', [
'clone',
'/path/to/source/repo',
'/myHomeDir/.backport/repositories/elastic/kibana',
Expand Down

0 comments on commit 2f8c1cc

Please sign in to comment.