forked from steveukx/git-js
-
Notifications
You must be signed in to change notification settings - Fork 2
/
FetchSummary.js
55 lines (48 loc) · 1.19 KB
/
FetchSummary.js
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
'use strict';
function FetchSummary (raw) {
this.raw = raw;
this.remote = null;
this.branches = [];
this.tags = [];
}
FetchSummary.parsers = [
[
/From (.+)$/, function (fetchSummary, matches) {
fetchSummary.remote = matches[0];
}
],
[
/\* \[new branch\]\s+(\S+)\s*\-> (.+)$/, function (fetchSummary, matches) {
fetchSummary.branches.push({
name: matches[0],
tracking: matches[1]
});
}
],
[
/\* \[new tag\]\s+(\S+)\s*\-> (.+)$/, function (fetchSummary, matches) {
fetchSummary.tags.push({
name: matches[0],
tracking: matches[1]
});
}
]
];
FetchSummary.parse = function (data) {
var fetchSummary = new FetchSummary(data);
String(data)
.trim()
.split('\n')
.forEach(function (line) {
var original = line.trim();
FetchSummary.parsers.some(function (parser) {
var parsed = parser[0].exec(original);
if (parsed) {
parser[1](fetchSummary, parsed.slice(1));
return true;
}
});
});
return fetchSummary;
};
module.exports = FetchSummary;