'use strict'; module.exports = MergeSummary; var PullSummary = require('./PullSummary'); function MergeConflict (reason, file) { this.reason = reason; this.file = file; } MergeConflict.prototype.toString = function () { return this.file + ':' + this.reason; }; function MergeSummary () { PullSummary.call(this); this.conflicts = []; this.merges = []; } MergeSummary.prototype = Object.create(PullSummary.prototype); MergeSummary.prototype.result = 'success'; MergeSummary.prototype.toString = function () { if (this.conflicts.length) { return 'CONFLICTS: ' + this.conflicts.join(', '); } return 'OK'; }; Object.defineProperty(MergeSummary.prototype, 'failed', { get: function () { return this.conflicts.length > 0; } }); MergeSummary.parsers = [ { test: /^Auto-merging\s+(.+)$/, handle: function (result, mergeSummary) { mergeSummary.merges.push(result[1]); } }, { test: /^CONFLICT\s+\((.+)\).+ in (.+)$/, handle: function (result, mergeSummary) { mergeSummary.conflicts.push(new MergeConflict(result[1], result[2])); } }, { test: /^Automatic merge failed;\s+(.+)$/, handle: function (result, mergeSummary) { mergeSummary.reason = result[1]; } } ]; MergeSummary.parse = function (output) { let mergeSummary = new MergeSummary(); output.trim().split('\n').forEach(function (line) { for (var i = 0, iMax = MergeSummary.parsers.length; i < iMax; i++) { let parser = MergeSummary.parsers[i]; var result = parser.test.exec(line); if (result) { parser.handle(result, mergeSummary); break; } } }); let pullSummary = PullSummary.parse(output); if (pullSummary.summary.changes) { Object.assign(mergeSummary, pullSummary); } return mergeSummary; };