-
Notifications
You must be signed in to change notification settings - Fork 2
/
util.ts
38 lines (29 loc) · 931 Bytes
/
util.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import * as path from 'path'
import * as fs from 'fs-extra'
import simpleGit, { SimpleGit } from 'simple-git'
const localCheckoutDir = path.posix.join(__dirname, '.local-deploy-sourcegraph')
export interface PrepareOptions {
skipCleanup?: boolean
}
export async function cloneLocalDSCheckout(ref: string, options?: PrepareOptions): Promise<string> {
const opts: PrepareOptions = {
skipCleanup: false,
...options,
}
if (!opts.skipCleanup) {
await fs.remove(localCheckoutDir)
}
await fs.mkdirp(localCheckoutDir)
const git: SimpleGit = simpleGit({
baseDir: localCheckoutDir,
})
const cloneURL = 'https://github.com/sourcegraph/deploy-sourcegraph.git'
await git
.init()
.addRemote('upstream', cloneURL)
.fetch('upstream', ref, {
'--depth': '1',
})
.checkout('FETCH_HEAD')
return localCheckoutDir
}