-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·40 lines (28 loc) · 910 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
32
33
34
35
36
37
38
39
40
#!/usr/bin/env node
const { execSync } = require("child_process");
const S = string => string.toString().replace(/[^0-9a-z-_.\/]/ig, "").replace(/^[^0-9a-z]/i, "");
const branch1 = S(process.argv[2]);
const branch2 = S(process.argv[3]);
const base = execSync("git merge-base " + branch1 + " " + branch2);
const conflict = execSync("git merge-tree " + S(base) + " " + branch1 + " " + branch2, { maxBuffer: 128 * 1024 * 1024 });
const lines = conflict.toString().split("\n");
let conflicts = false;
for (let state = 0, changed = null, i = 0; i < lines.length; i++)
{
const line = lines[i];
if (line === "changed in both")
{
state = 1;
}
else if (state === 1)
{
state = 0;
changed = line;
}
else if (line.match(/^.<<<<<+ \./))
{
console.log("CONFLICT " + changed);
conflicts = true;
}
}
process.exit(conflicts ? -1 : 0);