Skip to content

Commit

Permalink
Promisify spawn
Browse files Browse the repository at this point in the history
  • Loading branch information
Takeshi committed Feb 16, 2024
1 parent 444d151 commit 7b99537
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/utils/clone.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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<string>((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'))
}
})
})
}


Expand Down

0 comments on commit 7b99537

Please sign in to comment.