From 7b995379448e46c7174653c611de0d74da750b0e Mon Sep 17 00:00:00 2001 From: Takeshi Date: Thu, 15 Feb 2024 20:32:13 -0700 Subject: [PATCH] Promisify spawn --- src/utils/clone.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/utils/clone.ts b/src/utils/clone.ts index 7ac3c02..e735cde 100644 --- a/src/utils/clone.ts +++ b/src/utils/clone.ts @@ -1,5 +1,6 @@ import GitlyOptions from '../interfaces/options' import { getArchivePath } from './archive' +import { GitlyCloneError } from './error' import execute from './execute' import exists from './exists' import { isOffline } from './offline' @@ -20,8 +21,19 @@ export default async function clone( const local = async () => exists(path) const remote = async () => { - const result = spawn.sync('git', ['clone', info.href, path]) - return result.status === 0 + // Use the git command to clone the repository + // but promisify cross-spawn to handle the output + return new Promise((resolve, reject) => { + const child = spawn('git', ['clone', info.href, path]) + + child.on('close', (code) => { + if (code === 0) { + resolve(path) + } else { + reject(new GitlyCloneError('Failed to clone the repository')) + } + }) + }) }