-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathcheckout.js
More file actions
80 lines (61 loc) · 2.1 KB
/
checkout.js
File metadata and controls
80 lines (61 loc) · 2.1 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
import R from 'ramda';
import { core } from './lfsCommands';
import {
regex,
BAD_CORE_RESPONSE,
BAD_REGEX_PARSE_RESULT
} from '../constants';
import generateResponse from '../utils/generateResponse';
import {
verifyOutput,
errorCatchHandler
} from '../helpers';
const isValidLine = str => str !== '';
const generateCheckoutStats = (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_checked_out =
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_checked_out =
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.checkout_error = statLine.split('error:')[1].trim();
}
return stats;
}
return {};
};
function checkout(repo, callback) {
return core.checkout('', { cwd: repo.workdir() }, callback)
.then(({ stdout }) => {
const response = generateResponse();
response.raw = stdout;
response.checkout = generateCheckoutStats(stdout);
if (response.checkout.checkout_error) {
response.success = false;
response.stderr = response.checkout.checkout_error;
response.errno = BAD_CORE_RESPONSE;
}
return response;
}, errorCatchHandler);
}
export default checkout;