1- import { exec , execSync } from 'child_process' ;
1+ import { execFile , execFileSync } from 'child_process' ;
22
33type Input = { ref : string ; path : string } ;
44
55const createLoadError = ( error : any ) => new Error ( 'Unable to load file from git: ' + error ) ;
6- const createCommand = ( { ref, path } : Input ) => {
7- return `git show ${ ref } :${ path } `;
6+ const createCommand = ( { ref, path } : Input ) : string [ ] => {
7+ return [ ' show' , ` ${ ref } :${ path } `] ;
88} ;
99
1010/**
@@ -13,7 +13,7 @@ const createCommand = ({ ref, path }: Input) => {
1313export async function loadFromGit ( input : Input ) : Promise < string | never > {
1414 try {
1515 return await new Promise ( ( resolve , reject ) => {
16- exec ( createCommand ( input ) , { encoding : 'utf-8' , maxBuffer : 1024 * 1024 * 1024 } , ( error , stdout ) => {
16+ execFile ( 'git' , createCommand ( input ) , { encoding : 'utf-8' , maxBuffer : 1024 * 1024 * 1024 } , ( error , stdout ) => {
1717 if ( error ) {
1818 reject ( error ) ;
1919 } else {
@@ -31,7 +31,7 @@ export async function loadFromGit(input: Input): Promise<string | never> {
3131 */
3232export function loadFromGitSync ( input : Input ) : string | never {
3333 try {
34- return execSync ( createCommand ( input ) , { encoding : 'utf-8' } ) ;
34+ return execFileSync ( 'git' , createCommand ( input ) , { encoding : 'utf-8' } ) ;
3535 } catch ( error ) {
3636 throw createLoadError ( error ) ;
3737 }
0 commit comments