Skip to content

Commit 4812ec7

Browse files
authored
fix(cli): use execFileSync for git operations in --app init flow (#14960)
1 parent 702e2cf commit 4812ec7

2 files changed

Lines changed: 6 additions & 6 deletions

File tree

packages/amplify-cli/src/__tests__/commands/init.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
getPackageManagerByType,
99
$TSAny,
1010
} from '@aws-amplify/amplify-cli-core';
11-
import { execSync } from 'child_process';
11+
import { execFileSync, execSync } from 'child_process';
1212
import { ensureDir, existsSync, readFileSync, readJSON, readdirSync } from 'fs-extra';
1313
import { sync } from 'which';
1414
import { getPreInitSetup } from '../../init-steps/preInitSetup';
@@ -140,8 +140,8 @@ describe('amplify init:', () => {
140140
const recommendGen2 = true;
141141
const step = getPreInitSetup(!recommendGen2);
142142
await step(context as unknown as $TSContext);
143-
expect(execSync).toBeCalledWith(`git ls-remote ${appUrl}`, { stdio: 'ignore' });
144-
expect(execSync).toBeCalledWith(`git clone ${appUrl} .`, { stdio: 'inherit' });
143+
expect(execFileSync).toBeCalledWith('git', ['ls-remote', appUrl], { stdio: 'ignore' });
144+
expect(execFileSync).toBeCalledWith('git', ['clone', appUrl, '.'], { stdio: 'inherit' });
145145
expect(execSync).toBeCalledWith('yarn install', { stdio: 'inherit' });
146146
});
147147
});

packages/amplify-cli/src/init-steps/preInitSetup.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { $TSContext, AmplifyError, getPackageManager, LocalEnvInfo, pathManager } from '@aws-amplify/amplify-cli-core';
2-
import { execSync } from 'child_process';
2+
import { execFileSync, execSync } from 'child_process';
33
import * as fs from 'fs-extra';
44
import * as url from 'url';
55
import { generateLocalEnvInfoFile } from './s9-onSuccess';
@@ -83,7 +83,7 @@ function validateGithubRepo(repoUrl: string | boolean): asserts repoUrl is strin
8383
}
8484
url.parse(repoUrl);
8585

86-
execSync(`git ls-remote ${repoUrl}`, { stdio: 'ignore' });
86+
execFileSync('git', ['ls-remote', repoUrl], { stdio: 'ignore' });
8787
} catch (e) {
8888
throw new AmplifyError(
8989
'ProjectInitError',
@@ -110,7 +110,7 @@ const cloneRepo = async (repoUrl: string): Promise<void> => {
110110
}
111111

112112
try {
113-
execSync(`git clone ${repoUrl} .`, { stdio: 'inherit' });
113+
execFileSync('git', ['clone', repoUrl, '.'], { stdio: 'inherit' });
114114
} catch (e) {
115115
throw new AmplifyError(
116116
'ProjectInitError',

0 commit comments

Comments
 (0)