-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathclone.js
More file actions
81 lines (63 loc) · 2.02 KB
/
clone.js
File metadata and controls
81 lines (63 loc) · 2.02 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import R from 'ramda';
import { core } from './lfsCommands';
import {
regex,
BAD_REGEX_PARSE_RESULT
} from '../constants';
import generateResponse from '../utils/generateResponse';
import {
errorCatchHandler,
verifyOutput
} from '../helpers';
const isValidLine = str => str !== '';
const generateCloneStats = (raw) => {
if (raw && typeof raw === 'string') {
const stats = {};
const outputLines = raw.split('Git LFS:');
const filteredLines = R.filter(isValidLine, outputLines);
const statLine = filteredLines.pop();
const byteResults = statLine.match(regex.TOTAL_BYTES);
stats.total_bytes_cloned =
byteResults !== null ?
byteResults[0].trim() : BAD_REGEX_PARSE_RESULT;
stats.total_bytes =
byteResults !== null ?
byteResults[1].trim() : BAD_REGEX_PARSE_RESULT;
const fileResults = statLine.match(regex.TOTAL_FILES);
stats.total_files_cloned =
fileResults !== null ?
fileResults[0].trim() : BAD_REGEX_PARSE_RESULT;
const skippedByteResults = statLine.match(regex.SKIPPED_BYTES);
stats.total_bytes_skipped =
skippedByteResults !== null ?
skippedByteResults[0].trim() : BAD_REGEX_PARSE_RESULT;
const skippedFileResults = statLine.match(regex.SKIPPED_FILES);
stats.total_files_skipped =
skippedFileResults !== null ?
skippedFileResults[0].trim() : BAD_REGEX_PARSE_RESULT;
verifyOutput(stats, raw);
if (statLine.includes('error:')) {
stats.clone_error = statLine.split('error:')[1].trim();
}
return stats;
}
return {};
};
function clone(url, cwd, options) {
if (!url || !cwd) {
throw new Error('A valid URL and working directory are required');
}
const {
branch,
callback,
env = {}
} = (options || {});
const args = branch ? `-b ${branch}` : '';
return core.clone(`${url} ${args}`, { cwd, env }, callback)
.then(({ stdout }) => ({
...generateResponse(),
raw: stdout,
clone: generateCloneStats(stdout)
}), errorCatchHandler);
}
export default clone;