-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
executable file
·31 lines (27 loc) · 889 Bytes
/
index.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
const { execSync } = require('child_process');
const CONFLICT_REGEXP = new RegExp('<<<<<<< .our', 'gi')
/**
* @param {string} baseBranch
* @param {string} branch
* @returns {boolean} True if branches are conflicted, false otherwise or when we can't tell due to errors
*/
const conflicted = (baseBranch, branch) => {
try {
const output = execSync(`git merge-tree \`git merge-base ${baseBranch} ${branch}\` ${branch} ${baseBranch}`);
return CONFLICT_REGEXP.test(output.toString());
} catch (ex) {
console.log(ex.stdout.toString());
console.error(ex.stderr.toString());
return true;
}
};
/**
* @param {string} baseBranch
* @param {string} branch
* @returns {boolean} True if branches are mergable without conflicts, false otherwise or when we can't tell due to errors
*/
const mergable = (...args) => !conflicted(...args);
module.exports = {
conflicted,
mergable
}