-
-
Notifications
You must be signed in to change notification settings - Fork 313
/
pull.ts
28 lines (25 loc) · 975 Bytes
/
pull.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
import { PullResult } from '../../../typings';
import { GitResponseError } from '../errors/git-response-error';
import { parsePullErrorResult, parsePullResult } from '../parsers/parse-pull';
import { Maybe, StringTask } from '../types';
import { bufferToString } from '../utils';
export function pullTask(remote: Maybe<string>, branch: Maybe<string>, customArgs: string[]): StringTask<PullResult> {
const commands: string[] = ['pull', ...customArgs];
if (remote && branch) {
commands.splice(1, 0, remote, branch);
}
return {
commands,
format: 'utf-8',
parser(stdOut, stdErr): PullResult {
return parsePullResult(stdOut, stdErr);
},
onError(result, _error, _done, fail) {
const pullError = parsePullErrorResult(bufferToString(result.stdOut), bufferToString(result.stdErr));
if (pullError) {
return fail(new GitResponseError(pullError));
}
fail(_error);
}
}
}