forked from l8on/affiance
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMergeConflicts.js
29 lines (28 loc) · 879 Bytes
/
MergeConflicts.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
'use strict';
const PreCommitBase = require('./Base');
/**
* @class EsLint
* @extends PreCommitBase
* @classdesc Check for merge conflict markers in changed files
*/
module.exports = class MergeConflicts extends PreCommitBase {
/**
* Use grep to check for merge conflicts
* Uses spawnPromiseOnApplicableFiles to parallelize
*
* @returns {Promise}
* @resolves {string|string[]} 'pass' or a tuple of 'fail' and a message
* @rejects {Error} An Error thrown or emitted while running the hook
*/
run() {
return new Promise((resolve, reject) => {
this.spawnPromiseOnApplicableFiles().then((result) => {
if (result.stdout.toString().trim()) {
return resolve(['fail', `Merge conflict markers detected:\n${result.stdout.toString()}`]);
} else {
return resolve('pass');
}
}, reject);
});
}
};