-
-
Notifications
You must be signed in to change notification settings - Fork 318
/
Copy pathclone.ts
62 lines (54 loc) · 1.61 KB
/
clone.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import { configurationErrorTask, EmptyTask, straightThroughStringTask } from './task';
import { OptionFlags, Options, StringTask } from '../types';
import { append, filterString } from '../utils';
export type CloneOptions = Options &
OptionFlags<
| '--bare'
| '--dissociate'
| '--mirror'
| '--no-checkout'
| '--no-remote-submodules'
| '--no-shallow-submodules'
| '--no-single-branch'
| '--no-tags'
| '--remote-submodules'
| '--single-branch'
| '--shallow-submodules'
| '--verbose'
> &
OptionFlags<'--depth' | '-j' | '--jobs', number> &
OptionFlags<
| '--branch'
| '--origin'
| '--recurse-submodules'
| '--separate-git-dir'
| '--shallow-exclude'
| '--shallow-since'
| '--template',
string
>;
function disallowedCommand(command: string) {
return /^--upload-pack(=|$)/.test(command);
}
export function cloneTask(
repo: string | undefined,
directory: string | undefined,
customArgs: string[]
): StringTask<string> | EmptyTask {
const commands = ['clone', ...customArgs];
filterString(repo) && commands.push(repo);
filterString(directory) && commands.push(directory);
const banned = commands.find(disallowedCommand);
if (banned) {
return configurationErrorTask(`git.fetch: potential exploit argument blocked.`);
}
return straightThroughStringTask(commands);
}
export function cloneMirrorTask(
repo: string | undefined,
directory: string | undefined,
customArgs: string[]
) {
append(customArgs, '--mirror');
return cloneTask(repo, directory, customArgs);
}