History

Update Git documentation (2.30.0)

Simon Legner committed 5 years ago

Commit 3600a9f1 parent 8f17cfa41 files · +4398 −1Browse files

Showing the changes to node_modules/simple-git/src/responses/MergeSummary.js (1 of 41 files). Show all

Unified · Split

node_modules/simple-git/src/responses/MergeSummary.js+103−0
@@ -0,0 +1,103 @@
1+module.exports = MergeSummary;
2+module.exports.MergeConflict = MergeConflict;
3+
4+var PullSummary = require('./PullSummary');
5+
6+function MergeConflict (reason, file, meta) {
7+ this.reason = reason;
8+ this.file = file;
9+ if (meta) {
10+ this.meta = meta;
11+ }
12+}
13+
14+MergeConflict.prototype.meta = null;
15+
16+MergeConflict.prototype.toString = function () {
17+ return this.file + ':' + this.reason;
18+};
19+
20+function MergeSummary () {
21+ PullSummary.call(this);
22+
23+ this.conflicts = [];
24+ this.merges = [];
25+}
26+
27+MergeSummary.prototype = Object.create(PullSummary.prototype);
28+
29+MergeSummary.prototype.result = 'success';
30+
31+MergeSummary.prototype.toString = function () {
32+ if (this.conflicts.length) {
33+ return 'CONFLICTS: ' + this.conflicts.join(', ');
34+ }
35+ return 'OK';
36+};
37+
38+Object.defineProperty(MergeSummary.prototype, 'failed', {
39+ get: function () {
40+ return this.conflicts.length > 0;
41+ }
42+});
43+
44+MergeSummary.parsers = [
45+ {
46+ test: /^Auto-merging\s+(.+)$/,
47+ handle: function (result, mergeSummary) {
48+ mergeSummary.merges.push(result[1]);
49+ }
50+ },
51+ {
52+ // Parser for standard merge conflicts
53+ test: /^CONFLICT\s+\((.+)\): Merge conflict in (.+)$/,
54+ handle: function (result, mergeSummary) {
55+ mergeSummary.conflicts.push(new MergeConflict(result[1], result[2]));
56+ }
57+ },
58+ {
59+ // Parser for modify/delete merge conflicts (modified by us/them, deleted by them/us)
60+ test: /^CONFLICT\s+\((.+\/delete)\): (.+) deleted in (.+) and/,
61+ handle: function (result, mergeSummary) {
62+ mergeSummary.conflicts.push(
63+ new MergeConflict(result[1], result[2], {deleteRef: result[3]})
64+ );
65+ }
66+ },
67+ {
68+ // Catch-all parser for unknown/unparsed conflicts
69+ test: /^CONFLICT\s+\((.+)\):/,
70+ handle: function (result, mergeSummary) {
71+ mergeSummary.conflicts.push(new MergeConflict(result[1], null));
72+ }
73+ },
74+ {
75+ test: /^Automatic merge failed;\s+(.+)$/,
76+ handle: function (result, mergeSummary) {
77+ mergeSummary.reason = mergeSummary.result = result[1];
78+ }
79+ }
80+];
81+
82+MergeSummary.parse = function (output) {
83+ let mergeSummary = new MergeSummary();
84+
85+ output.trim().split('\n').forEach(function (line) {
86+ for (var i = 0, iMax = MergeSummary.parsers.length; i < iMax; i++) {
87+ let parser = MergeSummary.parsers[i];
88+
89+ var result = parser.test.exec(line);
90+ if (result) {
91+ parser.handle(result, mergeSummary);
92+ break;
93+ }
94+ }
95+ });
96+
97+ let pullSummary = PullSummary.parse(output);
98+ if (pullSummary.summary.changes) {
99+ Object.assign(mergeSummary, pullSummary);
100+ }
101+
102+ return mergeSummary;
103+};